Java iText矩形如何使用setBorderColorxxx设置颜色|如何向矩形添加文本
两个问题,Java iText矩形如何使用setBorderColorxxx设置颜色|如何向矩形添加文本,java,pdf,itext,Java,Pdf,Itext,两个问题, 如何隐藏或设置矩形框边框的白色 如何向矩形中添加文本 你的第一个问题很简单。这是一个复制品 创建表示链接注释的PDFanRotation对象时,默认情况下会定义边框。您可以在注释级别使用setboorder()方法删除此边框,如示例中所示: 你的第二个问题以前也已经回答过了。例如,见: 我在示例中结合了这两种方法: 但是,还有另一种方法可以同时添加文本和链接注释。这在我对重复问题的回答中得到了解释: 在这个回答中,我参考了一个例子,在这个例子中,我们如上所述使用Colu
你的第一个问题很简单。这是一个复制品 创建表示链接注释的
PDFanRotation
对象时,默认情况下会定义边框。您可以在注释级别使用setboorder()
方法删除此边框,如示例中所示:
你的第二个问题以前也已经回答过了。例如,见:
ColumnText
添加内容,但我们引入了一个可点击的块
:
Chunk chunk = new Chunk("The Best iText Questions on StackOverflow", bold);
chunk.setAnchor("http://developers.itextpdf.com/frequently-asked-developer-questions");
将
块
对象包装在段落
中,使用ColumnText
添加段落
,就有了无边框链接。将矩形添加到实际内容时,会呈现为矩形
定义的API参考边框。注释(如链接注释)不是实际内容。Rectangle
类用于注释以定义位置,而不是定义边框。批注的边框是在批注级别定义的
link.setBorder(new PdfBorderArray(0, 0, 0));
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();
}
Chunk chunk = new Chunk("The Best iText Questions on StackOverflow", bold);
chunk.setAnchor("http://developers.itextpdf.com/frequently-asked-developer-questions");