Hello - I wondered if you any thoughts about reducing the file size of a PDF (generated by EO-PDF) that has several (repeated [SVG]) images. At the moment several (chunked) PDF are generated as follows
Code: C#
//...
HtmlToPdfOptions htmlToPdfOptions = new HtmlToPdfOptions();
//...
HtmlToPdfResult htmlToPdfResult = null;
using (var debugConsoleLog = new StringWriter())
{
HtmlToPdf.DebugConsole = debugConsoleLog;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
_logger.LogInformation($"Generate PDF-generateFromCoversheetHtml: {generateFromCoversheetHtml}");
try
{
htmlToPdfResult = HtmlToPdf.ConvertHtml(inputHtml, stream, htmlToPdfOptions);
}
catch (Exception ex)
{
//...
}
bytes = stream.ToArray();
}
debugConsoleLog.Flush();
}
//...
...then these 'chunks' need to be merged - we would like to do this via EO-PDF (see the code below) however as this is slow by comparison we merge via a 3rd party tool
Code: C#
var pdfDocuments = new List<EO.Pdf.PdfDocument>();
List<byte[]> listOfBytes = GetListOfPdfs(...pdf-chunks...);
EO.Pdf.PdfDocument pdfDocument = null;
foreach (var pdfAsArray in listOfBytes)
{
if (pdfAsArray.Length > 0)
{
using (MemoryStream stream = new MemoryStream())
{
stream.Write(pdfAsArray, 0, pdfAsArray.Length);
stream.Seek(0, SeekOrigin.Begin);
pdfDocument = new EO.Pdf.PdfDocument(stream);
pdfDocuments.Add(pdfDocument);
}
}
}
pdfDocument = EO.Pdf.PdfDocument.Merge(pdfDocuments.ToArray());
using (MemoryStream stream = new MemoryStream())
{
pdfDocument.Save(stream);
merged = stream.ToArray();
pdfDocument = null;
}
So the options I have
- perhaps reduce the size of the PDF chunks being generated (is there a way to do this - eg. different HtmlToPdf.ConvertHtml overload, 'declarifying' (eg. reduce dpi) w/o losing too much clarity)
- I know that the EO-PDF merge consolidates fonts, etc and hence the file size is likely smaller, but is there a way to make this (the EO-PDF merge) more performant
Kind regards
Phil