Export Questions

  1. FAQ

Do you have a demo about exporting a .dwg file?

You can find some videos regarding exports on our YouTube channel:

ExportToRaster
ColladaExport
ExportToHOOPS

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

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;
odInitialize(&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;
params.setDatabase(pDb);
params.setVersion(PDFExportParams::kPDFv1_5);
//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:

When I export a drawing that contains a zoomed part to an .svg file, I have a result where only the part I see without zooming is exported to .svg. How can I fix it?

Please refer to:

  • /Drawing/Examples/OdSvgExportEx — Contains code to export the extents of model space. Search OdSvgExportEx.cpp for "zoomExtents".
  • /Kernel/Exports/RasterExport — Contains code that zooms to extents for the active layout.

Search RasterExportCmd.cpp for zoomToExtents().
Note: RasterExport works the same for all formats supported by Teigha (.dwg, .dgn, .rvt, etc.)

How to export a .dxf file with colored elements to a black and white .svg file?

Please refer to the "Export to .pdf File Parameters and Flags" topic and look for the "Export to a monochrome or a grayscale .pdf file" section. Although this applies to exporting to .pdf files, it works the same for .svg also.

After exporting a .dwg drawing to an .svg file, text has characters that were replaced by other symbols. How can I fix it?

The application can't find the .shx and .ttf files that contain the needed characters. To solve this problem:

  1. Put the font file in the same folder as the drawing.
  2. If the drawing is placed in a folder other than the application, use the ACAD environment variable to set the folder with the needed font or use the application's findFile() method to specify where the font file is located.
  3. OdString fontFile = pHostApp->findFile(L"fontFileName.ttf"); // Or use the full path name
    
    OdTtfDescriptor descr;
    
    pHostApp->ttfFileNameByDescriptor(descr, fontFile);
    

Detailed information about font handling can be found in the Font Handling topic.

Does Drawings SDK support thread-safe exporting to .svg and .png files?

Drawings SDK completely supports multi-threading only for loading and saving .dwg/.dxf files and vectorization (raster export). Importing and exporting to .svg and .png files is not currently checked and is unsafe; you can use them in a multi-threaded environment only at your own risk.

Why do I get a blank .pdf file when trying to export a drawing to .pdf with the exportPdf() function?

Probably, loading the PdfModule is missing from the beginning of your code:

::odrxDynamicLinker()->loadModule(OdPdfModuleVIModuleName);
Without this module, PdfUnderlay is invisible and the export saves nothing or saves just an extents rectangle.

How to export a .dwg drawing to a vector image (.svg)?

To export a .dwg drawing to a vector image file:

  1. Load the OdGsModule module.
  2. Create the graphics device.
  3. Set the required rendering properties.
  4. Set up the layout to render.
  5. Define the device output rectangle.
  6. Initiate the rendering process using the OdGsDevice::update() method.

For more details, see OdSvgExportEx sample application (\Core\Exports\RasterExport\).

How to export a .dwg drawing to a raster image (.bmp, .jpeg, .png)?

To export a dwg drawing to a raster image file:

  1. Get the device for bitmap creation.
  2. Load the RxRasterServices module.
  3. Set the raster image parameters (e.g., width, height, bits per pixel, etc.).
  4. Call the saveRasterImage() method of the raster services object.

For more details, see the RasterExport sample application (\Core\Exports\RasterExport\).

How to export a .dwg drawing to a .pdf file?

To export a dwg drawing to a .pdf file, follow the steps below:

  1. Load the PDF export module.
  2. Create a PDF export instance.
  3. Set the PDF export parameters.
  4. Call the exportPdf() method of the exporter object.

For more details, see the OdPdfExportEx sample application (\Examples\OdPdfExportEx).