> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/core/get-started/samples/cad2pdftest.md).

# Convert CAD to PDF - CAD2PDF

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),

{% hint style="info" %}
**Requirements**

*These packages are required to use these features in production. Trial keys have unlimited access to all features*

<a href="/core/get-started/get-started.md" class="button primary">Server SDK</a><a href="https://apryse.com/capabilities#CADConversion" class="button primary">Package: CAD Conversion</a><a href="/core/learn-more/modules.md#cad-module" class="button primary">Module: CAD</a><a href="https://showcase.apryse.com/cad-viewer" class="button primary">Live demo</a>
{% endhint %}

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 convert CAD to PDF with Apryse SDK with this sample, you will need:

1. [Get started with Server SDK](/core/get-started/get-started.md) in your language/framework
2. [Download the CAD Module](/core/learn-more/modules.md#cad-module)
3. Add the sample code provided below

Learn more about our [Server SDK](/core/get-started/get-started.md) and [PDF Conversion Library](/core/conversion/conversion.md).\
For a version of this in Node.js, including our WebViewer UI, check out the [CAD Viewer Showcase Demo Code Sample](/web/get-started/samples/showcase-demo-cad-viewer.md)

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.     
//---------------------------------------------------------------------------------------

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

using pdftron;
using pdftron.Common;
using pdftron.PDF;
using pdftron.SDF;

namespace CAD2PDFTestCS
{
    /// <summary>
    //---------------------------------------------------------------------------------------
    // The following sample illustrates how to convert CAD documents (such as dwg, dgn, rvt, 
    // dxf, dwf) to pdf 
    //---------------------------------------------------------------------------------------
    /// </summary>
    class Class1
    {
        private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
        static Class1() {}

        /// <summary>
        /// Check file extension
        /// </summary>
        static bool IsRVTFile(string input_file_name)
        {
            bool rvt_input = false;
            if (input_file_name.Length > 2)
            {
                if (input_file_name.Substring(input_file_name.Length - 3, 3) == "rvt")
                {
                    rvt_input = true;
                }
            }
            return rvt_input;
        }

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            // 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(PDFTronLicense.Key);
            PDFNet.AddResourceSearchPath("../../../../../Lib/");
            if (!CADModule.IsModuleAvailable())
            {
                Console.WriteLine();
                Console.WriteLine("Unable to run CAD2PDFTest: Apryse SDK CAD module not available.");
                Console.WriteLine("---------------------------------------------------------------");
                Console.WriteLine("The CAD module is an optional add-on, available for download");
                Console.WriteLine("at http://www.pdftron.com/. If you have already downloaded this");
                Console.WriteLine("module, ensure that the SDK is able to find the required files");
                Console.WriteLine("using the PDFNet::AddResourceSearchPath() function.");
                Console.WriteLine();
            }

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

            string input_file_name = "construction drawings color-28.05.18.dwg";
            string output_file_name = "construction drawings color-28.05.18.pdf";

            if (args.Length != 0)
            {
                input_file_name = args[0];
                output_file_name = input_file_name + ".pdf";
            }

            Console.WriteLine("Example cad:");
            try
            {
                using (PDFDoc pdfdoc = new PDFDoc())
                {
                    if (IsRVTFile(input_file_name))
                    {
                        CADConvertOptions opts = new CADConvertOptions();
                        opts.SetPageWidth(800);
                        opts.SetPageHeight(600);
                        opts.SetRasterDPI(150);

                        pdftron.PDF.Convert.FromCAD(pdfdoc, input_path + input_file_name, opts);
                    }
                    else
                    {
                        pdftron.PDF.Convert.FromCAD(pdfdoc, input_path + input_file_name, null);
                    }
                    pdfdoc.Save(output_path + output_file_name, SDFDoc.SaveOptions.e_remove_unused);
                }

                Console.WriteLine("Done.");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
            PDFNet.Terminate();
        }
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

#include <PDF/PDFNet.h>
#include <PDF/PDFDoc.h>
#include <PDF/Convert.h>
#include <PDF/CADModule.h>
#include <PDF/CADConvertOptions.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include "../../LicenseKey/CPP/LicenseKey.h"

using namespace pdftron;
using namespace pdftron::SDF;
using namespace PDF;
using namespace std;


//---------------------------------------------------------------------------------------
// The following sample illustrates how to convert CAD documents to PDF format 
// 
// The CAD module is an optional PDFNet Add-on that can be used to convert CAD
// documents into PDF documents
//
// The Apryse SDK CAD module can be downloaded from http://www.pdftron.com/
//---------------------------------------------------------------------------------------

UString inputPath("../../TestFiles/CAD/");
UString outputPath("../../TestFiles/Output/");

bool IsRVTFile(UString inputFile)
{
	bool rvt_input = false;
	if (inputFile.GetLength() > 2)
	{
		if (inputFile.SubStr(inputFile.GetLength() - 3, 3) == "rvt")
		{
			rvt_input = true;
		}
	}
	return rvt_input;
}

int main(int argc, char *argv[])
{
	int ret = 0;
	
	try
	{
		// 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::AddResourceSearchPath("../../../Lib/");
		if(!CADModule::IsModuleAvailable())
		{
			cout << endl;
			cout << "Unable to run CAD2PDFTest: Apryse SDK CAD module not available." << endl;
			cout << "---------------------------------------------------------------" << endl;
			cout << "The CAD module is an optional add-on, available for download" << endl;
			cout << "at http://www.pdftron.com/. If you have already downloaded this" << endl;
			cout << "module, ensure that the SDK is able to find the required files" << endl;
			cout << "using the PDFNet::AddResourceSearchPath() function." << endl << endl;
			return 0;
		}

		typedef struct
		{
			UString inputFile, outputFile;
		} TestFile;
		
		UString inputFileName, outputFileName;
		if (argv[1])
		{
			inputFileName = argv[1];
		}
		else
		{
			inputFileName = "construction drawings color-28.05.18.dwg";
		}
		outputFileName = inputFileName + ".pdf";
		
		TestFile testFiles[] =
		{
			{ inputFileName,	outputFileName},
		};

		unsigned int ceTestFiles = sizeof(testFiles) / sizeof(TestFile);
		for (unsigned int i = 0; i < ceTestFiles; i++)
		{

			// Convert the rest of the samples
			if (IsRVTFile(testFiles[i].inputFile))
			{
				try
				{
					PDFDoc pdfdoc;
					// Convert rvt file with some user options
					CADConvertOptions opts;
					opts.SetPageWidth(800);
					opts.SetPageHeight(600);
					opts.SetRasterDPI(150);

					Convert::FromCAD(pdfdoc, inputPath + testFiles[i].inputFile, &opts);
					pdfdoc.Save(outputPath + testFiles[i].outputFile, SDF::SDFDoc::e_linearized, NULL);
				}
				catch (Common::Exception& e)
				{
					cout << "Unable to convert file " << testFiles[i].inputFile << endl;
					cout << e << endl;
					ret = 1;
				}
				catch (...)
				{
					cout << "Unknown Exception" << endl;
					ret = 1;
				}
			}
			else
			{
				try
				{
					PDFDoc pdfdoc;
					Convert::FromCAD(pdfdoc, inputPath + testFiles[i].inputFile, NULL);
					pdfdoc.Save(outputPath + testFiles[i].outputFile, SDF::SDFDoc::e_linearized, NULL);
				}
				catch (Common::Exception& e)
				{
					cout << "Unable to convert file " << testFiles[i].inputFile << endl;
					cout << e << endl;
					ret = 1;
				}
				catch (...)
				{
					cout << "Unknown Exception" << endl;
					ret = 1;
				}
			}
		}

	}
	catch (Common::Exception& e)
	{
		cout << e << endl;
		ret = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}
	PDFNet::Terminate();
	return ret;
}
```

{% endcode %}
{% endtab %}

{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------

package main
import (
	"fmt"
	. "pdftron"
)

import  "pdftron/Samples/LicenseKey/GO"

// Relative path to the folder containing test files.
var inputPath = "../../TestFiles/CAD/"
var outputPath = "../../TestFiles/Output/"

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

func 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.
    PDFNetInitialize(PDFTronLicense.Key)
    
    // The location of the CAD Module
    PDFNetAddResourceSearchPath("../../../PDFNetC/Lib/")
    
    if ! CADModuleIsModuleAvailable(){

        fmt.Println("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.")

    }else{

        inputFileName := "construction drawings color-28.05.18.dwg"
        outputFileName := inputFileName + ".pdf"
        doc := NewPDFDoc()
        ConvertFromCAD(doc, inputPath + inputFileName)
        doc.Save(outputPath + outputFileName, uint(0))
    }
    PDFNetTerminate()
    fmt.Println("CAD2PDF conversion example")
}
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

import com.pdftron.common.PDFNetException;
import com.pdftron.pdf.*;
import com.pdftron.sdf.Obj;
import com.pdftron.sdf.ObjSet;
import com.pdftron.sdf.SDFDoc;

//---------------------------------------------------------------------------------------
// The following sample illustrates how to convert CAD documents to PDF format using
// the CAD2PDF class.
// 
// 'pdftron.PDF.CAD2PDF' is an optional PDFNet Add-On utility class that can be 
// used to convert CAD documents into PDF documents by using an external module (cad2pdf).
//
// cad2pdf modules can be downloaded from http://www.pdftron.com/pdfnet/downloads.html.
//---------------------------------------------------------------------------------------
public class CAD2PDFTest {
	
	public static boolean IsRVTFile(String input_file_name)
	{
		boolean rvt_input = false;
		
		if (input_file_name.length() > 2)
		{
			if (input_file_name.substring(input_file_name.length() - 3, input_file_name.length()).equals("rvt"))
			{
				rvt_input = true;
			}
		}
		return rvt_input;
	}

	public static void main(String[] args) {
		String input_file_name = "construction drawings color-28.05.18.dwg";
		String output_file_name = input_file_name + ".pdf";
		if (args.length != 0)
		{
			input_file_name = args[0];
			output_file_name = input_file_name + ".pdf";
		}
		PDFNet.initialize(PDFTronLicense.Key());
		try
		{
			PDFNet.addResourceSearchPath("../../../Lib/");
			if(!CADModule.isModuleAvailable())
			{
				System.out.println();
				System.out.println("Unable to run CAD2PDFTest: Apryse SDK CAD module not available.");
				System.out.println("---------------------------------------------------------------");
				System.out.println("The CAD module is an optional add-on, available for download");
				System.out.println("at http://www.pdftron.com/. If you have already downloaded this");
				System.out.println("module, ensure that the SDK is able to find the required files");
				System.out.println("using the PDFNet::AddResourceSearchPath() function." );
				System.out.println();
			}
		} catch (PDFNetException e) {
			System.out.println("CAD module not available, error:");
			e.printStackTrace();
			System.out.println(e);
		}


		// Relative path to the folder containing test files.
		String input_path = "../../TestFiles/CAD/";
		String output_path = "../../TestFiles/Output/";
		String outputFile;
		boolean printerInstalled = false;

		try (PDFDoc doc = new PDFDoc()) {
			if (IsRVTFile(input_file_name))
			{
				CADConvertOptions opts = new CADConvertOptions();
				opts.setPageHeight(800);
				opts.setPageWidth(300);
				Convert.fromCAD(doc, input_path + input_file_name, opts);
			}
			else
			{
				Convert.fromCAD(doc, input_path + input_file_name, null);
			}
			outputFile = output_path + output_file_name;
			doc.save(outputFile, SDFDoc.SaveMode.LINEARIZED, null);
		} catch (PDFNetException e) {
			System.out.println("Unable to convert DWG document, error:");
			e.printStackTrace();
			System.out.println(e);
		}
		PDFNet.terminate();
	}
}
```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------


//---------------------------------------------------------------------------------------
// The following sample illustrates how to convert CAD documents to PDF format 
// 
// The CAD module is an optional PDFNet Add-on that can be used to convert CAD
// documents into PDF documents
//
// The Apryse SDK CAD module can be downloaded from http://www.pdftron.com/
//---------------------------------------------------------------------------------------


const { PDFNet } = require('@pdftron/pdfnet-node');
const PDFTronLicense = require('../LicenseKey/LicenseKey');

((exports) => {
  'use strict';

  exports.runCAD2PDFTest = () => {
    const IsRVTFile = function (inputFile) {
      let rvt_input = false;
      if (inputFile.length > 2) {
        if (inputFile.substr(inputFile.length - 3, 3) === 'rvt') {
          rvt_input = true;
        }
      }
      return rvt_input;
    }

    const main = async () => {
      try {
        await PDFNet.addResourceSearchPath('../../lib/');
        if (!(await PDFNet.CADModule.isModuleAvailable())) {
          console.log('\nUnable to run CAD2PDFTest: Apryse SDK CAD module not available.');
          console.log('---------------------------------------------------------------');
          console.log('The CAD module is an optional add-on, available for download');
          console.log('at http://www.pdftron.com/. If you have already downloaded this');
          console.log('module, ensure that the SDK is able to find the required files');
          console.log('using the PDFNet.addResourceSearchPath() function.\n');

          return;
        }

        // Relative path to the folder containing test files.
        const inputPath = '../TestFiles/CAD/';
        const outputPath = '../TestFiles/Output/';

        const input_file_name = 'construction drawings color-28.05.18.dwg';
        const output_file_name = 'construction drawings color-28.05.18.pdf';

        const doc = await PDFNet.PDFDoc.create();
        doc.initSecurityHandler();

        if (IsRVTFile(input_file_name)) {
          const opts = new PDFNet.Convert.CADConvertOptions();
          opts.setPageWidth(800);
          opts.setPageHeight(600);
          opts.setRasterDPI(150);
          await PDFNet.Convert.fromCAD(doc, inputPath + input_file_name, opts);
        } else {
          await PDFNet.Convert.fromCAD(doc, inputPath + input_file_name);
        }
        const outputFile = outputPath + output_file_name;
        await doc.save(outputFile, PDFNet.SDFDoc.SaveOptions.e_linearized);
      } catch (err) {
        console.log(err);
      }
    };
    PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
      console.log('Error: ' + JSON.stringify(error));
    }).then(function(){ return PDFNet.shutdown(); });
  };
  exports.runCAD2PDFTest();
})(exports);
// eslint-disable-next-line spaced-comment
//# sourceURL=CAD2PDFTest.js
```

{% endcode %}
{% endtab %}

{% tab title="PHP" %}
{% code lineNumbers="true" %}

```php
<?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 https://dev.apryse.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();
?>
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software 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 https://dev.apryse.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()
```

{% endcode %}
{% endtab %}

{% tab title="Ruby" %}
{% code lineNumbers="true" %}

```ruby
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

require '../../../PDFNetC/Lib/PDFNetRuby'
include PDFNetRuby
require '../../LicenseKey/RUBY/LicenseKey'

$stdout.sync = true

# 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
#---------------------------------------------------------------------------------------

	# 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(PDFTronLicense.Key)
	
	# The location of the CAD Module
	PDFNet.AddResourceSearchPath("../../../PDFNetC/Lib/");
	
	begin  
		if !CADModule.IsModuleAvailable
			puts 'Unable to run CAD2PDFTest: PDFTron SDK CAD module not available.'
			puts '---------------------------------------------------------------'
			puts 'The CAD module is an optional add-on, available for download'
			puts 'at https://dev.apryse.com/. If you have already downloaded this'
			puts 'module, ensure that the SDK is able to find the required files'
			puts 'using the PDFNet::AddResourceSearchPath() function.'
		else
			inputFileName = "construction drawings color-28.05.18.dwg"
			outputFileName = inputFileName + ".pdf"
			doc = PDFDoc.new
			Convert.FromCAD(doc, input_path + inputFileName)
			doc.Save(output_path + outputFileName, 0)
			puts "CAD2PDF conversion example"
			doc.Close
		end
	rescue Exception=>e
		puts e

	end
	PDFNet.Terminate
```

{% endcode %}
{% endtab %}

{% tab title="VB" %}
{% code lineNumbers="true" %}

```vb
Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Imports pdftron
Imports pdftron.Common
Imports pdftron.PDF
Imports pdftron.SDF

Namespace CAD2PDFTestVB
    Class Class1
        Private Shared pdfNetLoader As pdftron.PDFNetLoader = pdftron.PDFNetLoader.Instance()

        Private Shared Function IsRVTFile(ByVal input_file_name As String) As Boolean
            Dim rvt_input As Boolean = False

            If input_file_name.Length > 2 Then

                If input_file_name.Substring(input_file_name.Length - 3, 3) = "rvt" Then
                    rvt_input = True
                End If
            End If

            Return rvt_input
        End Function

        Shared Sub Main(ByVal args As String())
            PDFNet.Initialize(PDFTronLicense.Key)
            PDFNet.AddResourceSearchPath("../../../../../Lib/")

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

            Dim input_path As String = "../../../../TestFiles/CAD/"
            Dim output_path As String = "../../../../TestFiles/Output/"
            Dim input_file_name As String = "construction drawings color-28.05.18.dwg"
            Dim output_file_name As String = "construction drawings color-28.05.18.pdf"

            If args.Length <> 0 Then
                input_file_name = args(0)
                output_file_name = input_file_name & ".pdf"
            End If

            Console.WriteLine("Example cad:")

            Try

                Using pdfdoc As PDFDoc = New PDFDoc()

                    If IsRVTFile(input_file_name) Then
                        Dim opts As CADConvertOptions = New CADConvertOptions()
                        opts.SetPageWidth(800)
                        opts.SetPageHeight(600)
                        opts.SetRasterDPI(150)
                        pdftron.PDF.Convert.FromCAD(pdfdoc, input_path & input_file_name, opts)
                    Else
                        pdftron.PDF.Convert.FromCAD(pdfdoc, input_path & input_file_name, Nothing)
                    End If

                    pdfdoc.Save(output_path & output_file_name, SDFDoc.SaveOptions.e_remove_unused)
                End Using

                Console.WriteLine("Done.")
            Catch e As PDFNetException
                Console.WriteLine(e.Message)
            End Try
            PDFNet.Terminate()
        End Sub
    End Class
End Namespace
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/core/get-started/samples/cad2pdftest.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
