Skip to main content
Dynamics 365
·
2 min read

How to reduce the file size of PDF files generated by AX 2009

PDF files generated from Microsoft Dynamics AX can get quite large in size. In this thread I share some hints on how you can potentially reduce the size of the generated PDF file.

Images
During PDF generation each image will be temporarily converted to a 24bit BMP file and afterwards stored as a JPG. So it does not really depend how good compressed the file is (JPG vs BMP), but the image size can make a difference. The suggestion is to keep the size (width/height) as small as possible but not smaller than the size it has to be on the document.

For example, if the size of your logo on the document is 60×20 mm then avoid using an image whose original size is, say, 240×80 mm. In this case use a logo with exactly the same size of 60×20 mm.

Compression Level
There is a parameter in the ClassDeclaration of the PDFViewer where you can set the compression level of the binary streams used for text and images within the PDF file:

#define.COMPRESSIONLEVEL(12)    //LZ77 Compression setting

As far as I could find out the levels are like this:
1 – best speed
to
15 – best compression

Setting the compression level to 15, I have observed the size to be smaller  (about ~10% smaller in size). However this may slightly affect the speed of PDF generation due to the higer compression.

Using predefined PDF fonts
Embedding fonts ensures that the document will display using the fonts used to create the document. However this can cause the PDF file generated to be quite large. An alternative is to not embed any fonts but create the document using fonts that will already be available on the system where it will be viewed.

Furthermore, another alternative could be to use one of the predifined fonts during PDF generation which are supported by all PDF Viewers. This means that these fonts can be displayed regardless of being installed on the machine where the PDF file is being viewed. You do not have to embed the font (‘PDF embed fonts’ option) when generating a PDF file from AX. This later option will probably give you the smallest generated file size.

List of predefined fonts, supported by all PDF viewers

Courier
Courier-Bold
Courier-Oblique;
Courier-BoldOblique
Helvetica
Helvetica-Bold
Helvetica-Oblique
Helvetica-BoldOblique
Symbol
Times
Times-Roman
Times-Bold
Times-Italic
Times-BoldItalic
ZapfDingbats

Especially the Helvetica font might be of interest, as the Arial font is very similar to the Helvetica font. However this font is not a Microsoft Windows standard font and has to be installed separately.
If you search for the Helvetica font on the internet you be pointed to multiple site where you can buy this font.

Note
When you consider to use a predefined font then you have to do the following code change in the endReport method of PDFViewer class:


// Delete the fonts stored in the fontdescrs map
mapEnumerator = fontDescrs.getEnumerator();
while (mapEnumerator.moveNext())
{
font = mapEnumerator.currentValue();
//->Begin
if(font.isTrueType())
//<-End
font.deleteFont();
}