2010-06-10 94 views
0

我想在iText的onCloseDocument事件中使用我的文檔的頁腳插入圖像。我有以下代碼:插入圖像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(); } 
} 

該代碼不會引發異常,但它也無法插入圖像。在OpenDocument上使用相同的代碼來插入相同的徽標。這兩種方法唯一的區別是pdfByte.addImage中的座標。但是,我已經嘗試了onCloseDocument中的不同協調,並且它們都不出現在我的文檔中的任何位置。

是否有任何故障排除技術用於檢測在PDF頁面中顯示的內容?如果沒有,任何人都可以看到我的onCloseDocument方法的問題?

編輯:作爲後續,似乎onDocumentClose將其內容放在頁面document.length()+1(根據其API)。但是,我不知道如何將頁碼更改回document.length()並將我的徽標放在最後一頁上。

回答

0

爲我工作的解決方案(問題的作者)將onCloseDocument更改爲onParagraphEnd(因爲我的文檔只有一個段落)。