1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| void __fastcall TForm1::Button2Click(TObject *Sender)
{
WideString Parameters="/NoProcessingAtStart";
TCOM_clsPDFCreatorOptions Opt;
WideString FileS;
TPrinter *Prntr = Printer();
bool Ret;
AnsiString DefaultPrinter;
Label1->Caption="";
Label2->Caption="";
DefaultPrinter=Prntr->Printers->Strings[Prntr->PrinterIndex];
OpenDialog1->InitialDir=GetCurrentDir();
if (!OpenDialog1->Execute())
return;
FileS=OpenDialog1->FileName;
PDFCreator = CoclsPDFCreator::Create();
if (!PDFCreator->cStart(Parameters,Ret)) {
MessageDlg("Le serveur PDF ne peut être démarré",
mtInformation, TMsgDlgButtons() << mbOK, 0);
return;
}
if (!FileExists(FileS)) {
MessageDlg("Fichier absent",
mtInformation, TMsgDlgButtons() << mbOK, 0);
return;
}
if (!PDFCreator->cIsPrintable(FileS)) {
MessageDlg("Fichier non imprimable",
mtInformation, TMsgDlgButtons() << mbOK, 0);
return;
}
Opt=CoclsPDFCreatorOptions::Create();
Opt=PDFCreator->cOptions;
Opt->set_AutosaveDirectory(WideString(ExtractFilePath(FileS)));
Opt->set_AutosaveFilename(WideString(ChangeFileExt(ExtractFileName(FileS),"")));
Opt->set_AutosaveFormat(0);
Opt->set_UseAutosave(1);
PDFCreator->set_cVisible(0);
PDFCreator->_set_cOptions(Opt); //PDFCreator->cOptions=Opt; écriture équivalente
PDFCreator->set_cDefaultPrinter(WideString("PDFCreator"));
PDFCreator->cClearCache();
PDFCreator->cPrintFile(FileS);
PDFCreator->set_cPrinterStop(false); // il parait que cela libère la file d'attente
Timer1->Enabled=true; // lévénement OnTimer le disable
while ((PDFCreator->cOutputFilename==WideString("")) && (Timer1->Enabled)) {
Label1->Caption=PDFCreator.cOutputFilename;
Application->ProcessMessages();
Sleep(500);
}
if (!Timer1->Enabled)
Label1->Caption="Timer expiré";
else
Label1->Caption=Format("%s",ARRAYOFCONST((PDFCreator->cOutputFilename)));
PDFCreator->set_cDefaultPrinter(WideString(DefaultPrinter));
PDFCreator->cClose(); // Dans la liste des tâches PDFCreator reste présent malgré cette instruction
Timer1->Enabled=true;
while ((!PDFCreator->get_cIsClosed()) && (Timer1->Enabled)) { //Attendre le déchargement de PDFCreator
Sleep(500);
Application->ProcessMessages();
}
delete PDFCreator;
if (!Timer1->Enabled)
Label2->Caption="Timer expiré";
else
Label2->Caption="PDFCreator fermé";
} |