Skip to content

DWG to PDF

Foxit PDF SDK has added a powerful DWG to PDF function since version 10.0, aiming to meet the needs of users in engineering, design and other fields for converting CAD drawing files. This function allows developers to convert 2D graphics files in DWG format into PDF documents with high precision through simple API calls, retaining the layout, size and details of the original drawings.

This feature has the following features:

  • High-precision conversion: Ensure that the converted PDF file restores the original visual effects and data information of the DWG file as much as possible.
  • Flexible output settings: Developers can set various parameters for PDF output according to their needs, such as page size, embedded fonts, layer control, etc.
  • Cross-platform support: Supports mainstream operating systems such as Windows, Linux and Mac, making it easier for developers to integrate into different application environments.
  • Multi-language support: Supports multiple programming languages ​​such as C, C++, Java, C#, Python, Objective-C, Node.js, go, etc.

Through the DWG to PDF function of Foxit PDF SDK, developers can easily integrate CAD drawings into PDF workflows to achieve convenient sharing, long-term archiving and efficient printing of drawings. To get started quickly, developers can refer to the DWG to PDF Example Configuration and Operation Guide to learn about the configuration steps and running examples, and quickly master how to use this function.

Convert DWG files to PDF

The following code demonstrates how to configure a DWG2PDFSettingData object, set export options, and then call the Convert.FromDWG method to perform the conversion.

c++
#include "include/addon/conversion/fs_convert.h"

foxit::addon::conversion::DWG2PDFSettingData pdf_setting_data;
pdf_setting_data.export_flags = foxit::addon::conversion::DWG2PDFSettingData::e_FlagEmbededTTF; pdf_setting_data.export_hatches_type = foxit::addon::conversion::DWG2PDFSettingData:: e_DWG2PDFExportHatchesTypeBitmap;
pdf_setting_data.other_export_hatches_type = foxit::addon::conversion::DWG2PDFSettingData:: e_DWG2PDFExportHatchesTypeBitmap;
pdf_setting_data.gradient_export_hatches_type = foxit::addon::conversion::DWG2PDFSettingData:: e_DWG2PDFExportHatchesTypeBitmap;
pdf_setting_data.searchable_text_type = foxit::addon::conversion::DWG2PDFSettingData:: e_DWG2PDFSearchableTextTypeNoSearch;
pdf_setting_data.is_active_layout = false; pdf_setting_data.paper_width = 640;
pdf_setting_data.paper_heigh = 900;
...
foxit::addon::conversion::Convert::FromDWG(engine_path, dwg_file_path, output_path, pdf_setting_data);
C
#include "include/fs_basictypes_c.h"
#include "include/fs_convert_c.h"

// Make sure that SDK has already been initialized successfully.

FSHDWG2PDFSettingData pdf_setting_data;

pdf_setting_data.export_flags = e_FlagEmbededTTF; pdf_setting_data.export_hatches_type = e_DWG2PDFExportHatchesTypeBitmap; pdf_setting_data.other_export_hatches_type = e_DWG2PDFExportHatchesTypeBitmap; pdf_setting_data.gradient_export_hatches_type = e_DWG2PDFExportHatchesTypeBitmap; pdf_setting_data.searchable_text_type = e_DWG2PDFSearchableTextTypeNoSearch; pdf_setting_data.is_active_layout = false;
pdf_setting_data.paper_width = 640;
pdf_setting_data.paper_heigh = 900;

FSDK_Convert_FromDWG(engine_path.c_str(), dwg_file_path.c_str(), output_path.cstr(), pdf_setting_data);
java
import com.foxit.sdk.addon.conversion.DWG2PDFSettingData;
import com.foxit.sdk.addon.conversion.Convert;

// Make sure that SDK has already been initialized successfully.

com.foxit.sdk.addon.conversion.DWG2PDFSettingData pdf_setting_data = new com.foxit.sdk.addon.conversion. DWG2PDFSettingData();
pdf_setting_data.setExport_flags(DWG2PDFSettingData.e_FlagEmbededTTF); pdf_setting_data.setExport_hatches_type(DWG2PDFSettingData.e_DWG2PDFExportHatchesTypeBitmap); pdf_setting_data.setOther_export_hatches_type(DWG2PDFSettingDatae_DWG2PDFExportHatchesTypeBitmap); pdf_setting_data.setGradient_export_hatches_type(DWG2PDFSettingDatae_DWG2PDFExportHatchesTypeBitmap) pdf_setting_data.setSearchable_text_type(DWG2PDFSettingData.e_DWG2PDFSearchableTextTypeNoSearch); pdf_setting_data.setIs_active_layout(false);
pdf_setting_data.setPaper_width(640); pdf_setting_data.setPaper_height(900);

com.foxit.sdk.addon.conversion.Convert.FromDWG(engine_path, dwg_file_path, output_path, pdf_setting_data);
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    # replace with the python2 lib path
    site.addsitedir(‘../../../’)
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *


pdf_setting_data = DWG2PDFSettingData()

