1

I'm using java and iText 7 to generate PDF.

I created a PDF template and has some data models inside this template in order to make it dynamic.

When first time I used this template to generate PDF, it worked fine. But second time I tried to modify the data value inside the template then generate again it raised an error.

 2016-09-24 18:35:17,589|http-bio-8080-exec-20|INFO|CustomerControllercom.itextpdf.kernel.PdfException: pdf.inderect.object.belong.to.other.pdf.document.Copy.object.to.current.pdf.document com.itextpdf.kernel.PdfException: pdf.inderect.object.belong.to.other.pdf.document.Copy.object.to.current.pdf.document at com.itextpdf.kernel.pdf.PdfOutputStream.write(PdfOutputStream.java:184) at com.itextpdf.kernel.pdf.PdfOutputStream.write(PdfOutputStream.java:174) at com.itextpdf.kernel.pdf.PdfOutputStream.write(PdfOutputStream.java:104) at com.itextpdf.kernel.pdf.PdfOutputStream.write(PdfOutputStream.java:176) at com.itextpdf.kernel.pdf.PdfOutputStream.write(PdfOutputStream.java:104) at com.itextpdf.kernel.pdf.PdfOutputStream.write(PdfOutputStream.java:176) at com.itextpdf.kernel.pdf.PdfOutputStream.write(PdfOutputStream.java:104) at com.itextpdf.kernel.pdf.PdfWriter.writeToBody(PdfWriter.java:315) at com.itextpdf.kernel.pdf.PdfWriter.flushObject(PdfWriter.java:232) at com.itextpdf.kernel.pdf.PdfDocument.flushObject(PdfDocument.java:1257) at com.itextpdf.kernel.pdf.PdfObject.flush(PdfObject.java:147) at com.itextpdf.kernel.pdf.PdfObject.flush(PdfObject.java:124) at com.itextpdf.kernel.pdf.PdfObjectWrapper.flush(PdfObjectWrapper.java:97) at com.itextpdf.kernel.pdf.PdfPage.flush(PdfPage.java:410) at com.itextpdf.kernel.pdf.PdfPage.flush(PdfPage.java:367) at com.itextpdf.kernel.pdf.PdfDocument.close(PdfDocument.java:720) at com.itextpdf.layout.Document.close(Document.java:115) 
3
  • The iText 7 Version I'm using : 7.0.0 Commented Sep 24, 2016 at 11:00
  • Most likely your code using itext is incorrect. Commented Sep 24, 2016 at 11:06
  • 1
    Show us your code. Commented Sep 24, 2016 at 12:50

1 Answer 1

1

I isolated the code caused the error, commented out all usage of PdfFont, it worked fine.

I checked a Chinese blog, seems like this error is cause by didn't release some document objects(like PdfFont in my case) when you want to print this PDF again. http://blog.csdn.net/fu250/article/details/52604900

I would much appreciate if someone can give a more detailed answer.

public final PdfFont regular; public final PdfFont bold;

public InvoiceRecieptServiceImpl() throws IOException { this.regular = PdfFontFactory.createFont(FontConstants.HELVETICA); this.bold = PdfFontFactory.createFont(FontConstants.HELVETICA_BOLD); }

Sign up to request clarification or add additional context in comments.

1 Comment

You have not yet shown your code. I don't understand Chinese, and the Google translation is not helpful. Do you probably use the identical PdfFont instances for different target documents. I would advice against that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.