Skip to content

DWG 转 PDF

福昕 PDF SDK 自 10.0 版本起,新增了强大的 DWG 转 PDF 功能,旨在满足工程、设计等领域用户对 CAD 图纸文件转换的需求。该功能允许开发者通过简单的 API 调用,将 DWG 格式的二维图形文件高精度地转换为 PDF 文档,保留原始图纸的布局、尺寸和细节。

该功能具有以下特点:

  • 高精度转换: 确保转换后的 PDF 文件尽可能地还原 DWG 文件的原始视觉效果和数据信息。
  • 灵活的输出设置: 开发者可以根据需求,设置 PDF 输出的各种参数,如页面尺寸、嵌入字体、图层控制等。
  • 跨平台支持: 支持 Windows、Linux 和 Mac 等主流操作系统,方便开发者集成到不同的应用环境中。
  • 多语言支持: 支持C, C++, Java, C#, Python, Objective-C, Node.js 等多种程序语言。

通过福昕 PDF SDK 的 DWG 转 PDF 功能,开发者可以轻松地将 CAD 图纸融入 PDF 工作流程,实现图纸的便捷共享、长期存档和高效打印。为快速上手,开发者可查阅 DWG 转 PDF 示例配置与运行指南,了解配置步骤和运行示例,快速掌握该功能的使用方法。

将 DWG 文件转换为 PDF

以下代码演示如何配置 DWG2PDFSettingData 对象,设置导出选项,然后调用 Convert.FromDWG 方法执行转换。

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("@foxitsoftware/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);