Itext7 generate pdf with Exception “Pdf indirect object belongs to other PDF document. Copy object to current pdf document.”

后端 未结 3 1196
南旧
南旧 2020-12-18 21:28

i want to generate a pdf with itext 7,but some wrong happens to us:

com.itextpdf.kernel.PdfException: Pdf indirect object belongs to other PDF document. Copy         


        
3条回答
  •  無奈伤痛
    2020-12-18 22:17

    This is how i solved the issue.

    1. Created an DocumentUtil class
    2. Add a static method

      public class DocumentUtils {    
          public static PdfFont setFont() throws Exception {
                  return PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
          }
      }
      
    3. Use the font like:

      PDfFont font = DocumentUtil.setFont();
      

提交回复
热议问题