Is there any way to prevent HtmlToPdf to embed any fonts?

Hi there, we are in shortage of database space, and the size of our PDF-s created using HtmlToPdfConverter (Blink engine) starts to be critical. It seems that a large part of the 1-2 pages, mainly text only PDF's size is the fonts embedded. If we only use e.g. Courier New which everyone may have on their machine, can we spare the space occupied by the embedded font?

Thanks.


6 Replies

SN Santhiya Narayanan Syncfusion Team June 9, 2023 10:46 AM UTC

No. There is no way to achieve this in our library. If you want to reduce the output file size, you can use the compression to the HTML converted stream


Please refer the below KB link

https://support.syncfusion.com/kb/article/10236/how-to-compress-a-pdf-document-in-asp-net-core


Please find the below UG link

https://help.syncfusion.com/file-formats/pdf/working-with-compression


Please refer below code snippet,


HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();          

string path = Path.GetFullPath("../../../Data/HtmlSample.html");

PdfDocument document = htmlConverter.Convert(path);

MemoryStream stream= new MemoryStream();

//Save and close the PDF document.

document.Save(stream);

PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream);

PdfCompressionOptions options = new PdfCompressionOptions();

//Enable the compress image.

options.CompressImages = true;

//Set the image quality.

options.ImageQuality = 50;

options.OptimizeFont = true;

//Compress the page contents

options.OptimizePageContents = true;

//Remove the metadata information

options.RemoveMetadata = true;

//Set the options to loaded PDF document

loadedDocument.Compress(options);

//Restructure the document

loadedDocument.FileStructure.IncrementalUpdate = false;

MemoryStream str= new MemoryStream();

//Save the document into stream.

loadedDocument.Save(str);

//Close the documents.

loadedDocument.Close(true);

File.WriteAllBytes("HTML-To-PDF.pdf", str.ToArray());



GG Gyorgy Gorog June 9, 2023 02:39 PM UTC

Santhiya, thanks for the info. In fact, this may be a good step in development. 

A 3-page PDF, for example, is 103 kBytes when converted from HTML, with all the compression options you mentioned. However, unembedding the fonts from it leaves a 25 kByte PDF. 



SN Santhiya Narayanan Syncfusion Team June 12, 2023 12:00 PM UTC

As per our understanding, you are getting the file size with 23KB less than compression while unembedded the fonts from the compressed pdf document. Can you please provide details how you have unembed the font which tool you have used, so that we can check this on our end. So that it will be helpful for us to analyze and assist you further on this.



GG Gyorgy Gorog June 12, 2023 05:31 PM UTC

Santhiya, unembedding is performed using iText7. Their example is https://kb.itextpdf.com/home/it7kb/examples/unembed-a-font



SN Santhiya Narayanan Syncfusion Team June 13, 2023 03:07 PM UTC

Currently we are checking on this and will update the further details on June 15th,2023.



SN Santhiya Narayanan Syncfusion Team June 15, 2023 02:06 PM UTC

Currently, we don't have the support to remove the font from the document. While unembedding the font from a compressed pdf document using IText7, 30 KB reduced, but the output document was not preserved properly. If we remove the font from the document, it doesn't preserve properly.

 

So we suggest that you use HTML with the compression option to reduce the file size.



Loader.
Up arrow icon