delphipdfservicepdf-generationquickreports

Generate PDF using QuickReport from a Windows Service in Delphi


I'm writing a windows service using Delphi XE3. The service is going to read from a database, generate a pdf using quickreport 5.05.1. I plan to generate the pdf using TQRPDFDocumentFilter.

Everything works fine in a normal VCL application, but when I implement it in a windows service the service hangs (without any exceptions) when I do a QuickRep.Prepare.

I have read that it is possible to use QuickReport in a windows service, but I do not know how. Any suggestions?

Where is the code:

procedure foo
var
 pdfFilter: TQRPDFDocumentFilter;
begin
  with TForm2.Create(Self) do
  begin
    ClientDataSet1.Open;
    QuickRep1.Prepare;
    pdfFilter := TQRPDFDocumentFilter.Create(GetApplicationFolder() + 'test.pdf');
    try
      QuickRep1.QRPrinter.ExportToFilter(pdfFilter);
    finally
      pdfFilter.Free;
      ClientDataSet1.Close;
    end;
  end;
end;

Edit: I have also tried turning off "show progress" on the QuickReport as suggested in another thread. Writing some code to catch an exception reveals that it indeed throws one. The message is "There is no default printer currently selected". So this leads me to believe that the local system user that the service is running under does not have any printers installed and that this is the problem.


Solution

  • I have resolved a similar problem (printing to a shared network printer from a Java server running as a Windows service) with these steps:

    IIRC with Delphi applications, the printer name is not case sensitive (with Java it is).