Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Examples of Exporting to PDF

The following sample applications show how to use PDF export features in client applications:

  • OdPdfExportEx – A console application implementing PDF export for .dwg files through a command line mode.
  • OdaMfcApp – A sample application based on the MFC class library, which contains the PDF export feature and provides a graphical user interface (GUI) for setting PDF export parameters.

OdPdfExportEx Application

Source files for OdPdfExportEx are located in Drawing/Examples/OdPdfExportEx.

In the sample application, the input argument string is used for passing the PDF export parameters:

 
        int flags = atoi(OdString(argv[3])); 
    

This string is converted into an integer value. Then the individual bits of the value are analyzed and stored into separate variables (using the GETBIT macro):


      int flags = atoi(OdString(argv[3]));
      #define COMMENTFLAG(AFLAG, ACOMMENTTRUE) if(AFLAG) STD(cout) << ACOMMENTTRUE << STD(endl)
      bool bMonoPalette (GETBIT(flags, 1) ); COMMENTFLAG( bMonoPalette,   "Monochrome mode");
      bool bActiveLayout(GETBIT(flags, 2) ); COMMENTFLAG( bActiveLayout,  "Active layout only");
    

Then the input PDF export parameters settings are parsed, and the flags property of PDFExportParams can be set:


      params.setExportFlags(PDFExportParams::PDFExportFlags(
        (bEmbededTTF          ? PDFExportParams::kEmbededTTF             : 0) |
        (bEmbededOptimizedTTF ? PDFExportParams::kEmbededOptimizedTTF    : 0) |
        (bTTFAsAGeometry      ? PDFExportParams::kTTFTextAsGeometry      : 0) |
        (bSHXAsAGeometry      ? PDFExportParams::kSHXTextAsGeometry      : 0) |
        (bEnableLayersSupport ? PDFExportParams::kEnableLayers           : 0) |
        (bIncludeOffLayers    ? PDFExportParams::kIncludeOffLayers       : 0) |
        (bUseSimpleGeomOpt    ? PDFExportParams::kSimpleGeomOptimization : 0) | 
        (bEncoded             ? PDFExportParams::kFlateCompression       : 0) |
        (bASCIIhexEncoded     ? PDFExportParams::kASCIIHexEncoding       : 0) |
        (bUseHiddenLineAlgo   ? PDFExportParams::kUseHLR                 : 0) |
        (bHyperlinks          ? PDFExportParams::kExportHyperlinks       : 0) |
        (bLinearized          ? PDFExportParams::kLinearized             : 0) |
        (bZoomToExtents       ? PDFExportParams::kZoomToExtentsMode      : 0)));
    

The command line format for the sample applications is:

usage: OdPdfExportEx <source file> <target file> <exportflags> [options]

Parameter exportflags is a bit mask represented with an integer value:

Bit position Description
0 Export in monochrome mode (supported for Windows only).
1 Export all layouts, otherwise the active layout.
2 - 3 Export solid non-gradient hatches:
  • 0 - Export solid, non-gradient hatches as bitmaps.
  • 1 - Export solid, non-gradient hatches using vectorizers.
  • 2 - Export solid, non-gradient hatches as PDF paths.
4 Export other types of hatches using vectorizers, otherwise as bitmaps.
5 Set zoom to extents.
6 Use embedded TrueType fonts.
7 Use embedded, optimized TrueType fonts.
8 Convert TrueType font text as geometry.
9 Convert SHX text as geometry.
10 Enable layer support.
11 Add invisible layers to the output PDF file.
12 Add extents bounding box.
13 Enable encoding (smaller size of the output PDF file).
14 Enable ASCII hex encoding.
15 Use hidden line removal algorithm.
16 Make TrueType text searchable. Available only if TrueType text is exported as geometry ("Convert TTF as geometry" bit is set).

See Export Fonts to PDF for additional information.

17 Make SHX text searchable. Available only if SHX text is exported as geometry ("Convert SHX as geometry" bit is set).

See Export Fonts to PDF for additional information.

18 Enable hyperlinks export.
19 Export to a web PDF file using the linearization algorithm.

See Export to a Linearized PDF File for additional information.

20 Export to a PDF file using the measuring scale.

See Export Measurement Data to PDF for additional information.

Parameter options are represented in the table below:

Option identifier and value Description
--paper PSValue Paper size (works only if the zoom to extents flag is enabled). PSValue can be one of the following:
  • A4
  • Letter
  • Custom
--paper-width XX Custom paper width of XX millimeters.
--paper-height YY Custom paper height of YY millimeters.
--geom-res YY Vector resolution is YY DPI.
--color-res YY Resolution of color raster images is YY DPI.
--bw-res YY Resolution of monochrome raster images is YY DPI.
--color-policy CPValue Color policy for the export process. CPValue can be one of the following:
  • AsIs (default)
  • MonoPlotstyle
  • Mono
  • Gray
See Export to a Monochrome or a Grayscale PDF File for additional information.
--archive ArchValue Determines to which PDF format version the original drawing is exported. ArchValue can be one of the following:
  • None. The original drawing is exported to the standard PDF format.
  • 1b. The original drawing is exported to PDF/A-1 format.
  • 2b. The original drawing is exported to PDF/A-2 format.

OdaMfcApp Application

The OdaMfcApp application provides a graphical user interface for PDF export of an opened drawing. Also, OdaMfcApp allows you to open .dwg files and explore their internal structure, manage plot style files, and many other useful actions while working with .dwg files.

Source files for OdaMfcApp are located in Drawing/Examples/win/OdaMfcApp.

Get PDF Export Sample Application Projects

After downloading and unpacking the Drawings SDK binary archive, you can find:

  • For Windows platforms: Microsoft Visual Studio solution, containing OdPdfExportEx and OdaMfcApp projects (Drawing -> Examples branch in the Solution Explorer tab). The solution is in the /Platforms/vc* subfolder of the ODA installation directory, where * is a placeholder for the downloaded configuration. For example, if you downloaded and unpacked the archive for Microsoft Visual Studio 2012 DLL release configuration, the solution file can be found in the /Platforms/vc11dll subfolder.
  • For non-Windows platforms: configure script, which allows you to generate make files for the OdPdfExport application and then build it using the make command. The generated make file is in the /Platforms/*/Drawing/Examples/OdPdfExportEx subfolder, where * is a placeholder for the downloaded configuration. For example, if you downloaded and unpacked the archive for Linux GCC 4.7 release dynamic library configuration, the make file can be found in the /Platforms/lnxX64_4.7dll/Drawing/Examples/OdPdfExportEx subfolder after running the ./configure script.

    See Compiling Sample Applications on Non-Windows Platforms for additional information.

Note that the OdaMfcApp sample application is available for Windows platforms only.

See Also

Export to PDF Overview

Export Several Drawings to One PDF File

Working with Other File Formats

Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.