PDF conversion problems (iii). Converting AutoCAD drawings into PDF documents

Source: Internet
Author: User

PDF conversion problems (iii). Converting AutoCAD drawings into PDF documents

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:

////// Obtain the ACAD internal printer object parameters through custom print parameters //////Drawing Object///Custom print Parameters///
  
   
Built-in printer Parameters
  Public static AcadPlotConfiguration getPlotConfiguration (AcadDocument document, PlotSetting plotSetting) {PageSize pageSize = plotSetting. pageSize; AcadPlotConfiguration plotConfiguration = document. plotConfigurations. add (Guid. newGuid (). toString ("N"), document. activeLayout. modelType); plotConfiguration. configName = plotSetting. printer; // Printer name plotConfiguration. styleSheet = plotSetting. styleSheet; // 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. translateCoordinates (new double [] {pageSize. lowerLeftX, pageSize. lowerLeftY, 0}, AcCoordinateSystem. acWorld, AcCoordinateSystem. acDisplayDCS, 0, Type. missing) as double []; double [] UpperR Ight = document. utility. translateCoordinates (new double [] {pageSize. upperRightX, pageSize. upperRightY, 0}, AcCoordinateSystem. acWorld, AcCoordinateSystem. acDisplayDCS, 0, Type. missing) as double []; plotConfiguration. setWindowToPlot (new double [] {LowerLeft [0], LowerLeft [1]}, new double [] {UpperRight [0], UpperRight [1]}); plotConfiguration. plotType = AcPlotType. acWindow; // print mode plotConfiguratio N. standardScale = AcPlotScale. acScaleToFit; // standard ratio, which must be UseStandardScale = true; plotConfiguration. useStandardScale = true; // configuration. useStandardScale = false; // configuration. setCustomScale (1, 30); plotConfiguration. centerPlot = true; // center print plotConfiguration. paperUnits = AcPlotPaperUnits. acMillimeters; // unit: plotConfiguration. plotRotation = (pageSize. rotation? AcPlotRotation. ac90degrees: AcPlotRotation. ac0degrees); // portrait // plotConfiguration. PlotHidden = false; // hide the metadata return plotConfiguration ;}////// Print the model space of the drawing to the PDF file //////Drawing Object///Printer settingsPublic static void goPlotting (AcadDocument document, PlotSetting 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.