Universal Document Converter
Product Overview
Download
Purchase
Tutorials
Developer Solutions
Support Service
About fCoder SIA


      Site search
   


      Popular conversions
PDF to JPG converter
Convert Word to PDF
Convert PDF to TIFF
Autocad to PDF converter
Convert Word to JPG
Powerpoint to PDF converter
Printing to PDF
Convert Excel to PDF
Convert DJVU to PDF
Convert Web Page to PDF

      Video tutorials
Show tutorial



Main page>Developer Solutions>Examples>Visual C++>AutoCAD Drawings to PDF

Converting AutoCAD Drawings to PDF for Visual C++


//////////////////////////////////////////////////////////////////
// This example was designed for using in Microsoft Visual C++ from 
// Microsoft Visual Studio 2003 or above.
//
// 1. Autodesk AutoCAD 2000 or above should be installed and activated on your PC.
//    Autodesk AutoCAD LT does not have COM interface and cannot be used as COM-server!
//
// 2. Universal Document Converter 5.2 or above should be installed, too.
//
// 3. You must initialize the COM before you call any COM method.
// Please insert "::CoInitialize(0);" in your application initialization
// and "::CoUninitialize();" before closing it.
//
// 4. Import AutoCAD libraries for 32-bit version of Windows.
// For 64-bit version please change "C:\\Program Files\\" to
// "C:\\Program Files (x86)\\" in all pathes.
#pragma message("Import AutoCAD API")
// AutoCAD 2000 -> "C:\\Program Files\\ACAD2000\\acad.tlb"
// AutoCAD 2002 -> "C:\\Program Files\\AutoCAD 2002\\acad.tlb"
// AutoCAD 2004 -> "C:\\Program Files\\Common Files\\Autodesk Shared\\acax16enu.tlb"
// AutoCAD 2005 -> "C:\\Program Files\\Common Files\\Autodesk Shared\\acax16enu.tlb"
// AutoCAD 2006 -> "C:\\Program Files\\Common Files\\Autodesk Shared\\acax16enu.tlb"
// AutoCAD 2007 -> "C:\\Program Files\\Common Files\\Autodesk Shared\\acax17enu.tlb"
// AutoCAD 2008 -> "C:\\Program Files\\Common Files\\Autodesk Shared\\acax17enu.tlb"
// AutoCAD 2009 -> "C:\\Program Files\\Common Files\\Autodesk Shared\\acax17enu.tlb"
#import "C:\\Program Files\\Common Files\\Autodesk Shared\\acax17enu.tlb"\
    rename_namespace("ACAD"), auto_rename
// 5. Import Universal Document Converter software API:
#import "progid:udc.apiwrapper" rename_namespace("UDC")
//////////////////////////////////////////////////////////////////
void PrintAdobePDFToJPEG( CString sFilePath )
{
  LONG nBACKGROUNDPLOT, nFILEDIA, nCMDDIA;
  float fAppVer = 0.f;
  UDC::IUDCPtr pUDC(__uuidof(UDC::APIWrapper));
  UDC::IUDCPrinterPtr itfPrinter = pUDC->Printers["Universal Document Converter"];
  UDC::IProfilePtr itfProfile = itfPrinter->Profile;
// Use Universal Document Converter API to change settings of converterd drawing
// Load profile located in folder "%APPDATA%\UDC Profiles".
// Value of %APPDATA% variable should be received using Windows API's SHGetSpecialFolderPath function.
// Or you can move default profiles into a folder you prefer.   
  itfProfile->Load("Drawing to PDF.xml");
 
  itfProfile->OutputLocation->Mode = UDC::LM_PREDEFINED;
  itfProfile->OutputLocation->FolderPath = L"C:\\Out";
  itfProfile->PostProcessing->Mode = UDC::PP_OPEN_FOLDER;
// Run AutoCAD as COM-server
  ACAD::IAcadApplicationPtr objACADApp(L"AutoCAD.Application");
  ACAD::IAcadDocumentPtr itfDrawing;
  ACAD::IAcadLayoutPtr itfLayout;
  ACAD::IAcadPaperSpacePtr itfActiveSpace;
  sscanf_s( objACADApp->Version, "%f", &fAppVer );
// Open drawing from file
  itfDrawing = objACADApp->Documents->Open( (LPCTSTR)sFilePath, false );
// Change AutoCAD preferences for scaling the drawing to page
  if( itfDrawing->ActiveSpace == 0 )
  {
     itfActiveSpace = itfDrawing->PaperSpace;
     itfLayout = itfActiveSpace->Layout;
  }
  else
  {
     itfActiveSpace = itfDrawing->ModelSpace;
     itfLayout = itfActiveSpace->Layout;
  }
  itfLayout->PlotType = ACAD::acExtents;
  itfLayout->UseStandardScale = true;
  itfLayout->StandardScale = ACAD::acScaleToFit;
  itfLayout->CenterPlot = true;
  if( fAppVer >= 16.1f )
  {
    nBACKGROUNDPLOT = itfDrawing->GetVariable("BACKGROUNDPLOT");
    nFILEDIA = itfDrawing->GetVariable("FILEDIA");
    nCMDDIA = itfDrawing->GetVariable("CMDDIA");
    itfDrawing->SetVariable("BACKGROUNDPLOT", 0L);
    itfDrawing->SetVariable("FILEDIA", 0L);
    itfDrawing->SetVariable("CMDDIA", 0L);
  }
  itfDrawing->Plot->QuietErrorMode = true;
// Plot the drawing
  itfDrawing->Plot->PlotToDevice("Universal Document Converter");
  if( fAppVer >= 16.1f )
  {
// Restore AutoCAD default preferences
    itfDrawing->SetVariable("BACKGROUNDPLOT", nBACKGROUNDPLOT);
    itfDrawing->SetVariable("FILEDIA", nFILEDIA);
    itfDrawing->SetVariable("CMDDIA", nCMDDIA);
  }
// Close drawing
  itfDrawing->Close(false);
// Close Autodesk AutoCAD
  objACADApp->Quit();
}


© fCoder SIA About fCoder SIA | Privacy Policy | Site Map