Drawings SDK Developer Guide > Working with .dwg Files > Working with Other File Formats > Exporting to Other Formats > Exporting to a PDF File > Export Several Drawings into One PDF File
Export Several Drawings to one PDF File

Since Drawings SDK version 21.2, you can export more than one drawing to one output PDF file through the native export interface. This topic describes how to use this functionality in your custom applications.

For the following example, there are two (or more) drawings: Test.dwg and Test2.dwg.

To export the two drawings to PDF.

  1. Open the original drawing databases:
              
    OdDbDatabasePtr pDb1 = pHostApp->readFile("Test1.dwg");
    OdDbDatabasePtr pDb2 = pHostApp->readFile("Test2.dwg");
              
            
  2. Fill the layouts array, the same way you would fill it when you want to export several layouts from one drawing:
              
    OdArray < OdString > layoutsArray;
    layoutsArray.push_back(L"Layout1");
    layoutsArray.push_back(L"Layout1");
              
            
  3. Fill the database array:
              
    OdRxObjectPtrArray dbArray;
    dbArray.push_back(pDb1);
    dbArray.push_back(pDb2);
              
            

    Now you have two corresponding arrays: the array of layouts and the array of drawing databases. The array of layouts contains two similar names ("Layout1"), but these layouts belong to different databases. This approach allows mixing layouts from different databases.

  4. Create an instance of the PDFExportParams class and associate the layouts and databases with it by calling the setLayouts() method:
              
    PDFExportParams params;
    params.setLayouts(layoutsArray, &dbArray);
              
            
  5. Optionally, to zoom the exported content to extents, set the kZoomToExtentsMode flag:
              
    params.setExportFlags(PDFExportParams::PDFExportFlags(PDFExportParams::kFlateCompression | PDFExportParams::kZoomToExtentsMode));
              
            
  6. Fill the page params array:
              
    OdGsPageParams pageParams;
    pageParams.set(210, 297);
    params.pageParams().resize(nPages, pageParams);
              
            
  7. Load the export module, create an exporter object, and call its exportPdf() method:
              
    OdPdfExportModulePtr pModule = ::odrxDynamicLinker()->loadApp(OdPdfExportModuleName, false);
    OdPdfExportPtr exporter = pModule->create();
    
    OdUInt32 errorCode = exporter->exportPdf(params);
              
            

The output PDF file is illustrated in the picture below:

You can also get access to the list of drawing databases that store the layouts you want to export. Use the databases() method of the PDFExportParams class for this purpose.

To clear all settings related to exporting layouts from multiple databases, call the clearMultipleDbSettings() method of the PDFExportParams class.

There is another advantage of multi-database export: databases of different formats can be exported to one output PDF file. Simply load the libraries that implement read functionality for the appropriate file format, then read the database content. For example, it is possible to export a BimRv database:

      
OdStaticRxObject <OdExBimHostAppServices> bimSvc;
::odrxDynamicLinker()->loadModule(OdBmBaseModuleName, false);
::odrxDynamicLinker()->loadModule(OdBmLoaderModuleName, false);
::odrxDynamicLinker()->loadModule(OdBmLabelUtils, false);
OdDbBaseDatabasePtr pDb3 = bimSvc.readFile(L"bim_file.rfa");
      
    

Then you can export the loaded database using the same routine described earlier.

See Also

Export Layouts and Set Page Parameters for PDF

Export to PDF Parameters and Flags

Examples of Exporting to PDF

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