Your first question is easy. It's a duplicate of iText - How to stamp image on existing PDF and create an anchor
When you create a PdfAnnotation
object that represents a link annotation, a border is defined by default. You can remove this border using the setBorder()
method at the level of the annotation as is done in the AddImageLink example:
link.setBorder(new PdfBorderArray(0, 0, 0));
Your second question has also been answered before. See for instance:
I have combined both in the AddLinkAnnotation5 example:
public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
// Here we define the location:
Rectangle linkLocation = new Rectangle(320, 695, 560, 741);
// here we add the actual content at this location:
ColumnText ct = new ColumnText(stamper.getOverContent(1));
ct.setSimpleColumn(linkLocation);
ct.addElement(new Paragraph("This is a link. Click it and you'll be forwarded to another page in this document."));
ct.go();
// now we create the link that will jump to a specific destination:
PdfDestination destination = new PdfDestination(PdfDestination.FIT);
PdfAnnotation link = PdfAnnotation.createLink(stamper.getWriter(),
linkLocation, PdfAnnotation.HIGHLIGHT_INVERT,
3, destination);
// If you don't want a border, here's where you remove it:
link.setBorder(new PdfBorderArray(0, 0, 0));
// We add the link (that is the clickable area, not the text!)
stamper.addAnnotation(link, 1);
stamper.close();
reader.close();
}
However, there's also another way to add the text and the link annotation at the same time. That's explained in my answer to the duplicate question: How to add overlay text with link annotations to existing pdf?
In this answer, I refer to the AddLinkAnnotation2 example, where we add the content using ColumnText
as described above, but we introduce a clickable Chunk
:
Chunk chunk = new Chunk("The Best iText Questions on StackOverflow", bold);
chunk.setAnchor("http://developers.itextpdf.com/frequently-asked-developer-questions");
Wrap the chunk
object inside a Paragraph
, add the Paragraph
using ColumnText
and you have your borderless link.