Some test text!

Loading...
Guides

Python 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 Python code demonstrates how to use the PDFTron CAD module for direct, high-quality conversion from DWG, DXF, DGN, DWF, and RVT to PDF. Learn more about our Python PDF Library and PDF Conversion Library.

Get Started Samples Download

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

#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2020 by PDFTron Systems Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

import site
site.addsitedir("../../../PDFNetC/Lib")
import sys
from PDFNetPython import *

sys.path.append("../../LicenseKey/PYTHON")
from LicenseKey import *

# Relative path to the folder containing test files.
input_path = "../../TestFiles/CAD/"
output_path = "../../TestFiles/Output/"

# ---------------------------------------------------------------------------------------
# The following sample illustrates how to use CAD module
# --------------------------------------------------------------------------------------

def main():

    # 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)
    
    # The location of the CAD Module
    PDFNet.AddResourceSearchPath("../../../PDFNetC/Lib/")

    if not CADModule.IsModuleAvailable():

        print("""
        Unable to run CAD2PDFTest: PDFTron SDK CAD module not available.
        ---------------------------------------------------------------
        The CAD module is an optional add-on, available for download
        at http://www.pdftron.com/. If you have already downloaded this
        module, ensure that the SDK is able to find the required files
        using the PDFNet::AddResourceSearchPath() function.""")

    else:

        inputFileName = "construction drawings color-28.05.18.dwg"
        outputFileName = inputFileName + ".pdf"
        doc = PDFDoc()
        Convert.FromCAD(doc, input_path + inputFileName, None)
        doc.Save(output_path + outputFileName, 0)

    PDFNet.Terminate()
    print("CAD2PDF conversion example")


if __name__ == '__main__':
    main()

UPCOMING WEBINAR: Live tech update and run-through. October 21 @ 11am PDT