Universal Document Converter
Información general
Descargas
Comprar
Tutoriales
Desarrolladores
Soporte técnico
Acerca de fCoder SIA


      Búsqueda en el sitio
   


      Conversiones populares
Adobe PDF a JPEG
Word Document a PDF
Hojas de cálculo Excel a PDF
PowerPoint a JPEG
Diseño Visio a PDF
Diseño AutoCAD a TIFF
Página web a JPEG
Convertir de cálculo Excel a PDF
Convertir DjVu a PDF
Convertir una página web a PDF

      Tutorial de vídeo
Ver el tutorial



Página principal>Developer Solutions>Examples>Visual C++>AutoCAD Drawings to PDF

Converting AutoCAD Drawings to PDF


//////////////////////////////////////////////////////////////////
// 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
  itfProfile->Load("C:\\Program Files\\Universal Document Converter\\UDC Profiles\\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 Acerca de fCoder SIA | Mapa del sitio