Convert CAD to PDF - CAD2PDF - Ruby 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-2023 by Apryse Software Inc. All Rights Reserved.
3# Consult LICENSE.txt regarding license information.
4#---------------------------------------------------------------------------------------
5
6require '../../../PDFNetC/Lib/PDFNetRuby'
7include PDFNetRuby
8require '../../LicenseKey/RUBY/LicenseKey'
9
10$stdout.sync = true
11
12# Relative path to the folder containing test files.
13input_path = "../../TestFiles/CAD/"
14output_path = "../../TestFiles/Output/"
15
16#---------------------------------------------------------------------------------------
17# The following sample illustrates how to use CAD module
18#---------------------------------------------------------------------------------------
19
20 # The first step in every application using PDFNet is to initialize the
21 # library and set the path to common PDF resources. The library is usually
22 # initialized only once, but calling Initialize multiple times is also fine.
23 PDFNet.Initialize(PDFTronLicense.Key)
24
25 # The location of the CAD Module
26 PDFNet.AddResourceSearchPath("../../../PDFNetC/Lib/");
27
28 begin
29 if !CADModule.IsModuleAvailable
30 puts 'Unable to run CAD2PDFTest: PDFTron SDK CAD module not available.'
31 puts '---------------------------------------------------------------'
32 puts 'The CAD module is an optional add-on, available for download'
33 puts 'at https://dev.apryse.com/. If you have already downloaded this'
34 puts 'module, ensure that the SDK is able to find the required files'
35 puts 'using the PDFNet::AddResourceSearchPath() function.'
36 else
37 inputFileName = "construction drawings color-28.05.18.dwg"
38 outputFileName = inputFileName + ".pdf"
39 doc = PDFDoc.new
40 Convert.FromCAD(doc, input_path + inputFileName)
41 doc.Save(output_path + outputFileName, 0)
42 puts "CAD2PDF conversion example"
43 doc.Close
44 end
45 rescue Exception=>e
46 puts e
47
48 end
49 PDFNet.Terminate

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales