ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  MultiPagePdf throws from outPDF if there are no pages
Posted by Rand on Jan-27-2022 22:44
Windows 10, latest update
chartdir70.dll
Visual Studio 2019 Pro
using MFC through wxWidgets

I have some charts in viewports on notebook pages.  When report generate is clicked logic creates a MultiPagePDF and passes it successively to each notebook page(single thread).  The notebook page adds an image of each of its charts to the MultiPagePDF using .addPage().  All worked as intended.

We changed the way one of the pages looks, it no longer contains a chart. If just that page participates in report generation then ChartDirector throws an exception from the line where outPDF() is called. I am unable to trap that exception though the call is inside a try/catch.

I would expect outPDF() to return false in this case, or generate a valid empty report. It generates a report of size 0 which I cannot open. PDF-Xchange Viewer shows the error message "[PDF Structure 40]: Invalid File Format"
I have attached one of those reports.

I will add some workaround logic as an interim solution.

If you need to alter your code, it would be nice if MultiPagePDF has a method to get the number of pages, or at least a HasContent() or something similar.

  Re: MultiPagePdf throws from outPDF if there are no pages
Posted by Rand on Jan-27-2022 22:47
File attachment did not work, probably 0 length is not attachable.

  Re: MultiPagePdf throws from outPDF if there are no pages
Posted by Peter Kwan on Jan-28-2022 14:51
Hi Rand,

I have just done a test. I confirm that if the MultiPagePdf does not contain any page (the addPage API is never called), when it will crash when trying to output the PDF.

We will fix this problem in the next release. In the mean time, you may need to keep track of if any page is added to the PDF, and do not output the PDF with zero page. Another method is to ensure the PDF has at least one page. In our sample code, there is a cover page for the PDF report, so there is at least one page in the PDF.

Regards
Peter Kwan

  Re: MultiPagePdf throws from outPDF if there are no pages
Posted by Rand on Jan-29-2022 01:34
I added a flag to indicate if a page was added.  That solves the problem for me.
Thank you.