Convert CAD to PDF - CAD2PDF - Go Sample Code

Requirements
View Demo

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 in your language/framework
  2. Download the CAD Module
  3. Add the sample code provided below

To use this feature in production, your license key will need the CAD Conversion Package. Trial keys already include all packages.

Learn more about our Server SDK and PDF Conversion Library.

1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3// Consult LICENSE.txt regarding license information.
4//---------------------------------------------------------------------------------------
5
6package main
7import (
8 "fmt"
9 . "pdftron"
10)
11
12import "pdftron/Samples/LicenseKey/GO"
13
14// Relative path to the folder containing test files.
15var inputPath = "../../TestFiles/CAD/"
16var outputPath = "../../TestFiles/Output/"
17
18// ---------------------------------------------------------------------------------------
19// The following sample illustrates how to use CAD module
20// --------------------------------------------------------------------------------------
21
22func main(){
23
24 // The first step in every application using PDFNet is to initialize the
25 // library and set the path to common PDF resources. The library is usually
26 // initialized only once, but calling Initialize() multiple times is also fine.
27 PDFNetInitialize(PDFTronLicense.Key)
28
29 // The location of the CAD Module
30 PDFNetAddResourceSearchPath("../../../PDFNetC/Lib/")
31
32 if ! CADModuleIsModuleAvailable(){
33
34 fmt.Println("Unable to run CAD2PDFTest: PDFTron SDK CAD module not available.\n" +
35 "---------------------------------------------------------------\n" +
36 "The CAD module is an optional add-on, available for download\n" +
37 "at http://www.pdftron.com/. If you have already downloaded this\n" +
38 "module, ensure that the SDK is able to find the required files\n" +
39 "using the PDFNet::AddResourceSearchPath() function.")
40
41 }else{
42
43 inputFileName := "construction drawings color-28.05.18.dwg"
44 outputFileName := inputFileName + ".pdf"
45 doc := NewPDFDoc()
46 ConvertFromCAD(doc, inputPath + inputFileName)
47 doc.Save(outputPath + outputFileName, uint(0))
48 }
49 PDFNetTerminate()
50 fmt.Println("CAD2PDF conversion example")
51}

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales