PDA

View Full Version : Can I replace standard FP errors with custom ones?


esmith
January 10th, 2014, 08:45 AM
This is the error I get when processing a job that does not generate output:
A body page does not have master page assigned.
A blank page is emitted since no record is composed properly.

dlpdfdocwritepdf, progress "Doc->PageCount is zero", error: Bad parameter.

PDF Library Document Write Error: Bad parameter.

pdf_om_WriteDoc, dtl_pdf_WritePdf returned "-2"

Job aborted with error.

Long story short, each data file can produce one or both of two template pages. Sometimes data produces only one type, but the determination is made on-the-fly by several factors and can not be determined prior to processing at this time. The client now wants each style to be output as a separate file. Since data can not be pre-sorted, I am processing each data file twice with a manual value change that tells FP if a record should be ignored based on aforementioned computations.

A colleague came up with a solution that preprocesses records in OnJobStart and posts a custom message to msg log in OnJobEnd, but it precedes the default error message which is all that is seen when composition is done.

I would like to replace the default error with a custom one so that it is the last entry in the log and can be seen in the composition dialog window. I know about JavaScript's catch(e) method, but I do not know how/what I need to catch in order to replace it in the log. Any help?

Dan Korn
January 10th, 2014, 09:50 AM
Long story short, each data file can produce one or both of two template pages.
Okay, but it seems that in addition to either one or two pages, producing zero pages is also a possible outcome. That's why you get that error, no?
Sometimes data produces only one type, but the determination is made on-the-fly by several factors and can not be determined prior to processing at this time. The client now wants each style to be output as a separate file. Since data can not be pre-sorted, I am processing each data file twice with a manual value change that tells FP if a record should be ignored based on aforementioned computations.
I'm not sure I understand what you mean. How are you processing the data file twice? Are you running FusionPro multiple times?

You can always tell FusionPro to do a preprocessing pass, by setting FusionPro.Composition.forcePreprocessing = true in OnJobStart, then you can use values such as FusionPro.Composition.totalPages and FusionPro.Composition.totalRecordCount in your rules.
A colleague came up with a solution that preprocesses records in OnJobStart and posts a custom message to msg log in OnJobEnd, but it precedes the default error message which is all that is seen when composition is done.
Okay. But I'm still not sure if you're forcing preprocessing, like I talked about above, or doing something else.

You can also write to an XML log file by calling FusionPro.Composition.CreateXMLLogFile in OnJobStart, and then you can call FusionPro.Composition.LogXMLMetadata to add entries.
I would like to replace the default error with a custom one so that it is the last entry in the log and can be seen in the composition dialog window.
What do you mean by "the default error?" Do you mean the stuff about "Doc->PageCount is zero" and all that? FusionPro is always going to report that if it doesn't write any output. Well, maybe we could change something so that it doesn't do that, but basically the PDF output format is confused, as it's all dressed up to output pages but has nowhere to go.

If you want to suppress that error, you need to output something, a single page. Maybe you could just always emit a cover page for the job, on the first record composed, or add some logic to detect the lack of output pages in your preprocessing pass and then emit a single blank page.
I know about JavaScript's catch(e) method, but I do not know how/what I need to catch in order to replace it in the log. Any help?
You can indeed use try/catch blocks to handle error messages thrown by JavaScript functions, such as Field. But the error you're talking about isn't a JavaScript error, it's a composition error, so you can't "catch" it like that.

At any rate, if you're in an automated environment, using FusionPro VDP Producer API (FP Server), then what you want to go by isn't so much the messages in the log file, but the return code from FusionPro.exe (which in this case is probably the dreaded error 1096 (http://forums.pti.com/showthread.php?p=11301)). And if you're not using FusionPro in an automated environment like this, then, frankly, you should consider it, but if you're just relying on a human to examine the file, then I would do the preprocessing, figure out if there are no pages to be output, and then either force a page to be output like I mentioned above, or put out a message in all caps with some asterisks around it so that the person looking at the log file sees it, even though there may be some other messages after that.

I will say that, in FusionPro 9.2, we are adding a new JavaScript function, FusionPro.Composition.Abort, which you can call at any time to abort the composition with a custom return code and/or a custom message written to both the main log (.msg) file and the XML log file. (It can also be used to abort a single record, like the settings on the Advanced tab of the Composition Settings allow now, but with the ability to precisely define the conditions under which to abort, instead of guessing what Minor, Medium, and Severe mean, and which error messages are hard-coded into which categories.) However, even with these new 9.2 features, you would still need to determine on your own that you have no pages to output so that you could call the FusionPro.Composition.Abort function, and if you know that, then you can handle the error yourself now, as I suggested.