Removing transparency from PDF drawings

Q:

We are an engineering company that uses AutoCAD for production of plans. Our current process of plotting PDFs uses the lines merge function which puts transparency in our PDFs. Our clients have trouble plotting our PDFs due to the “flattening” process.

Basically, we now need to remove the transparency. So, what settings would you recommend to accomplish this and keep the resolution (most important) and file size (less important) in the same ballpark as the original drawing.

Can we use PDFTron Flattener or PDFNet for this?

A:

If you only want to remove transparency and may be fine with rasterizing PDF, the simplest option would be to use PDFDraw (see http://www.pdftron.com/pdfnet/samplecode.html#PDFDraw) to rasterize PDF pages with transparency and replace the existing pages with rasterized version (e.g. see AddImage sample for how to create a PDF page from a Bitmap).

For discussion on how to determine if a PDF has transparency, please see:
https://groups.google.com/d/topic/pdfnet-sdk/Ke75f9qBGYc/discussion

That said, there are multiple methods used to control Flattener:

  • You can use SetDPI and SetMaximumImagePixels to increase the resolution of flattened content.
  • SetPreferJPG(false) will cause these images to be compressed with FLATE instead of JPEG compression (which is lossy).
  • SetTreshold can be used to control when text is flattened (see http://www.pdftron.com/pdfnet/PDFNet/html/T_pdftron_PDF_Flattener_Threshold.htm).
  • Flattening with e_fast instead of e_simple will result in less content being flattened.

Regarding pdftron.PDF.Flattener if you were dealing with primarily text based document ‘Flattener.FlattenMode.e_simple’ option (http://www.pdftron.com/pdfnet/docs/PDFNetC/d1/d35/classpdftron_1_1_p_d_f_1_1_flattener.html) would simply reduce page representation to text and a background image. However since you may be dealing with vector drawings this would not be very helpful since most pages would simply turn into images.


Another approach that could preserve vector properties of the original PDF would be to edit PDF page. The basic idea is shown in ElementEdit sample (http://www.pdftron.com/pdfnet/samplecode.html#ElementEdit) . Once you detect a transparent element you could:

  • make it solid
  • remove it
  • simulate transparency (e.g. install an image mask. E…g with checkerboard pattern). This feature does not require PDF blend or transparency features.
  • Mark the page for rasterization (via PDFDraw)