PdfLinkannotaion предоставляет такую функциональность, но всегда создает гиперссылку. Если я напишу простую pdfTextAnnotation или PdfLineannotaion. Они оба создают маленький желтый значок комментария рядом с изображением.
Любая помощь, как я могу покончить с этой проблемой. Я тоже пробовал pdfpopUpAnnotaion.
protected void manipulatePdf(String dest) throws Exception {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
Document doc = new Document(pdfDoc);
Table table = new Table(1);
// Part of the content is a link:
Paragraph phrase = new Paragraph();
phrase.add("The founders of iText are still struggling ");
Cell cell = new Cell();
cell.add(phrase);
cell.setNextRenderer(new LinkInCellRenderer(cell, 1));
table.addCell(cell);
Paragraph phrase2 = new Paragraph();
phrase2.add("This is a retry mechanism and i am still struggling");
Cell cell_new = new Cell();
cell_new.add(phrase2);
cell_new.setNextRenderer(new LinkInCellRenderer(cell_new, 2));
table.addCell(cell_new);
doc.add(table);
doc.close();
}
class LinkInCellRenderer extends CellRenderer {
private int count;
public LinkInCellRenderer(Cell modelElement, int i) {
super(modelElement);
this.count = i;
}
@Override
public void draw(DrawContext drawContext) {
super.draw(drawContext);
Rectangle rectangle = getOccupiedAreaBBox();
float llx = rectangle.getX() + 1;
float lly = rectangle.getY() + 1;
float urx = rectangle.getX() + getOccupiedAreaBBox().getWidth() - 1;
float ury = rectangle.getY() + getOccupiedAreaBBox().getHeight() - 1;
PdfPopupAnnotation pdfPopupAnnotation = new PdfPopupAnnotation(getOccupiedAreaBBox());
System.out.println(llx);
System.out.println(lly);
System.out.println(urx);
System.out.println(ury);
//pdfPopupAnnotation.setHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT);
//pdfPopupAnnotation.setAction(PdfAction.createURI(url));
// pdfPopupAnnotation.setTitle(new PdfString(this.title)).setContents("this is not happening");
//PdfLinkAnnotation a = new PdfLinkAnnotation(getOccupiedAreaBBox())
// .setAction(PdfAction.createURI("http://happening.com/bio"));
//).setContents("this is still not happening");
PdfAnnotation annotation = new PdfLineAnnotation(getOccupiedAreaBBox(), new float[]{llx, lly, urx, ury});
// annotation.setColor(WebColors.getRGBAColor("blue"));
// Setting title to the PdfLineAnnotation
annotation.setTitle(new PdfString("iText"));
// Setting contents of the PdfLineAnnotation
annotation.setContents("Hi welcome to my struggle number " + this.count);
//drawContext.getDocument().getLastPage().addAnnotation(a);
//drawContext.getDocument().getLastPage().addAnnotation(pdfPopupAnnotation);
drawContext.getDocument().getLastPage().addAnnotation(annotation);
}
}
}