Reducing PDF File Size When Saving in Aspose.Words

I am using Aspose.Words to save an RTF document as a PDF. The resulting file size in the PDF is a bit larger than I would like.

Does Aspose.Words provide any compression options for the PDF? Is the solution compression tools in Aspose.PDF? What can be done to reduce file size for PDFs generated from Aspose?

Hi Rick,

Thanks for your inquiry. The size of Pdf documents can be reduced only by doing the following:

  1. Decreasing size of images inside PDF (this can be done only be decreasing quality).
  2. Subsetting fonts, which are embedded into the PDF documents. (Aspose.Words does this by default).
  3. Compression of text (Usually the decrease in size is not very big)
  4. Using “Core fonts”. “Core fonts” are 14 fonts, which are supported by PDF viewers by default. We can optionally get rid embedding of these fonts into PDF.

Secondly, could you please attach your input Word document (.rtf file) here for testing? I will investigate the issue on my side and provide you more information.

Moreover, you can also specify Image and Text compression options during rendering to Pdf format. Please take a look at the following properties:

  1. PdfSaveOptions.ImageCompression Property
  2. PdfSaveOptions.TextCompression Property

I hope, this helps.

Best regards,

Hi Awais,
Thank you for your quick response.
I am not using images in my document, so that should not be an issue.
I would like to add text compression and remove embedding.
Could you provide an example showing how to pass the PdfSaveOptions.TextCompression parameter to the Save function? I could not find PdfTextCompression in the SaveOptions class.
I have attached a .rtf file that is 3KB. After converting the file to .pdf it is 40KB.
Thanks again for your reply, it was very helpful.
Rick

Hi Rick,

Thanks for your inquiry.

While using the latest version of Aspose.Words i.e. 11.10.0, I managed to reproduce this issue on my side. I have logged this issue in our bug tracking system. The issue ID is WORDSNET-7491. Your request has also been linked to this issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Secondly, here is the sample code you’ve asked for:

Document doc = new Document(@"C:\Temp\me_us_00005_1.rtf");
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.TextCompression = PdfTextCompression.Flate;
doc.Save(@"C:\Temp\out.pdf", saveOptions);

Best regards,

Hi Awais,
Thank you for logging this issue. I have tried the sample code you provided and confirmed that it did not reduce the file size of the .pdf.
You also mentioned removal of core font text embedding. Is this type of embedding a default in Aspose.Words? Could you provide a sample of how this can be removed. Thank you.
Rick

Hi Rick,

Thanks for the additional information. No, by default, Aspose.Words does not substitute TrueType fonts e.g. Arial, Times New Roman, Courier New and Symbol with core PDF Type 1 fonts. I would suggest you please read the following article that outlines ‘Controlling Embedding of Core and Windows Standard Fonts’.
https://docs.aspose.com/words/net/specify-rendering-options-when-converting-to-pdf/

Best regards,

Hi Rick,

Thanks for your patience.

The Pdf size is 40kb because of embedded font files. In your particular document, ‘Times New Roman’ font is used and it may not be embedded if you disable EmbedStandardWindowsFonts option or enable UseCoreFonts option. This way Pdf document size could be reduced to 5 kb or even to 3 kb. Please try running the following code snippet on your side:

Document doc = new Document(@"C:\Temp\me_us_00005_1.rtf");
PdfSaveOptions saveOptions = new PdfSaveOptions();
// saveOptions.EmbedStandardWindowsFonts = false;
saveOptions.UseCoreFonts = true;
doc.Save(@"C:\Temp\out.pdf", saveOptions);

I hope, this helps.

Best regards,

Hi Awais,
This is good to know, I am not too familiar with fonts as they relate to file sizes.
I will give this code snippet a try. Thanks so much!
Rick

Hi Rick,

Sure, we will wait for your feedback on this. Please let us know any time you have any further queries. We’re always glad to help you.

Best regards,

Hi Rick,

It is to update you that our development team has finished working on your issue (WORDSNET-7491) and has come to a conclusion that your issue and the behaviour you’re observing is actually not a bug in Aspose.Words. So, we’ve closed this issue as ‘Not a Bug’. If we can help you with anything else, please feel free to ask.

Best regards,