4

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...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user3336544
  • 211
  • 1
  • 4
  • 11
  • I think that Teigha is the less expensive option. AutoCAD is incredibly expensive. But that holds if you want to make it a service. If you want to make a plugin than choose the platform of the CAD program. – Ognyan Dimitrov Aug 15 '15 at 07:33
  • Teigha vs AutoCAD pricing depends on how many seats you sell and how you want to use it. From my hazy memory, once you get past 100 seats Teigha costs about the same as RealDwg. – CAD bloke Aug 20 '15 at 23:08

2 Answers2

5

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

Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44
  • is there a quickstart on how to upload, convert, download a .dwg file thought REST calls?? the documentation page does no exist : developer.api.autodesk.com/documentation/v1/acad_io/index.html#acad-io-api-reference . – user3336544 Aug 13 '15 at 12:23
  • the sample is not entirely focused on PDF, but should give you some idea: https://developer.autodesk.com/api/autocadio/#stepbystep – Augusto Goncalves Aug 13 '15 at 15:59
3

My take as of 2015:

After endless research and tests, I have concluded that there is currently NO FREE SOLUTION to convert AutoCAD .dwg files to PDF/image in Java which we can consider as reliable. This applies especially to latest versions of AutoCAD, for example: AutoCAD 2010, AutoCAD 2013, etc....

Reliable (and expensive) solutions would be Teigha by ODA (2000$ a year) and RealDWG in C# by AutoCAD (5000$ a year)...

Cheaper alternatives are as such:

  • AutoCAD I/O for 10$ per month (as suggested by Augusto Gonclaves)
  • Writing a LISPS routine and running them with a SCRIPT file in a paid instance of AutoCAD 2015/2016..
  • Wait for a more complete implementation of AutoCAD Core Console...

Open-source libraries such as Kabeja and YCad may be able to deal with older AutoCAD versions, but do not expect much from them as these projects are inactive since a few years ago. It's worth to keep an eye out for Apache Tika though, since they started writing parsers for .dwg files, but development has been slow...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user3336544
  • 211
  • 1
  • 4
  • 11