Some test text!

Search
Hamburger Icon

PHP CAD to PDF converter (DWG, DXF, DGN, DWF, and RVT)

More languages

More languages
C++
C#
C# (.NET Core)
Go
Java
JS (Node.js)
PHP
Python
Ruby
VB

Sample PHP code demonstrates how to use the Apryse CAD module for direct, high-quality conversion from DWG, DXF, DGN, DWF, and RVT to PDF. Learn more about our PHP PDF Library and PDF Conversion Library.

Get Started Samples Download

To run this sample, get started with a free trial of Apryse SDK.

<?php
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------
if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
include("../../../PDFNetC/Lib/PDFNetPHP.php");
include("../../LicenseKey/PHP/LicenseKey.php");

// Relative path to the folder containing the test files.
$input_path = getcwd()."/../../TestFiles/CAD/";
$output_path = getcwd()."/../../TestFiles/Output/";

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use CAD module
//---------------------------------------------------------------------------------------
	
	// The first step in every application using PDFNet is to initialize the 
	// library and set the path to common PDF resources. The library is usually 
	// initialized only once, but calling Initialize() multiple times is also fine.
	PDFNet::Initialize($LicenseKey);
	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.

	// The location of the CAD Module
	PDFNet::AddResourceSearchPath("../../../Lib/");
	if(!CADModule::IsModuleAvailable()) {
		echo "Unable to run CAD2PDFTest: PDFTron SDK CAD module not available.\n
			---------------------------------------------------------------\n
			The CAD module is an optional add-on, available for download\n
			at http://www.pdftron.com/. If you have already downloaded this\n
			module, ensure that the SDK is able to find the required files\n
			using the PDFNet::AddResourceSearchPath() function.\n";
	} else
	{
		$doc = new PDFDoc();
		Convert::FromCAD($doc, $input_path."construction drawings color-28.05.18.dwg");
		$doc->Save($output_path."construction drawings color-28.05.18.dwg.pdf", 0);
		echo "CAD2PDF conversion example \n";
	}
	PDFNet::Terminate();
?>