Questions and Answers about PDF Export Settings and Plot Settings

Sergey Sherstnev

August 24, 2017

There is often a misunderstanding between general plot settings and specific settings for exporting drawings to .pdf files. This can lead to a misunderstanding of how to implement a feature for exporting a drawing, and we also receive suggestions to add functionality to the PDF export settings when that functionality already exists in the general plot settings.

Initially it is necessary to understand that plotting a drawing is not only plotting in a .pdf file, although print to PDF is a very popular type of printing. Plotting a drawing involves settings that must be applied to the drawing regardless the type of printing, whether to a .pdf file or to paper. For example, plot area, drawing orientation, scale coefficient, etc. A full list of these settings is available in the Page Setup dialog in the OdaMfcApp example application.

image1

More details are in the documentation about Plot Settings at docs.opendesign.com (login required):

image2

To get access to these settings, open an OdDbLayout for writing, which is inherited from OdDbPlotSettings:

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


OdDbPlotSettings *pPlotSettings = pLayout.get();

And then set the necessary params using PlotSettingsValidator:

OdDbPlotSettingsValidatorPtr pValidator = pDb->appServices()->plotSettingsValidator();
pValidator->setPlotType(pPlotSettings, OdDbPlotSettings::kWindow);
pValidator->setPlotWindowArea(pPlotSettings,min_x, min_y, max_x, max_y);
pValidator->setPlotCentered(pPlotSettings, true);
pValidator->setStdScaleType(pPlotSettings, OdDbPlotSettings::kScaleToFit);

Or OdDbLayout itself:

pLayout->setPrintLineweights(bUseLW);
pLayout->setPlotPlotStyles(bUsePS);
pLayout->setScaleLineweights(bScaleLW);

Then export the drawing:

exportToPdf(pDb);

Now, let’s look at the PDF Export settings themselves. This group of settings applies to the PDF export and doesn’t concern other types of printing. The settings are for data compression, text export (as geometry or as text), preparing the document for long-term archiving (pdf/a) or Web publishing (linearization), and more. A full list of these settings is available in the Export to PDF dialog in the OdaMfcApp example application:

image3

More details are in the corresponding section of the documentation at docs.opendesign.com (login required):

image4

These settings are easy to use:

PDFExportParams params;
params.setVersion(PDFExportParams::kPDFv1_5);
params.setExportFlags(PDFExportParams::PDFExportFlags(
PDFExportParams::kSHXTextAsGeometry | PDFExportParams::kTTFTextAsGeometry |    PDFExportParams::kUseHLR | PDFExportParams::kFlateCompression));
params.setGeomDPI(m_iGeomRes);
params.setDatabase(pDb);

There is one setting that belongs to the PDF Export settings but replaces some general plot settings: PDFExportParams::kZoomToExtentsMode. This setting is roughly equivalent to the plot settings OdDbPlotSettings::kExtents, OdDbPlotSettings::kScaleToFit, PlotCentered == true that can be applied to a certain paper size:

params.setExportFlags(PDFExportParams::PDFExportFlags(PDFExportParams::kZoomToExtentsMode));
OdGsPageParams pageParams;
pageParams.set(dPaperW, dPaperH);
params.pageParams().resize(nPages, pageParams);

This was implemented specifically to be the easiest to use PDF Export setting in Teigha.

A good example of mixing up these two kinds of settings is printing transparent elements of a drawing. kExportTrancparency was added originally by mistake to the PDF Export settings:

params.setExportFlags(PDFExportParams::PDFExportFlags(PDFExportParams::kExportTrancparency));

However, with Teigha 4.2.1, kExportTrancparency had its correct place in plot settings. After, there were many questions about creating .pdf files with transparency support. Meanwhile it is not much harder than supporting transparency using PDF Export settings:

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

Finally, let’s see about one more group of settings that affects the visual appearance of exported and printed drawings: plot styles. Plot styles allow you to set the linetype, lineweight, line join and line end type, and other parameters. Plot styles are available in the Plot Style Table Editor dialog in the OdaMfcApp example application:

image5

More details are in the corresponding section of the documentation at docs.opendesign.com (login required):

image6

To use a plot style, do the following:

_tputenv(L"DDPLOTSTYLEPATHS=Path_to_plotstyles_directory");
OdDbLayoutPtr pLayout = OdDbBlockTableRecordPtr(pDb->getActiveLayoutBTRId().safeOpenObject())->getLayoutId().safeOpenObject(OdDb::kForWrite);
OdDbPlotSettingsValidatorPtr pValidator = pDb->appServices()->plotSettingsValidator();

pValidator->refreshLists(0);
pValidator->setCurrentStyleSheet((OdDbPlotSettings*)pLayout, "plotstyle.stb");
pLayout->setPlotPlotStyles(true);

exportToPdf(pDb);