最近在做基于三方存证机构的pdf电子合同签署,需要生成的PDF时对某些文本添加超链接,废话不多说,上代码
public static void addTextContentWithHyperlink(PdfPTable table) {
Paragraph country = new Paragraph();
Anchor dest = new Anchor("我是百度链接", textFont);
dest.setName("百度链接");
dest.setReference("https://www.baidu.com");
country.add(dest);
PdfPCell lastCell = new PdfPCell(country);
lastCell.setHorizontalAlignment(Element.ALIGN_LEFT);
lastCell.setBorder(Rectangle.NO_BORDER);
//lastCell.setColspan(tableSize);
table.addCell(lastCell);
}
这样在表格添加的文本就带有超链接了



