Java 在文档中插入图像

Java 在文档中插入图像,java,pdf,itext,Java,Pdf,Itext,我正在尝试使用iText的onCloseDocument事件在文档的页脚中插入图像。我有以下代码: public void onCloseDocument(PdfWriter writer, Document document) { PdfContentByte pdfByte = writer.getDirectContent(); try { // logo is a non-null global variable Image

我正在尝试使用iText的onCloseDocument事件在文档的页脚中插入图像。我有以下代码:

public void onCloseDocument(PdfWriter writer, Document document) {
      PdfContentByte pdfByte = writer.getDirectContent();
      try {
          // logo is a non-null global variable
          Image theImage = new Jpeg(logo);
          pdfByte.addImage(theImage, 400.0f, 0.0f, 0.0f, 400.0f, 0.0f, 0.0f);
      } catch (Exception e) { e.printStackTrace(); }
}
代码不会抛出异常,但也无法插入图像。此相同代码用于在待处理文档中插入相同的徽标。这两种方法之间的唯一区别是pdfByte.addImage中的坐标。然而,我在onCloseDocument中尝试了很多不同的协调,但它们都没有出现在我的文档中的任何地方

是否有任何故障排除技术可用于检测PDF页面外显示的内容?如果没有,有人能看到我的onCloseDocument方法的问题吗


编辑:作为后续操作,onDocumentClose似乎将其内容放在页面document.length()+1上(根据其大小)。但是,我不知道如何将页码改回document.length(),并将我的徽标放在最后一页。

对我(问题的作者)有效的解决方案是将onCloseDocument改为onParagraphEnd(因为我的文档只有一个段落)