Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

SendEachPageAsNewPDFFile

edited October 2005 in General
This is good example but can we create the PDF pages as we are printing the
hard copy on the same run?

Comments

  • edited October 2005
    Hi,

    Adding a PrinterDevice to the device list will allow you to print as well as
    export once calling PrintToDevice...

    uses
    ppPrnDev;

    procedure TForm1.Button1Click(Sender: TObject);
    var
    lPrinterDevice: TppPrinterDevice;
    begin

    lPrinterDevice := TppPrinterDevice.Create(nil);
    try
    lPrinterDevice.Publisher := ppReport1.Publisher;

    FDevice := TppDevice.Create(self);
    FDevice.Publisher := ppReport1.Publisher;
    FDevice.OnPageReceive := ehDevicePageReceive;

    ppReport1.AllowPrintToFile := True;
    ppReport1.ShowPrintDialog := False;
    ppReport1.PrintToDevices;
    FDevice.Free;
    finally
    lPrinterDevice.Free;
    end;

    end;

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited October 2005
    Thats is great.
    Can you take it a step further and create a pdf file per Group as we may
    have more than one page per group?
    Thanks again
  • edited October 2005
    Hi,

    Unfortunately the device knows nothing about each individual group in a
    report. The best approach for a task like this one would be to create a
    dynamic query connected to a single report object, then each time the query
    changes re-generating and re-printing the report.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited October 2005
    Actually after messing with it for a while I was able to get it work as long
    as each group starts on a new page.
    my test code
    procedure TForm1.ppGroup1AfterGroupBreak(Sender: TObject);
    begin
    fFileDevice.EndJob;
    ffiledevice.Free;
    fFileDevice := TppPDFDevice.Create(self);
    FFileDevice.FileName :=
    zMysqlQuery1.fieldbyname('Account').asstring+'.pdf';
    fFileDevice.StartJob;
    end;
    procedure TForm1.BitBtn1Click(Sender: TObject);
    var
    lPrinterDevice: TppPrinterDevice;
    begin

    lPrinterDevice := TppPrinterDevice.Create(nil);
    fFileDevice := TppPDFDevice.Create(self);

    FFileDevice.FileName :=
    zMysqlQuery1.fieldbyname('Account').asstring+'.pdf';
    try
    lPrinterDevice.Publisher := ppReport1.Publisher;

    FDevice := TppDevice.Create(self);
    FDevice.Publisher := ppReport1.Publisher;
    FDevice.OnPageReceive := ehDevicePageReceive;

    ppReport1.AllowPrintToFile := True;
    ppReport1.ShowPrintDialog := False;

    ppReport1.PrintToDevices;
    FFileDevice.endjob;
    FDevice.Free;
    finally
    lPrinterDevice.Free;
    end;
    end;
    procedure TForm1.ehDevicePageReceive(Sender, aPage: TObject);
    var
    lPage: TppPage;
    begin

    lPage := TppPage(aPage);
    // lFileDevice := TppPDFDevice.Create(self);
    try
    if not ffiledevice.Busy then
    FFileDevice.StartJob;
    fFileDevice.ReceivePage(lPage);
    finally
    end;

    end;
  • edited October 2005
    Excellent... good work. :)

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.