Reputation: 138
I am using .Net > iText 7.
In pdf generation code -> after all operations are done and I say doc.Close(). This throws a pdfException with a message "pdf.inderect.object.belong.to.other.pdf.document.Copy.object.to.current.pdf.document"
After checking out the iText code, I found out that the exception in around indirectReference The internal property name is : PdfException.PdfInderectObjectBelongToOtherPdfDocument
The stacktrace is :
at iText.Kernel.Pdf.PdfOutputStream.Write(PdfIndirectReference indirectReference)
at iText.Kernel.Pdf.PdfOutputStream.Write(PdfDictionary pdfDictionary)
at iText.Kernel.Pdf.PdfOutputStream.Write(PdfObject pdfObject)
at iText.Kernel.Pdf.PdfOutputStream.Write(PdfDictionary pdfDictionary)
at iText.Kernel.Pdf.PdfOutputStream.Write(PdfObject pdfObject)
at iText.Kernel.Pdf.PdfOutputStream.Write(PdfDictionary pdfDictionary)
at iText.Kernel.Pdf.PdfOutputStream.Write(PdfObject pdfObject)
at iText.Kernel.Pdf.PdfWriter.WriteToBody(PdfObject pdfObj)
at iText.Kernel.Pdf.PdfWriter.FlushObject(PdfObject pdfObject, Boolean canBeInObjStm)
at iText.Kernel.Pdf.PdfDocument.FlushObject(PdfObject pdfObject, Boolean canBeInObjStm)
at iText.Kernel.Pdf.PdfObject.Flush(Boolean canBeInObjStm)
at iText.Kernel.Pdf.PdfPage.Flush(Boolean flushXObjects)
at iText.Kernel.Pdf.PdfPage.Flush()
at iText.Kernel.Pdf.PdfDocument.Close()
at iText.Layout.Document.Close()
Please note: After starting the application, pdf gets generated for the very first time, but in all later tries I get this exception.
Any help on this would be really appreciated.
Thanks in advance.!!
Upvotes: 0
Views: 2839
Reputation: 76
In Java i had the same issue because i used static constants for font. try not to use static values for PdfFont. I removed this
private static PdfFont font;
And i replaced it with local values
PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
Upvotes: 2