是否有将 .dwg 文件直接转换为 PDF 或图像文件的 Java 库(免费和开源)?.dwg 使用 CAD 的最新规范(R14、R13、R12 和 2013)。
我知道 .NET 和 C++ 中有一些……Java 中的那些大多是专有且昂贵的(例如:Java 的 Teigha)。
Java 中的免费文件(例如 Kabeja)通过中间格式 .dxf,这是一个非常大的文件......
不确定库,但您当然可以使用 AutoCAD I/O,它是作为 Web 服务运行的 AutoCAD,无需在您的计算机上安装任何应用程序即可运行。在http://developer.autodesk.com上查看更多信息
这是一个脚本 (.scr),您可以在 AutoCAD 控制台上使用它来创建 PDF 文件。在这里工作得很好。
(setq CurrDwgName (getvar "dwgname"))
(setq Fname (substr CurrDwgName 1 (- (strlen CurrDwgName) 4)))
(setq name (strcat (getvar "DWGPREFIX") Fname ".pdf"))
;Command:
FILEDIA
;Enter new value for FILEDIA <1>:
0
;Command:
-PLOT
;Detailed plot configuration? [Yes/No] <No>:
Yes
;Enter a layout name or [?] <Model>:
Model
;Enter an output device name or [?] <None>:
DWG To PDF.pc3
;Enter paper size or [?] <ANSI A (11.00 x 8.50 Inches)>:
ANSI A (11.00 x 8.50 Inches)
;Enter paper units [Inches/Millimeters] <Inches>:
Inches
;Enter drawing orientation [Portrait/Landscape] <Portrait>:
Landscape
;Plot upside down? [Yes/No] <No>:
No
;Enter plot area [Display/Extents/Limits/View/Window] <Display>:
Extents
;Enter plot scale (Plotted Inches=Drawing Units) or [Fit] <Fit>:
Fit
;Enter plot offset (x,y) or [Center] <0.00,0.00>:
;Plot with plot styles? [Yes/No] <Yes>:
Yes
;Enter plot style table name or [?] (enter . for none) <>:
.
;Plot with lineweights? [Yes/No] <Yes>:
Yes
;Enter shade plot setting [As displayed/legacy Wireframe/legacy Hidden/Visualstyles/Rendered] <As displayed>:
;Enter file name <C:\Work\solids-Model.pdf>:
!name
;Save changes to page setup? Or set shade plot quality? [Yes/No/Quality] <N>:
No
;Proceed with plot [Yes/No] <Y>:
Yes
;Command:
FILEDIA
;;;Enter new value for FILEDIA <1>:
1
如果您觉得自己像“老派”,请创建一个 .BAT 文件,其中包含:
FOR %%f IN (C:\dwg_folder\*.dwg) DO "C:\Program Files\Autodesk\AutoCAD 2016\accoreconsole.exe" /i "%%f" /product ACAD /s "C:\folder\PDFScript.scr" /l en-US
这应该将特定文件夹中的所有 DWG 批处理为 PDF
我对 2015 年的看法:
经过无休止的研究和测试,我得出的结论是,目前没有免费的解决方案可以将 AutoCAD .dwg 文件转换为 Java 中的 PDF/图像,我们认为这是可靠的。这尤其适用于最新版本的 AutoCAD,例如:AutoCAD 2010、AutoCAD 2013 等......
可靠(且昂贵)的解决方案将是 ODA 的 Teigha(每年 2000 美元)和 AutoCAD 的 C# 中的 RealDWG(每年 5000 美元)......
更便宜的替代品如下:
Kabeja 和 Ycad 等开源库可能能够处理较旧的 AutoCAD 版本,但不要对它们抱有太大期望,因为这些项目自几年前以来就处于非活动状态。不过,值得关注 Apache Tika,因为他们开始为 .dwg 文件编写解析器,但开发一直很缓慢......