program AutoCADtoPDF;
{$APPTYPE CONSOLE}
uses
SysUtils,
Variants,
Windows,
Dialogs,
ActiveX,
UDC_TLB,
AXDBLib_TLB,
AutoCAD_TLB;
procedure PrintAutoCADtoPDF(AutoCADFilePath: string);
var
objUDC: IUDC;
Printer: IUDCPrinter;
Profile: IProfile;
App: AcadApplication;
Doc: AcadDocument;
Layout: AcadLayout;
Version: Double;
FormatSettings: TFormatSettings;
ReadOnly, Password: OleVariant;
nBACKGROUNDPLOT, nFILEDIA, nCMDDIA: OleVariant;
xNull: OleVariant;
SaveChanges: OleVariant;
begin
objUDC := CoAPIWrapper.Create;
Printer := objUDC.get_Printers('Universal Document Converter');
Profile := Printer.Profile;
Profile.Load('C:\Program Files\Universal Document Converter\UDC Profiles\Drawing to PDF.xml');
Profile.OutputLocation.Mode := LM_PREDEFINED;
Profile.OutputLocation.FolderPath := 'c:\UDC Output Files';
Profile.PostProcessing.Mode := PP_OPEN_FOLDER;
App := CoAcadApplication.Create;
GetLocaleFormatSettings($0409 , FormatSettings);
Version := StrToFloat(Copy(App.Version, 1, 4), FormatSettings);
ReadOnly := False;
Password := Variants.EmptyParam;
Doc := App.Documents.Open(AutoCADFilePath, ReadOnly, Password);
if Doc.ActiveSpace = acPaperSpace then
Layout := Doc.PaperSpace.Layout
else Layout := Doc.ModelSpace.Layout;
Layout.PlotType := acExtents;
Layout.UseStandardScale := True;
Layout.StandardScale := acScaleToFit;
Layout.CenterPlot := True;
nBACKGROUNDPLOT := 0;
nFILEDIA := 0;
nCMDDIA := 0;
if Version >= 16.1 then
begin
nBACKGROUNDPLOT := Doc.GetVariable('BACKGROUNDPLOT');
nFILEDIA := Doc.GetVariable('FILEDIA');
nCMDDIA := Doc.GetVariable('CMDDIA');
xNull := 0;
Doc.SetVariable('BACKGROUNDPLOT', xNull);
Doc.SetVariable('FILEDIA', xNull);
Doc.SetVariable('CMDDIA', xNull);
end;
Doc.Plot.QuietErrorMode := True;
Doc.Plot.PlotToDevice('Universal Document Converter');
if Version >= 16.1 then
begin
Doc.SetVariable('BACKGROUNDPLOT', nBACKGROUNDPLOT);
Doc.SetVariable('FILEDIA', nFILEDIA);
Doc.SetVariable('CMDDIA', nCMDDIA);
end;
SaveChanges := False;
Doc.Close(SaveChanges, Variants.EmptyParam);
App.Quit();
end;
var
TestFilePath: string;
begin
TestFilePath := ExtractFilePath(ParamStr(0)) + 'TestFile.dwg';
try
CoInitialize(nil);
try
PrintAutoCADtoPDF(TestFilePath);
finally
CoUninitialize;
end;
except
on E: Exception do
MessageDlg(E.ClassName + ' : ' + E.Message, mtError, [mbOK], 0);
end;
end.
|