How to create a PDF file without display of a file save dialog?

Top  Previous  Next

It is easy to add PDF export to the ReportBuilder demo application

 

a) we need a check box:

 

clip0100

 

b) modify the uses clause

 

uses ....  wppdfRBDev, wppdfr1;

 

c) modify the procedure PrintReport()

 

var

...

  pdf : TppwPDFDevice;

 

 

...

 

      if cbxPrintToPDF.checked then

      begin

        with TOpenDialog.Create(nildo

        try

          Filter := 'PDF Files (*.PDF)|*.PDF';

          FileName := 'c:\rb.pdf';

          if Execute then

          begin

            pdf := TppwPDFDevice.Create(Self);

            pdf.Filename := FileName;

            pdf.PDFPrinter.FontMode := wpUseTrueTypeFonts;

            pdf.PDFPrinter.AutoLaunch := true;

            pdf.Publisher := lForm.Report.Publisher;

            lForm.Report.PrintToDevices;

            pdf.Free;

          end;

        finally

          Free;

        end;

      end else

        if cbxPrintToArchive.Checked then

 ...

 

This is the basic code needed for the task:

 

uses wppdfRBDev, WPPDFR1, WPPDFR2;

 

var pdf : TppwPDFDevice;

begin

   pdf := TppwPDFDevice.Create(Self);

   pdf.Filename := 'c:\rb.pdf';

   pdf.PDFPrinter.FontMode := wpUseTrueTypeFonts;

   pdf.Publisher := some_Report.Publisher;

   some_Report.PrintToDevices;

   pdf.Free;

  end

 

Note: some_Report is an instance of a RB report object.

 

Please note that through pdf.PDFPrinter You have access to all properties of the TWPCustomPDFExport object.

 

 

It is also possible to create a report as a stream, here "OutputStream":

 

var pdf : TppwPDFDevice;

begin

      WPPDFPrinter1.AutoLaunch:=False;

      WPPDFPrinter1.InMemoryMode:=True;

      WPPDFPrinter1.Stream:= OutputStream;

      pdf := TppwPDFDevice.Create(Self);

      pdf.PDFPrinter.FontMode := wpUseTrueTypeFonts;

      pdf.Publisher := ppReport1.Publisher; //some_Report.Publisher;

      WPPDFPrinter1.BeginDoc;

      ppGlobalPDFPrinter:=WPPDFPrinter1;

      ppReport1.PrintToDevices;

      WPPDFPrinter1.EndDoc;

      pdf.Free;

  end