0

I see this error a lot in an application with a lot of traffic when dealing with a PDF merge request.

java.lang.RuntimeException: The page 3 was requested but the document has only 2 pages. at com.lowagie.text.pdf.PdfWriter.close(PdfWriter.java:1169) at com.lowagie.text.pdf.PdfCopy.close(PdfCopy.java:485) at ...

The error is in the PdfCopy class, addPage method:

public void addPage(PdfImportedPage iPage) throws IOException, BadPdfFormatException

pageRef = getCurrentPage(); // increase pageReferences.size()

But later on an IOException occurs (ClientAbortException), but the last line ++currentPageNumber; didn't get a chance to execute.

How do I prevent this from happening? Can I add a finally block in the last line?

cokeman19
  • 2,405
  • 1
  • 25
  • 40
user63684
  • 101
  • 1
  • Do you know what causes the `IOException`? – Mehrdad Nurolahzade Feb 14 '16 at 02:07
  • 1
    You're using a version of iText that is no longer supported (it's 7 years old!!!). Please upgrade and post a new question if the problem persists. – Bruno Lowagie Feb 14 '16 at 07:16
  • Furthermore you mention a `ClientAbortException` - as far as I know iText does not throw (or regularly cause) such an exception. Thus, you seem to have a third library interfering in your iText using code. – mkl Feb 14 '16 at 12:33
  • It is org.apache.catalina.connector.ClientAbortException. which extends java.io.IOExceptio. – user63684 Feb 15 '16 at 16:10

0 Answers0