Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java library to programmatically convert AutoCAD .dwg files to PDF or image? [closed]

Tags:

autocad

dwg

Is there a Java library (free and open source) that converts .dwg files directly to PDFs or images file? The .dwg uses recent normes of CAD (R14, R13, R12, and 2013).

I know that there are a few in .NET and C++... The ones in Java are mostly proprietary and expensive (example: Teigha for Java).

The free ones in Java such as Kabeja passes through an intermediary format, .dxf, which is a very huge file...

like image 968
user3336544 Avatar asked Oct 12 '25 08:10

user3336544


1 Answers

Not sure about libraries, but you can certainly use AutoCAD I/O, which is AutoCAD running as a webservice that works without any app on your machine. See more at http://developer.autodesk.com

Here is a script (.scr) that you can use on AutoCAD Console to create PDF files. Worked really good here.

(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 

And if you're feeling like 'old-school', create a .BAT file with:

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

This should batch process all DWGs at a specific folder to PDF

like image 144
Augusto Goncalves Avatar answered Oct 16 '25 07:10

Augusto Goncalves