Itext不平衡的开始/结束文本操作符

时间:2016-11-18 22:21:30

标签: java itext

虽然我正在开始和关闭,但我得到的是异常。不确定是否因为异常块我没有关闭。

ERROR xyz.A  - execute() error closing OutputStreamWriter.    [source:]
    java.io.IOException: com.lowagie.text.exceptions.IllegalPdfSyntaxException: Unbalanced begin/end text operators.
            at PDFOutputWriter.close(PDFOutputWriter.java:91)
            at xyz.A.execute_aroundBody0(A.java:319)
          org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149)

以下代码抛出此异常。

  public void addPageNumber(PdfWriter writer, Document document) {
        PdfContentByte cb = writer.getDirectContent();
        cb.saveState();
        String text = writer.getCurrentPageNumber() - pageOffset + " - " + timeStamp;
        float textBase = document.bottom() - 20;
        cb.beginText();
        try {
            cb.setFontAndSize( BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252,
                false), 12);

        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        cb.setTextMatrix(document.left(), textBase);
        cb.showText(text);
        cb.endText();
        cb.restoreState();
        previousPage = writer.getCurrentPageNumber();
    }



<groupId>com.itextpdf</groupId>
        <artifactId>com.lowagie</artifactId>
<itext.version>2.1.7</itext.version>


 <groupId>com.itextpdf</groupId>
        <artifactId>itextpdf</artifactId>
 <version>5.5.8</version>

0 个答案:

没有答案