Export to PDF from Print Preview Reruns Report

Export to PDF from Print Preview Reruns Report

Another one from my stash of Blog post I need to make, resurfaced today, so it seemed like a good time to Get-R-Done.

If you take a look at the online help for the iPreview function you will find this little tidbit at the bottom of the page

So what exactly does that mean? Well when you are viewing a report in the print previewer and you use the export tab to export to PDF (or any of the other functions) it doesn’t directly export the current preview to PDF. What it does is completely rerun the report.

Let me say that again! THE REPORT IS RERAN!!!!

So if you have code updating a table, deleting files, or you are initializing a query outside the report, your life is going to suck and it’s going to take you forever to figure out what the heck is going on. Or at least it did me.

So you might need to adjust your code, such as initializing the query from within the report. Deleting files or updating tables from outside the report etc.

I actually discovered this way back in 2012, yes Uncle Pete has quite the stock pile of tidbits to share. Today I found yet another side effect of this particular issue.

We have a project that prints Lab Reports for blood samples. These are normally printed as individual reports, and have Page 1 or 1, Page 1 of 2, etc. on them.

However in one area of the application, several samples can be processed together and there is a printing option that prints both the processing report and all of the Lab Reports for the samples involved. Easy enough with one of the great WL function for report, called Sequencing Reports, using the functions iSequencingAdd and iSequencingPrint

However a side effect of that, which in most instances you would want, is that Page numbers are continued over between the reports. So if Report 1 has 2 pages, Report 2 has 1 page, and Report 3 has 1 page, the Page numbers printed on the report will be 1 of 4, 2 of 4, etc.

In this case we don’t want that behavior we still want those lab reports to be Page 1 of 1 for each report.

We “solved” this with yet another function iResetNbPages which as the name implies resets the page numbers. Below is our code, after each iSequencingAdd we make a call to iResetNbPages so the page numbering for each report included is individual.

We tested this all was great it worked just like we wanted. However those pesky users still kept complaining about the page numbers not resetting, and after a few back and forths they even sent us a PDF proving the issue.

Have you figured out the issue yet? You got it when the report came up in the print preview, the page numbers for individual for each report and all looked fine, but as soon as they used the export to PDF function from the preview, the reports get reran, but since at that point its doing it internally some how our iResetNbPages was not getting executed, and the resulting PDF had the paging numbering as if they were all part of a single report.

So now that we finally knew what the problem was, all we need to do was come up with a solution. PCSOFT actually gave us a hint, on the help page for iResetNbPages, you will find this nugget of wisdom.

So I added a Start of document block to our Lab Report, I made it “Always invisible” that way it doesn’t actually use any space on the report, but it still technically prints, so the Reinitialize the number of pages after the block print, still takes effect.

Now even when the export the PDF our page numbers are for each individual report and all is well with the world.

One thought on “Export to PDF from Print Preview Reruns Report

  1. A+ on this one, thanks

    El jue, 26 nov 2020 a las 11:25, wxBlog – All things wx – Covering pcSoft products (WINDEV, WEBDEV, WINDEV Mobile) () escribió:

    > Pete Halsted posted: ” Another one from my stash of Blog post I need to > make, resurfaced today, so it seemed like a good time to Get-R-Done. If you > take a look at the online help for the iPreview function you will find this > little tidbit at the bottom of the page ” >

    Like

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s