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 into One .pdf File

Since version 21.2 Drawings SDK provides the possibility to export more than one different drawings into one output .pdf file through the native export interface. The topic describes how to use this functionality in your custom applications.

It is assumed that you have two drawings (it can be more than two): Test.dwg and Test2.dwg and you want to export their contents into a .pdf file.

The export routine is detailed below.

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

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

  4. Create an instance of PDFExportParams class and associate the layouts and the databases with it through 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:

Another advantage of multi-database export: databases of different formats can be exported into one output .pdf file. To use this advantage, it is enough to load libraries, which implements the reading functionality of an appropriate 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");
      
    

After that, we can export the loaded database using the ordinary routine described earlier.

See Also

Export to .pdf File Parameters and Flags

Export to .pdf File Examples

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