pdf_setting_data.export_flags = DWG2PDFSettingData.e_FlagEmbededTTF pdf_setting_data.export_hatches_type = DWG2PDFSettingData.e_DWG2PDFExportHatchesTypeBitmap pdf_setting_data.other_export_hatches_type = DWG2PDFSettingData.e_DWG2PDFExportHatchesTypeBitmap pdf_setting_data.gradient_export_hatches_type = DWG2PDFSettingData.e_DWG2PDFExportHatchesTypeBitmap pdf_setting_data.searchable_text_type = DWG2PDFSettingData.e_DWG2PDFSearchableTextTypeNoSearch pdf_setting_data.is_active_layout = False
pdf_setting_data.paper_width = float(640) pdf_setting_data.paper_heigh = float(900)
Convert.FromDWG(engine_path, dwg_file_path, output_path, pdf_setting_data)
objc
#include "FSPDFObjC.h"

FSDWG2PDFSettingData *pdf_setting_data = [FSDWG2PDFSettingData new]; 
pdf_setting_data.export_flags = FSDWG2PDFSettingDataFlagEmbededTTF; pdf_setting_data.export_hatches_type = FSDWG2PDFSettingDataDWG2PDFExportHatchesTypeBitmap; pdf_setting_data.other_export_hatches_type = FSDWG2PDFSettingDataDWG2PDFExportHatchesTypeBitmap;
pdf_setting_data.gradient_export_hatches_type = FSDWG2PDFSettingDataDWG2PDFExportHatchesTypeBitmap; pdf_setting_data.searchable_text_type = FSDWG2PDFSettingDataDWG2PDFSearchableTextTypeNoSearch; pdf_setting_data.is_active_layout = false;
pdf_setting_data.paper_width = 640;
pdf_setting_data.paper_heigh = 900;

[FSConvert fromDWG:engine_path src_dwg_path:dwg_file_path saved_pdf_path:output_path settings:pdf_setting_data];
js
const FSDK = require("@fuxinsoft/foxit-pdf-sdk-node");

let settings = new FSDK.DWG2PDFSettingData();
settings.export_flags = FSDK.DWG2PDFSettingData.e_FlagEmbededTTF;
settings.export_hatches_type = FSDK.DWG2PDFSettingData.e_DWG2PDFExportHatchesTypeBitmap;
settings.other_export_hatches_type = FSDK.DWG2PDFSettingData.e_DWG2PDFExportHatchesTypeBitmap;
settings.gradient_export_hatches_type = FSDK.DWG2PDFSettingData.e_DWG2PDFExportHatchesTypeBitmap;
settings.searchable_text_type = FSDK.DWG2PDFSettingData.e_DWG2PDFSearchableTextTypeNoSearch;
settings.is_active_layout = false;
settings.paper_width = 640;
settings.paper_height = 900;
FSDK.Convert.FromDWG(engine_path, dwg_file_path, output_file_path, settings);
csharp
using foxit;

// Make sure that SDK has already been initialized successfully.

foxit.addon.conversion.DWG2PDFSettingData pdf_setting_data = new 
foxit.addon.conversion.DWG2PDFSettingData(); pdf_setting_data.export_flags = foxit.addon.conversion.DWG2PDFSettingData.DWG2PDFExportFlags.e_FlagEmbededTTF; pdf_setting_data.export_hatches_type = foxit.addon.conversion.DWG2PDFSettingData.DWG2PDFExportHatchesType. e_DWG2PDFExportHatchesTypeBitmap;
pdf_setting_data.other_export_hatches_type = foxit.addon.conversion.DWG2PDFSettingData.DWG2PDFExportHatchesType. e_DWG2PDFExportHatchesTypeBitmap;
pdf_setting_data.gradient_export_hatches_type = foxit.addon.conversion.DWG2PDFSettingData. DWG2PDFExportHatchesType.e_DWG2PDFExportHatchesTypeBitmap;
pdf_setting_data.searchable_text_type = foxit.addon.conversion.DWG2PDFSettingData.DWG2PDFSearchableTextType. e_DWG2PDFSearchableTextTypeNoSearch;
pdf_setting_data.is_active_layout = false; pdf_setting_data.paper_width = 640;
pdf_setting_data.paper_heigh = 900;
...
foxit.addon.conversion.Convert.FromDWG(engine_path, dwg_file_path, output_path, pdf_setting_data);
go
import (
. "foxit.com/fsdk"
“fmt”
)  

pdf_setting_data := NewDWG2PDFSettingData()

pdf_setting_data.SetExport_flags(DWG2PDFSettingDataE_FlagEmbededTTF)
pdf_setting_data.SetExport_hatches_type(DWG2PDFSettingDataE_DWG2PDFExportHatchesTypeBitmap) pdf_setting_data.SetOther_export_hatches_type(DWG2PDFSettingDataE_DWG2PDFExportHatchesTypeBitmap) pdf_setting_data.SetGradient_export_hatches_type(DWG2PDFSettingDataE_DWG2PDFExportHatchesTypeBitmap) 
pdf_setting_data.SetSearchable_text_type(DWG2PDFSettingDataE_DWG2PDFSearchableTextTypeNoSearch) pdf_setting_data.SetIs_active_layout(false)
pdf_setting_data.SetPaper_width(640) 
pdf_setting_data.SetPaper_heigh(900)
ConvertFromDWG(engine_path, dwg_file_path, output_path, pdf_setting_data)