Setting the Drawing Size and Paper Size when Exporting to PDF

Sergey Sherstnev

October 24, 2019

A common problem can occur when exporting a drawing to PDF: the exported drawing might look incorrect in a PDF reader. Fortunately, it’s usually a quick fix by setting the appropriate paper size according to the drawing size.

Here are some common ways that output .pdf files don’t look correct: lines are too bold and merged, details are not visible, or sometimes even nothing can be clearly seen in the exported PDF.

 

output .pdf files doesn’t look correct

 

The most common reason for these issues is an inconsistency between the drawing size and the size of the paper that is chosen for the PDF export.

Let’s imagine that we are trying to print a huge solid drawing, which has a large real extents, onto a tiny paper. Of course, the closest lines, text characters, etc. will be incorrect. This is often the situation when the drawing has a default paper size like ANSI A4 or Letter or when exporting to PDF using the default option Zoom to Extents with the A4 paper size in the ODA Debug App (OdaMfcApp.exe).

There are several ways to fix the issue. The first is to set the proper paper size that conforms to the drawing size and layout plot settings, and to not use the Zoom to Extents option.

PDFExportParams params;
params.setExportFlags(PDFExportParams::PDFExportFlags(params.exportFlags() & ~PDFExportParams::kZoomToExtentsMode));
OdDbPlotSettingsValidatorPtr pPlotValidator = pDb->appServices()->plotSettingsValidator();

OdDbLayoutPtr pLayout = OdDbLayoutPtr(pDb->currentLayoutId().safeOpenObject(OdDb::kForWrite));
OdDbPlotSettings *pPlotSettings = pLayout.get();

pPlotValidator->refreshLists(0);

OdResult res = pPlotValidator->setPlotCfgName(pPlotSettings, "DWG To PDF.pc3");
res = pPlotValidator->setCanonicalMediaName(pPlotSettings, OD_T("ISO_A1_(841.00_x_594.00_MM)"));

An easier way to set the paper size is like this:

PDFExportParams params;
params.setExportFlags(PDFExportParams::PDFExportFlags(PDFExportParams::kDefault));
params.pageParams().resize(1, OdGsPageParams(420, 297));

In both cases the resulting .pdf file can be properly displayed in a PDF reader.

 

.pdf file can be properly displayed in a PDF reader

 

A third way can be used if you need to export to tiny paper for some reason. In this case, do not print lineweights:

OdDbLayoutPtr pLayout = OdDbBlockTableRecordPtr(pDb->getActiveLayoutBTRId().safeOpenObject())->getLayoutId().safeOpenObject(OdDb::kForWrite);
pLayout->setPrintLineweights(false);

With this option all lines are printed with zero lineweights, but there is a side effect. If we export SHX fonts not as a geometry, the text (if such fonts are placed in the .pdf file) can be pale in comparison with the same settings on big paper.

 

export SHX fonts

 

This is caused by how the SHX fonts are stored in .pdf files.

Exporting to PDF is a great way to distribute and share drawings. Hopefully these tips will help you create consistently good-looking .pdf files.