java - com.itextpdf.text.exceptions.IllegalPdfSyntaxException : Unbalanced begin/end text operators

标签 java itext

在 iText 中使用 PdfContentByte 解决此问题。当我尝试创建新页面时,我使用以下代码-

           canvas = writer.getDirectContent();
           canvas.saveState();


           canvas.stroke();
           canvas.restoreState();
         ...
            canvas.endText();
            itextDocument.newPage();

            setUpperFontAndSize(canvas);
            canvas.beginText();

该问题发生在调用 endText() 时。有什么办法解决吗?

最佳答案

OP 说

The issue is occurring at the time of calling endText()

根据该方法的源代码,该异常表明没有匹配的 beginText()之前打电话。

A text object begins with the BT operator and ends with the ET operator, as shown in the Example, and described in Table 107.

EXAMPLE

BT
…Zero or more text operators or other allowed operators…
ET

... text objects cannot be statically nested ...

关于java - com.itextpdf.text.exceptions.IllegalPdfSyntaxException : Unbalanced begin/end text operators,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27835553/

相关文章:

java - JsonIgnore 和 XmlElement 注释冲突

java - Java中的误解

c# - itextsharp 中的阿拉伯语编码

java - 如何为 keystore 创建属性文件?

java - iText 和数字签名

c# - 分割 10k 页 PDF 时出现内存泄漏(iTextSharp PDF API)

c# - 用点填充 PDFP 表格单元

java - 处理海量数据表时应该如何使用Hibernate Mapping

java - 从 JSON 读取时出现异常

java - 对于 Galaxy S10,display.getSize(size) 返回错误的屏幕尺寸