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

Event that fires after PDF is created

Hi,

I'm using the Groups | Create new file option to create an individual PDF for each group and was looking for an event that fires after the PDF is created. I tried using the AfterGroupBreak event of the group but it does not appear that the PDF exists yet then that event is fired. I'm looking to do some logic after each PDF is created. Does such an event exist?
Thanks,
Scott

Comments

  • Hi Scott,

    You can try using the FileDevice.OnEndJob event to know when each file has been created.

    What exactly are you trying to do after each file is created? Perhaps more information about what you are trying to accomplish will help me understand the best course of action.

    Best Regards,

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

    What I'm trying to do is to add a record to the Attachments table in our application for each PDF that is created. A PDF is created for different "customer" records in the database. Before adding the record, I want to verify that the PDF exists. I was hoping to be able to add the record immediately after the PDF is created as I have all the required information at that point (i.e. Customer_GUID, AttachmentFileName, etc). If I cannot create the Attachment record on the fly then I will need to create a list and save all the required information I need to create the record for each customer and then add them in bulk after the report has completed creating all PDF.
    Thanks,
    Scott
  • Hi Scott,

    I created a simple test. Implement Report.OnFileDeviceCreate to assign Report.FileDevice.OnEndJob handler.


    procedure TForm1.ppReport1FileDeviceCreate(Sender: TObject); begin ppReport1.FileDevice.OnEndJob := ehFileDevice_EndJob; end; procedure TForm1.ehFileDevice_EndJob(Sender: TObject); begin ShowMessage(ppReport1.FileDevice.FileName); end;

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • Hi Nard,

    I tried the above and got some weird results. In my sample, three files get exported to PDF. Let's call them 1.pdf, 2.pdf, 3.pdf and they get exported in that order. However, the ShowMessage on the FileDevice.OnEndJob shows the following:

    2.pdf
    3.pdf
    3.pdf

    The 2.pdf ShowMessage displays after the 1.pdf file is created but before the 2.pdf files is created.

    Any assistance you can provide is greatly appreciated.

    Thanks,
    Scott
  • edited June 2018
    SpawnNewJob assign new FileName before call EndJob.

    You can try something like this:

    type
    TppFileDeviceHelper = class(TppFileDevice);

    procedure TForm1.ehFileDevice_EndJob(Sender: TObject);
    var
    Device: TppFileDeviceHelper;
    FileName: string;
    begin
    Device := TppFileDeviceHelper(ppReport1.FileDevice);

    if Device.RenameFileOnEndJob then
    FileName := Device.FirstFileName
    else
    FileName := Device.CurrentFileName;

    ShowMessage(FileName);
    end;

    For more options you can used Device.OnReceivePage. See TppFileDevice.ReceivePage for ideas.

    PS. Do not work for single page (Image) devices.
    PS. FFirstFileName do not set to empty string on StartJob (can be problems, if used the same device for for print more then one time)
  • Thanks, I will try your suggestion and let you know how it works.
    Thanks,
    Scott
Sign In or Register to comment.