At present, domestic enterprises are not very automated, and most of them cannot use 3D images for direct processing and production. Therefore, 2D images are still the most fundamental production basis for most enterprises. In enterprises, converting two-dimensional graphs to PDF is a very important small step, because subsequent printing and communication between enterprises are inseparable from PDF documents transferred from two-dimensional graphs.
In 3D CAD design software, 2D graph to PDF is generally a built-in function of the software, so these software generally provides an API directly to implement the function of converting PDF. For example, the toolkit library of proe and the nxopen library of NX (note that it is not a C library, but a C ++ library. The C library of NX does not seem to have the function of converting to PDF ). However, AutoCAD, a well-known software that leads the world's two-dimensional drawing design standards, does not have a built-in PDF conversion function.
Early versions of AutoCAD do not support PDF conversion at all. At that time, to convert DWG drawings to PDF, you must use a third-party library opendwg (early name: DWG DirectX) to Convert PDF files, either print the drawing into PDF using the Adobe Acrobat printer. Later, AutoCAD was built in ...... A printer that prints drawings into PDF files. I have never studied converting opendwg library to PDF and printing PDF with Acrobat printers. I mainly use the DWG to 2D printer that comes with AutoCAD.
There are two ways to use the DWG to export printer to print drawings: Calling Based on the AutoCAD com Library (Using ObjectARX in C ++ to do this I have not studied) and based on AutoCAD.. Net Library.
Com Library:
/// <Summary> /// obtain the Acad internal printer object parameters through custom print parameters /// </Summary> /// <Param name = "document"> Drawing Object </param> /// <Param name = "plotsetting"> Custom print parameters </param> /// <returns> built-in printer parameters </returns> Public static acadplotconfiguration getplotconfiguration (acaddocument document, plotsetting) {pagesize = plotsetting. pagesize; acadplotconfiguration plotconfiguration = document. plotconfigurations. add (GUI D. newguid (). tostring ("N"), document. activelayout. modeltype); plotconfiguration. configname = plotsetting. printer; // printer name plotconfiguration. stylesheet = plotsetting. stylesheet; // The style table name plotconfiguration. plotwithlineweights = true; // ratio of the width to the width of the plotconfiguration. plotwithplotstyles = true; // use the style plotconfiguration. canonicalmedianame = pagesize. name; // drawing size double [] lowerleft = document. utility. translatecoord Inates (New Double [] {pagesize. lowerleftx, pagesize. lowerlefty, 0}, accoordinatesystem. acworld, accoordinatesystem. acdisplaydcs, 0, type. missing) as double []; double [] upperright = document. utility. translatecoordinates (New Double [] {pagesize. upperrightx, pagesize. upperrighty, 0}, accoordinatesystem. acworld, accoordinatesystem. acdisplaydcs, 0, type. missing) as double []; plotconfiguration. setwind Owtoplot (New Double [] {lowerleft [0], lowerleft [1]}, new double [] {upperright [0], upperright [1]}); plotconfiguration. plottype = acplottype. acwindow; // print mode plotconfiguration. standardscale = acplotscale. acscaletofit; // standard ratio, which must be usestandardscale = true; plotconfiguration. usestandardscale = true; // configuration. usestandardscale = false; // configuration. setcustomscale (1, 30); plotconfiguration. cente Rplot = true; // center print plotconfiguration. paperunits = acplotpaperunits. acmillimeters; // unit: plotconfiguration. plotrotation = (pagesize. rotation? Acplotrotation. ac90degrees: acplotrotation. ac0degrees); // horizontal vertical // plotconfiguration. plothidden = false; // hide the metadata return plotconfiguration ;} /// <summary> /// print the model space of the drawing to the PDF file /// </Summary> /// <Param name = "document"> Drawing Object </param> /// <Param name = "plotsetting"> printer setting </param> Public static void goplotting (acaddocument document, plotsetting) {If (acactivespace. acpaperspace = document. activespace) {document. mspace = true; document. activespace = acactivespace. acmodelspace;} document. regen (acregentype. acallviewports); object oisbackground = document. getvariable ("backgroundplot"); acadplotconfiguration plotconfiguration = getplotconfiguration (document, plotsetting); acadlayout layout = document. activelayout; layout. copyfrom (plotconfiguration); layout. refreshplotdeviceinfo (); document. setvariable ("backgroundplot", 0); // Print Document on the foreground. plot. quieterrormode = true; document. plot. numberofcopies = 1; document. plot. plottofile (plotsetting. targetfile, plotsetting. printer); plotconfiguration. delete (); document. setvariable ("backgroundplot", oisbackground );}
. Net Library:
public static void goPlotting(PlotEngine engine, PlotInfo plotInfo, PlotPageInfo pageInfo, string sName, string sFile) { PlotInfoValidator validator = new PlotInfoValidator(); validator.MediaMatchingPolicy = MatchingPolicy.MatchEnabled; validator.Validate(plotInfo); engine.BeginPlot(null, null); engine.BeginDocument(plotInfo, sName, null, 1, true, sFile); engine.BeginPage(pageInfo, plotInfo, true, null); engine.BeginGenerateGraphics(null); engine.EndGenerateGraphics(null); engine.EndPage(null); engine.EndDocument(null); engine.EndPlot(null); }
The main feature of the COM library is that an external program can be used to start and operate AutoCAD to facilitate integration with other software. the main feature of the net Library is that it has transactions and other things. Compared with the com library, some operations (such as traversing the model library) will be much faster, but unfortunately it can only be used in AutoCAD internal processes.
PDF conversion problems (iii). Converting AutoCAD drawings into PDF documents