[英]Can't get itext Rectangle to work correctly with annotations
我是itext的新手,但我的注釋圖標無法正確顯示。
我正在嘗試為注釋圖標創建一個矩形。 我的例子如下:
Rectangle rect = new Rectangle(164, 190, 164, 110);
chunk_text.setAnnotation(PdfAnnotation.createText(writer, rect, "Warning", comments, false, "Comment"));
PdfContentByte pdb = new PdfContentByte(writer);
chunk_free.setAnnotation(PdfAnnotation.createFreeText(writer, rect, comments, pdb));
chunk_popup.setAnnotation(PdfAnnotation.createPopup(writer, rect, comments, false));
但是,該圖標無法顯示,或者只是PDF中的一個小點。
我找不到我做錯了什么。
您可以這樣創建矩形
Rectangle rect = new Rectangle(164, 190, 164, 110);
根據JavaDocs :
public Rectangle(float llx, float lly, float urx, float ury)
構造一個
Rectangle
。參數:
llx-左下角x
lly-左下y
urx-右上方x
ury-右上y
由於左下角x等於右上角x ,矩形的寬度為零。 因此,毫不奇怪
圖標無法顯示,或者只是PDF中的一個小點。
因此,使用描述足夠大的矩形的坐標,例如
Rectangle rect = new Rectangle(164, 190, 328, 300);
另一個問題:通過將注釋設置為塊注釋並(大概)將塊添加到PDF中來添加注釋:
chunk_text.setAnnotation(PdfAnnotation.createText(writer, rect, "Warning", comments, false, "Comment"));
無論如何,這項技術最終還是通過渲染的塊文本的邊界框替換了矩形。 因此,它可能並不是您真正想要的。 而是使用PdfWriter
的addAnnotation
方法。
此外,您添加了一個與其他任何注釋都不相關的Popup注釋。 根據規范,這沒有意義:
彈出注釋(PDF 1.3)在彈出窗口中顯示文本,以供輸入和編輯。 它不應單獨出現,而是與標記注釋及其父注釋相關聯,並應用於編輯父文本。
使用iText為父注釋parent
和使用以下命令的彈出注釋popup
構建彈出窗口-父關系
parent.setPopup(popup);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.