draw() or drawToWeb(request, response, outputstream)

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Generator for Java (v5)  /  draw() or drawToWeb(request, response, outputstream)

DynamicPDF Generator for Java (v5) Forum

I am working on upgrading our code from V 3.0 to V 5.0.

I am experiencing a problem with Document.draw() or Document.drawToWeb method.

Receiving below error message:

com.cete.dynamicpdf.GeneratorException: Invalid page number.
        at com.cete.dynamicpdf.io.n.getPageObject(Unknown Source)
        at com.cete.dynamicpdf.merger.forms.j.drawDictionary(Unknown Source)
        at com.cete.dynamicpdf.forms.FormField.draw(Unknown Source)
        at com.cete.dynamicpdf.io.DocumentResourceList.a(Unknown Source)
        at com.cete.dynamicpdf.io.n.draw(Unknown Source)
        at com.cete.dynamicpdf.Document.draw(Unknown Source)
        at com.cete.dynamicpdf.Document.draw(Unknown Source)

Currently, I am clueless on why this is happening. If possible can you be help in understanding what might cause this error?

Thank you in advance.
Posted by a ceTe Software moderator
Hello,

Can you please send over the input PDF document and the code which you are using to our support team at: support@cete.com so that they can look into it further?

Thanks,
ceTe Software Support Team.
Thanks for the response.

But I am not sure if I can send the PDF I am adding as it is company specific document. But here the code for drawToWeb():

                if (viewDocument != null && viewDocument.getPages().getSize() > 0) {
                        viewDocument.setInitialPageZoom(PageZoom.RETAIN);
                        viewDocument.setInitialPageMode(PageMode.AUTO);
                        viewDocument.drawToWeb(request, response, response
                            .getOutputStream());
                        return false;
                } else {
                        return true;
                }

Here is code for draw():

if (documentToAdd != null && documentToAdd.getPages().getSize() > 0) {

                        byte[] docToByte = documentToAdd.draw();

                        P3PdfDocument pdfDocument = new P3PdfDocument(docToByte);
                        this.append(pdfDocument);
                } else {
                        return null;
                }

Thanks for your help!!

Posted by a ceTe Software moderator
Hello,

Are you getting this error with all the PDF documents you are using or only a few documents? In any case we need to be able to recreate the error on our side in order for us to figure out what the issue is. We need the PDF document that is causing the error. If you have a document that is causing this error and that is not confidential please do send it to support@cete.com so we can look into it further. 

Thanks,
ceTe Software Support Team.
It is happening on all document in certain scenario.

It is very tricky to explain the scenario. But I will try:

We attach PDF documents (which we call it as forms) to the output of a insurance policy. And when they endorse (make any changes to the original policy) to the same policy we attach the same form but this time only attach the changes in the forms.

What's happening is the PDF are attaching fine first time (when the policy was issued first time). But at endorsement time where we have to show the changes, the same form is failing. It is just not one or two forms. Almost all forms at endorsement time are failing.

But if I set MergeOption(false) everything seems to be working, but I will not get the data on the PDF. E.g:

 PdfDocument pdfDocument = new PdfDocument(\\physicalpath\\+"abc.pdf");
        MergeDocument document = new MergeDocument(pdfDocument,
                new MergeOptions(false));

Hope it gives you some idea on the scenario.

Please let me know your inputs.

Thank you.
Posted by a ceTe Software moderator
Hello,

Removing the document pages using the Iterator will most likely throw the “Invalid page number” error, because the documents that has form fields has Xref table which stores the relationships between the objects and using the iterator will only remove the page but not the entries of the removed objects in other pages.  In order to avoid this error while removing pages from the document use the overloaded append method to copy only the necessary pages to a different document.

PdfDocument pdfDocument = new PdfDocument("F:/temporary/CustomerPDF/test.pdf");
MergeOptions options=new MergeOptions();
options.setFormFields(true);
MergeDocument tempDoc = new MergeDocument();
tempDoc.append(pdfDocument, 2, (pdfDocument.getPages().getSize()-1),options);
if (tempDoc != null)
{
  String name = "F:/temporary/CustomerPDF/final.pdf";
  tempDoc.draw(name);
}


Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 9:17 PM.