void __fastcall PrintPDF(UnicodeString lpInFileName, UnicodeString DirOutFile, UnicodeString lpOutFileName)
{
TclsPDFCreator* oPDFCreator = new TclsPDFCreator(NULL);
oPDFCreator->Connect();
oPDFCreator->cStart(L"/NoProcessingAtStartup", true);
oPDFCreator->cVisible = true;
oPDFCreator->cPrinterStop = true;
oPDFCreator->cClearCache();
oPDFCreator->cDefaultPrinter = WideString(“PDFCreator”).c_bstr();
_clsPDFCreatorOptionsPtr opt = oPDFCreator->get_cOptions();
opt->UseAutosave = 1;
opt->UseAutosaveDirectory = 1;
opt->AutosaveFormat = 0; // ; 0=PDF, 1=PNG, 2=JPG, 3=BMP, 4=PCX, 5=TIFF, 6=PS, 7= EPS, 8=ASCII
opt->AutosaveStartStandardProgram = 0;
opt->UseStandardAuthor = 1;
opt->StandardAuthor = L"";
opt->AutosaveDirectory = WideString(DirOutFile).c_bstr();
opt->AutosaveFilename = WideString(lpOutFileName).c_bstr();
oPDFCreator->_set_cOptions(opt);
oPDFCreator->cPrinterStop = false;
oPDFCreator->cPrintURL(WideString(lpInFileName).c_bstr(), 100);
while (oPDFCreator->cCountOfPrintjobs != 1)
{
Sleep(10);
Application->ProcessMessages();
}
while (oPDFCreator->cCountOfPrintjobs != 0)
{
Sleep(10);
Application->ProcessMessages();
}
oPDFCreator->cClearCache();
oPDFCreator->cPrinterStop = true;
oPDFCreator->cClearCache(); // Clean cache
Application->ProcessMessages();
VARIANT_BOOL bClose = oPDFCreator->cClose();
Application->ProcessMessages();
oPDFCreator->Disconnect();
Sleep(500);
delete oPDFCreator;
Sleep(1500);
Application->ProcessMessages();
}