I have a Problem with the Driver API and Delphi. We migrate from PDFX 2 to PDFX 4 with the need COM-Interface. After modifying my code (from ESC-Sequences to COM) everything seems to work fine with the new Version 4. But now I have problems with printing when creating a lot of PDFs in a bulk job. The pdfsaver just stops and creates no files. After killing the pdfsave4.exe process and restarting my app, some pdfs were generated until it stops again. The exact same routine works since years with the v2 of PDFX.
So I tried to simplify and reproduce this problem in your Sample code. As you can see I modified the methods “FormCreate”, “b_goClick” and “FormDestroy”:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
// InitSaverObj;
end;
procedure TForm1.b_goClick(Sender: TObject);
begin
if ed_Dest.Text='' then
exit;
InitSaverObj;
PDFPrinter.SetAsDefaultPrinter;
IsPXCPrinterDefault:=true;
PDFPrinter.Option['Save.RunApp']:=cb_RunViewer.checked;
//
PDFPrinter.Option['Save.File'] := ed_Dest.Text;
PDFPrinter.Option['Save.SaveType'] := 'Save';
PDFPrinter.Option['Save.ShowSaveDialog'] := 'No';
PDFPrinter.Option['Save.WhenExists'] := 'Overwrite';
//
if cb_Compression.Checked then
begin
PDFPrinter.Option['Compression.Graphics'] := 'Yes';
PDFPrinter.Option['Compression.Text'] := 'Yes';
PDFPrinter.Option['Compression.ASCII'] := 'No';
PDFPrinter.Option['Compression.Color.Enabled'] := 'Yes';
PDFPrinter.Option['Compression.Color.Method'] := 'Auto';
PDFPrinter.Option['Compression.Indexed.Enabled'] := 'Yes';
PDFPrinter.Option['Compression.Indexed.Method'] := 'Auto';
PDFPrinter.Option['Compression.Mono.Enabled'] := 'Yes';
PDFPrinter.Option['Compression.Mono.Method'] := 'Auto';
end
else //cb_Compression.Checked
begin
PDFPrinter.Option['Compression.Graphics'] := 'No';
PDFPrinter.Option['Compression.Text'] := 'No';
end; //not cb_Compression.Checked
//
PDFPrinter.Option['Fonts.EmbedAll'] := cb_embFonts.Checked;
if PageControl1.TabIndex=0 then
begin
Printer.Orientation := poLandscape;
Printer.BeginDoc;
Printer.Canvas.TextOut(300, 300, ed_textout.Text);
Printer.NewPage;
Printer.EndDoc;
end
else
if PageControl1.TabIndex=1 then
begin
if FileExists(ed_FileToPrint.Text) then
ShellExecute(HWND(nil), 'printto', PChar(ed_FileToPrint.Text), PChar('"' + PrinterName + '"'), nil, SW_MINIMIZE);
end
else
if PageControl1.TabIndex=2 then
begin
if (WebBrowser1.ReadyState = READYSTATE_COMPLETE) then
WebBrowser1.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER);
end;
PDFPrinter.RestoreDefaultPrinter;
InterfaceDisconnect(PDFPrinter,_IPXCPrinterEvents,FConnectionToken);
PDFPrinter := nil;
FEventSink := nil;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
// InterfaceDisconnect(PDFPrinter,_IPXCPrinterEvents,FConnectionToken);
// PDFPrinter := nil;
// FEventSink := nil;
end;
If you now start the Demo with my code and click “Go” sometimes (may be around 10 to 20 times) then the Application freezes and the progress window of the pdfsaver4 stays with this message:
I have choose the “Embedd Fonts” option and I think this problem occurs earlier.
If you do that with your original code everything is ok. It seems that the com object isn’t destroyed correctly.
Because the printing code in my application is inside a DLL which is loaded dynamically I have to instantiate and destroy the printer-objects inside the DLL and so this problem occurs here.
Thanks für your help.
Michael