Controlling the File Size of Exported .pdf Files

Sergey Sherstnev

January 30, 2018

From time to time, ODA members have questions about why the file size of exported .pdf files is so large. Sometimes the issues require investigation and fixing, but sometimes the reason is simply the chosen parameters, which dramatically increase the size of the resulting .pdf file. In this article, we’ll look at these parameters and give recommendations on how to reduce exported .pdf file size.

Text export flags:

  • kTTFTextAsGeometry and kSHXTextAsGeometry are responsible for how the text in a drawing will be exported into .pdf: as text or as a set of geometry primitives. The effect of these flags on file size depends on the amount of text in the drawing, the number of different fonts, and on other parameters such as vector resolution of the .pdf.
  • kEmbededTTF (can be set if kTTFTextAsGeometry is not set) controls whether the whole font file will be embedded in the .pdf file. It makes .pdf portability much better but obviously increases the file size. To reduce file size, the flag kEmbededOptimizedTTF can be used. This flag removes unused parts of the embedded font so the file size will be smaller, but future editing of this .pdf will be limited.
  • SearchableTextType (can be set if kTTFTextAsGeometry or kSHXTextAsGeometry is also set) adds annotations with text into the .pdf, which provides the ability to search text when text is exported as geometry. This option increases the size of the .pdf.

Compression settings:

  • kFlateCompression compresses the content of the .pdf using a zip algorithm. It significantly reduces the .pdf file size. We recommend always using this flag.
  • kASCIIHexEncoding converts the content to an ASCIIHex sequence, which practically doubles the .pdf size. Some people believe that this conversion makes the .pdf look better, but we do not recommend using this option if you care about file size.
  • DCTCompression (setDCTCompression(bool bEnable)) compresses the images in the .pdf using a JPEG algorithm if it has a point. It significantly reduces the .pdf file size, and we recommend always using this flag.
  • DCTQuality (setDCTQuality(OdUInt16 quality)) sets the quality of the JPEG compression as a percentage (10 to 100). The better the quality, the bigger the .pdf file size.

Resolution settings:

  • VectorResolution (setGeomDPI(OdUInt16 dpi)) for the geometry, colorImagesDPI (setColorImagesDPI(OdUInt16 dpi)) and bwImagesDPI (setBWImagesDPI(OdUInt16 dpi)) for color and black-and-white images, and hatchDPI (setHatchDPI(OdUInt16 dpi)) for hatches exported as bitmap images. These are simple: the bigger the resolution, the better the .pdf file looks (especially when zooming) but the bigger the .pdf file size.

Hatch setting:

  • The hatch export type (ExportHatchesType parameter) provides different export types for different kinds of hatches. They are described in detail previously on this blog , but in general to reduce the .pdf file size, we recommend using kPdfPaths for solid filled hatches, kBitmap for gradient filled hatches, and kVectorizer for other hatches.

Other flags and parameters, representing specific features:

  • PDF_A_mode (setArchived(PDF_A_mode mode)) produces PDF/A files (described previously on this blog ). This can significantly increase the .pdf file size, so the choice is a smaller .pdf vs. a long-term archived document.
  • kLinearized produces a linearized .pdf file. This also increases the .pdf file size a bit, but provides a quicker view over the Internet.
  • kMeasuring makes the .pdf file size grow a bit by adding auxiliary information into the .pdf (described previously on this blog ). The same with the kExportHyperlinks flag (if links are in the drawing).
  • kEnableLayers, kIncludeOffLayers and kMergeLines also increase the size by adding optional graphic content to provide .pdf layer functionality and partial transparency for line-crossing, so if these options are not important they can be turned off to reduce the .pdf file size.
  • CropImages (setImageCropping(bool bEnable)) cuts unused parts of images, and therefore can significantly reduce .pdf file size. For example, sometimes images exported from a drawing appear in the .pdf in such way that only part of the image can be displayed (part of the image is placed outside the page or just outside a certain viewport). This option is set by default and we strongly recommend to keep it that way.
  • kSimpleGeomOptimization narrows down a lot of geometry when exporting big drawings with huge amounts of geometry, especially using average/small paper size or average/small resolution. For example, we can use a circle or ellipse, which displays in the .pdf file just like a point or line. And it will not turn into the circle again even when zoomed to the maximum. So this means that such entities can be exported to the .pdf as just one point or line and the quality will not be affected. In some cases this option can reduce the .pdf file size by dozens of times, so it is recommended to almost always use it. The only side effect of this flag is the increased time to export because the optimization takes extra time.