java - Can't get itext Rectangle to work correctly with annotations -
i'm new itext , can't annotation icons appear correctly.
i'm trying create rectangle annotation icon. example below:
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)); but, icon fails appear or small dot in pdf.
i cant find im doing wrong.
you create rectangle this
rectangle rect = new rectangle(164, 190, 164, 110); according javadocs:
public rectangle(float llx, float lly, float urx, float ury)constructs
rectangle-object.parameters:
llx - lower left x
lly - lower left y
urx - upper right x
ury - upper right y
as lower left x equals upper right x, rectangle has 0 width. thus, not surprising that
the icon fails appear or small dot in pdf.
thus, use coordinates describing large enough rectangle, e.g.
rectangle rect = new rectangle(164, 190, 328, 300); another issue: add annotation setting chunk annotation , (presumably) adding chunk pdf:
chunk_text.setannotation(pdfannotation.createtext(writer, rect, "warning", comments, false, "comment")); this technique anyways replaces rectangle bounding box of rendered chunk text. thus, might not want. instead use addannotation method of pdfwriter.
furthermore add popup annotation not related other annotation. not make sense, according specification:
a pop-up annotation (pdf 1.3) displays text in pop-up window entry , editing. shall not appear alone associated markup annotation, parent annotation, , shall used editing parent’s text.
using itext build popup-parent relation parent annotation parent , popup annotation popup using
parent.setpopup(popup);
Comments
Post a Comment