BoldDesk®Customer service software offering ticketing, live chat, and omnichannel support, starting at $49/mo. for 10 agents. Try it for free.
I'm attempting to convert HTML files to PDF, but the resulting PDFs are much larger in size compared to the original images. Upon extracting images from the PDF, I noticed that JPEG images are being converted to PNG format, leading to increased file sizes. This issue is causing delays in implementing Syncfusion. Do you have any solutions?
I've attached the code and images in a compressed file for reference.
Hi John,
Thank you for contacting Syncfusion support.
We are able to reproduce the reported issue on our end. Currently, we are validating this and will update further details on 5th February, 2024.
Regards,
Karmegam
Hi John,
On our further analysis, our HTML Converter internally using a chrome headless browser for converting HTML to PDF. It will preserve the PDF document like how the input HTML/URL is displayed in Chromium-based web browsers (chrome, print preview). The same behavior will replicated in our converter. We have checked the provided input URL in Chrome print preview and saved the document. The saved PDF from the Chrome print preview itself has the images in PNG format. The output file size and extracted image sizes are also similar. So, our library also has a similar type and size of images when extracting the PDF document. We have attached the Chrome saved document and our library output document for your reference.
Regards,
Sivaram G
I've found that this issue is resolved in Chrome version 122 (currently in beta). Is there an upcoming Chromium update planned for the library? If so, when can we expect it?
We will upgrade the binaries to the latest stable version if current binaries have any major security vulnerabilities and preservation issues. We are not proceeding the binaries update with beta version of binaries. We will test and confirm this once stable version of the binaries will be published for version 122.x.x. However, you can download and use the beta version of binaries and use it for our HTML to PDF conversion with BlinkPath property of BlinkConverterSettings. We have attached the code snippet below for your reference,
//Initialize HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();
//Set Blink Path blinkConverterSettings.BlinkPath = @"BlinkBinaries_beta\";
//Assign Blink converter settings to HTML converter. htmlConverter.ConverterSettings = blinkConverterSettings; |
Same issue with me too. Because of that my personal work hampers a lot. I have purchased a software for taking Office 365 Backup and for my personal stuff. But due to this issue I need to take help from others.
Hi Rohit,
Thank you for reaching out to Syncfusion support.
Upon further analysis, the reported issue occurs in the Blink rendering engine itself. However, we have a workaround solution to resolve this size issue while converting the HTML to a PDF document. In this workaround solution, we can compress the converted PDF document image quality by using the PdfCompressionOptions class.
Please refer to the below code snippet.
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink); BlinkConverterSettings settings = new BlinkConverterSettings();
settings.ViewPortSize = new Size(900, 0); htmlConverter.ConverterSettings = settings;
string htmlText = File.ReadAllText(htmlFilePath); PdfDocument document = htmlConverter.Convert(htmlText, Path.GetFullPath($"../../../html/"), out PdfLayoutResult layoutResult);
MemoryStream memoryStream = new MemoryStream(); document.Save(memoryStream); Console.WriteLine(memoryStream.Length); document.Close(true);
//Load the existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument(memoryStream);
//Create a new compression option. PdfCompressionOptions options = new PdfCompressionOptions(); //Enable the compress image. options.CompressImages = true; //Set the image quality. options.ImageQuality = 50;
//Assign the compression option to the document. loadedDocument.Compress(options); MemoryStream compressedStream = new MemoryStream(); loadedDocument.Save(compressedStream); File.WriteAllBytes("result.pdf", compressedStream.ToArray()); |
Please refer to the below documentation.
Working with Compression | Syncfusion
Kindly try the above-provided solution and get back to us if you need further assistance.
Regards,
Karmegam