Home Devices
New Blog Post: Email: Multi-Service

PDF report generate "silently"?

I have followed the example of creating a PDF file using TppPDFDevice.Create(nil), which very nicely allows me to merge multiple PDF reports, and then finally setting "myPDFDevice.EndPrintJob:= True" upon the last report. The only issue is that in this case I do NOT want to display the PDF file on the screen to the user. It is better in this case to just let the user know the info has been recorded. Is there a way to create the PDF "silently" - in other words to create the PDF but not show it?

Scott S.


  • Almost worked to simply set ModalPreview to False. The help for that property says it "determines if the Print preview form is modal". In fact, when False, no preview form is displayed at all, which is exactly what I want.
    EXCEPT this leaves Adobe Reader in a funky state, unable to open the new or any other stored PDF files. The only remedy I have found so far is to use Windows Task Manager to remove all the Adobe reader tasks. Then Adobe reader works to view the new report as well as others. So I need a better way to not show the preview OR a programatic way to kill running Adobe tasks.

    Scott S.
  • Hi Scott,

    By default the PDF file is not opened after it is generated by ReportBuilder. Assuming you are using the RBWiki example on how to merge multiple reports into a single PDF, you will notice the following line of code: lPDFDevice.PDFSettings.OpenPDFFile := True;

    Setting this property to False (or commenting it out) will prevent the PDF from being opened after it is created.

    Best Regards,

    Nico Cizik
    Digital Metaphors
  • Thanks Nico,
    Setting OpenPDFFile to False helps indeed. No more hung up Acro Reader. But now I do not see a created PDF at all. I was indeed following the example to merge reports, and I reset Report1 gathering new data for monthly as of dates for a series of reports, as you can see in the code below. I tried various sequences between the PDF device and my repoert1 in the loop.

    (The most important part of my procedure is to send report generated data to my DB, and that works fine, but it would be nice to see the generated PDF file).

    Scott S.

    myPDFDevice:= TppPDFDevice.Create(nil);
    ppReport1.PDFSettings.OpenPDFFile:= False;
    myPDFDevice.PDFSettings:= ppReport1.PDFSettings;//assign the set properties
    myPDFDevice.PDFSettings.OpenPDFFile:= False;//FALSE for sure (same in Report1)
    //TRUE creates the PDF file but leaves Acro Reader in funky state (need to end process)
    myPDFDevice.FileName:= reportPath;
    myPDFDevice.EndPrintJob:= False;
    //2.while loop multi-reports send to single PDF
    onLastRpt:= False;
    while AsDate >= (EarlyDatePicker.Date-1) do begin
    if (Trunc(AsDate) - Trunc(EarlyDatePicker.Date)) < 30 then onLastRpt:= True;
    GetReportData; //using the AsDate
    msgNextStr:= 'Processing performance for '+DatetoStr(AsDate)+'.';
    if not onLastRpt then begin
    myPDFDevice.Publisher:= ppReport1.Publisher;
    ppReport1.Reset;//reset so can re-run Report1 with new AsOf!!!
    end else begin //on final report
    myPDFDevice.Publisher:= ppReport1.Publisher;
    myPDFDevice.EndPrintJob:= True;//finalize BUT user not SEE PDF??
    end; //not need Resets on final report
    myPDFDevice.StartPrintJob:= False;//only "start" with the very first report
    rptMonth:= rptMonth-1;
    if rptMonth=0 then begin
    rptYear:= rptYear-1;
    AsDate:= EncodeDate(rptYear,rptMonth,rptDay);
    PrHerdEnd:= AsDate;
    end;// while dates in selected range
    myPDFDevice.Free; //3. FINALLY
  • I said "it would be nice to see the PDF file". What I meant is that it would be nice to generate a PDF file that could later be accessed. I do not want or need the user to see the file when it is generated.
  • Hi Scott,

    Looking at your code, the generated PDF file is being saved to the "reportPath" location. This is where your user will be able to access the file if needed. ReportBuilder does not delete or stream the PDF file automatically so unless this is being done somewhere else in your code, the file should be present at this location on your disk.

    Best Regards,

    Nico Cizik
    Digital Metaphors
  • Thanks for the clue that revealed my coding error! You said:
    "ReportBuilder does not delete or stream the PDF file automatically so unless this is being done somewhere else in your code, the file should be present at this location on your disk."
    In an earlier attempt to avoid seeing the preview, I had put the code to delete the generated PDF file elsewhere. So now, yes, the user does not see the preview but the PDF is stored - perfect!
    Scott S.
Sign In or Register to comment.