Convert CAD to PDF - CAD2PDF - PHP Sample Code

Sample code demonstrates how to use the Apryse CAD module for direct, high-quality conversion from DWG, DXF, DGN, DWF, and RVT to PDF. Samples provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby, Go and VB.

To run this sample, you will need:

  1. Get started with Server SDK in your language/framework
  2. Download the CAD Module

Learn more about our Server SDK and PDF Conversion Library.

1<?php
2//---------------------------------------------------------------------------------------
3// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
4// Consult LICENSE.txt regarding license information.
5//---------------------------------------------------------------------------------------
6if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
7include("../../../PDFNetC/Lib/PDFNetPHP.php");
8include("../../LicenseKey/PHP/LicenseKey.php");
9
10// Relative path to the folder containing the test files.
11$input_path = getcwd()."/../../TestFiles/CAD/";
12$output_path = getcwd()."/../../TestFiles/Output/";
13
14//---------------------------------------------------------------------------------------
15// The following sample illustrates how to use CAD module
16//---------------------------------------------------------------------------------------
17
18 // The first step in every application using PDFNet is to initialize the
19 // library and set the path to common PDF resources. The library is usually
20 // initialized only once, but calling Initialize() multiple times is also fine.
21 PDFNet::Initialize($LicenseKey);
22 PDFNet::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.
23
24 // The location of the CAD Module
25 PDFNet::AddResourceSearchPath("../../../Lib/");
26 if(!CADModule::IsModuleAvailable()) {
27 echo "Unable to run CAD2PDFTest: PDFTron SDK CAD module not available.\n
28 ---------------------------------------------------------------\n
29 The CAD module is an optional add-on, available for download\n
30 at https://dev.apryse.com/. If you have already downloaded this\n
31 module, ensure that the SDK is able to find the required files\n
32 using the PDFNet::AddResourceSearchPath() function.\n";
33 } else
34 {
35 $doc = new PDFDoc();
36 Convert::FromCAD($doc, $input_path."construction drawings color-28.05.18.dwg");
37 $doc->Save($output_path."construction drawings color-28.05.18.dwg.pdf", 0);
38 echo "CAD2PDF conversion example \n";
39 }
40 PDFNet::Terminate();
41?>

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales