How To…Send Each Page as a PDF

Question

“Is it possible to create a new PDF file for each page in the report?”

Solution

This can be done by manually taking control of the StartJob/EndJob routines of the TppDevice.  Start by creating a generic TppDevice object, assigning its OnPageReceive event and calling PrintToDevices.  Next implement the OnPageReceive event to create a PDF Device, start a new job, send the page, and end the job.  This will fire for each page of the report effectively creating a new PDF file for each page.

Download: SendEachPageAsNewPDFFile.zip

Sample Delphi code:

uses
  ppDevice,
  ppPDFDevice; 

procedure TForm1.Button1Click(Sender: TObject);
begin
 FDevice := TppDevice.Create(self);
 FDevice.Publisher := ppReport1.Publisher;
 FDevice.OnPageReceive := ehDevicePageReceive;
 ppReport1.AllowPrintToFile := true;
 ppReport1.PrintToDevices;
 FDevice.Free;

end;

procedure TForm1.ehDevicePageReceive(Sender, aPage: TObject);
var
  lPage: TppPage;
  lFileDevice: TppPDFDevice;
begin

  lPage := TppPage(aPage);

  lFileDevice := TppPDFDevice.Create(self);

  try
    lFileDevice.FileName := 'c:\'+IntToStr(lPage.AbsolutePageNo)+'.pdf';
    lFileDevice.StartJob;
    lFileDevice.ReceivePage(lPage);
    lFileDevice.EndJob;
    
  finally
    lFileDevice.Free;

  end;

end;