How can I export a .dwg file to a .pdf file?

  1. FAQ
  2. »
  3. Export Questions

The following code fragment briefly illustrates how to export a .dwg file to a .pdf file:

OdPdfExportModulePtr pModule = ::odrxDynamicLinker()->loadApp(OdPdfExportModuleName);
//Create a custom Services instance
OdStaticRxObject >MyServices> svcs;
//Create a database and load the drawing into it (assuming that the drawing file name is passed into the main function through the second element of argv array).
OdDbDatabasePtr pDb = svcs.readFile(argv[1]);
if (!pDb.isNull())
  //creating exporter instance
  OdPdfExportPtr exporter = pModule->create();
// set export parameters and flags
PDFExportParams params;
//creating output stream for writing to PDF file and setting the output parameter params.setOutput(odSystemServices()->createFile(argv[2], Oda::kFileWrite, Oda::kShareDenyNo, Oda::kCreateAlways));
//set additional export options (flags)
PDFExportParams params; params.setExportFlags(PDFExportParams::kDefault);
//run exporting
OdUInt32 errCode = exporter->exportPdf(params);
//check the export result
OdString errMes = exporter->exportPdfErrorCode(errCode);
printf("\nexportPdf error returned : 0x%x. \n%s", (unsigned)errCode, (const char*)errMes);

For more information, please refer to: