CAD Module is a new optional add-on utility which can be used with Apryse SDK 7.0 or later to convert CAD documents to PDF while preserving layers without any external dependencies. Supported CAD formats include DWG, DWF, DXF, and DGN can be directly converted to PDF using the PDF.Convert.FromCAD method with this module. Beta support for RVT format is also available on Windows.
2PDFNet::GetSystemFontList(); // Wait for fonts to be loaded if they haven't already. This is done because PHP can run into errors when shutting down if font loading is still in progress.
3PDFNet::AddResourceSearchPath("../../../Lib/");
4if(!CADModule::IsModuleAvailable()) {
5 echo "Unable to run CAD2PDFTest: Apryse SDK CAD module not available.";
5 fmt.Println("Apryse SDK CAD module not available.\n")
6}
If the module has been successfully added, you can use the Convert.FromCAD method. This method requires that you pass in a PDFDoc object that will append converted pages to the specified PDF document.
You can also optionally provide a CADConvertOptions as an argument to change the PageHeight and PageWidth attributes for the conversion of the CAD document. If your document is of the RVT format, you can also set the RasterDPI and Sheets attributes to control the rasterization resolution and list of sheets to be converted (RVT beta support currently only available on Windows). You must call the AddSheets method multiple times depending on the number of sheets you would like to add.
1CADConvertOptions opts = new CADConvertOptions();
By default, layers present in the original CAD drawing will be preserved as Optional Content Groups (OCGs) in the PDF. OCGs can be extracted, edited, manipulated, and removed with Apryse SDK. They can also be rendered into a viewer where users can interact with them.
Sample
The CAD Module ships with the CAD2PDFTest sample which can be used to test the conversion functionality using provided test files or your own documents. The sample first initializes PDFNet, which is required for all Apryse SDK functionality, then uses PDFNet.AddResourceSearchPath to include the CAD Module. The same lines of code can be used to integrate the module in your application or project.
The CAD2PDFTest sample also shows how to check if a file is of RVT file format and uses CADConvertOptions to convert to PDF (currently only supported on Windows).
Troubleshooting
Fonts
For best results, the CAD Module requires access to the fonts (SHX, RSC and TTF) used in the drawing. If the requisite fonts are not embedded in the drawing and not installed on your server, the CAD Module will use its own bundled fonts (located in the in fonts/ folder within the CAD module package) as substitutes for the originals. The specifics of the substitution mappings are defined in a file called substitution.json (which is also located in the fonts/ folder). If necessary, this file can be customized to define different font mappings or add new mappings. The JSON has following entries:
fontFileMappings:
This is where direct substitutions based on font file name are specified.
For each font you want to replace, you can define multiple fonts in list form. CAD Module searches fonts one by one from the beginning of the list and choose the first font that is found.
fallbackFonts:
This is where fallback fonts are defined.
Fallback fonts for monospaced and proportional font are defined separately.
You can define/customize fallback fonts for each language as needed; default ones are used otherwise.
An alternative way of performing direct substitutions for a font is to provide a font file and name it as "<target_font_name>_fallback.[ttf | ttc |otf]". For example, If you want to map iso8.shx to a TTF font, then name your TTF file to iso8_fallback.ttf and place it in the location discoverable by the CAD Module (you can use PDFNet.AddResourceSearchPath() to specify the location of the font). Note that the fallback font name must be in lowercase. This method takes priority over the JSON file method.
OpenGL
On Linux CADModule uses OpenGL API for rendering 3D objects. In a headless server environment (i.e., without monitors/graphical drivers) implementation of OpenGL specification needs to be provided. One such implementation is Mesa. On headless Linux you may need to install libgl1-mesa-dev, libx11-dev and libglu1-mesa-dev.