我必须在PDF中的表格中放置一些数据,其中包含电子邮件信息,需要在生成的PDF中放置一个锚点,这样点击该电子邮件时,将打开带有预填充主题的Outlook窗口和电子邮件可以通过添加消息直接发送。
参考在线示例,我已经将内容添加到Paragraph中并添加了一个Anchor,但不幸的是,它没有成功,请找到代码的剪辑。
table.addCell(getLCell(1, labelMap.get("email"), 1, 8));
Paragraph para=new Paragraph();
para.add(new Phrase(email));
Anchor anchor = new Anchor("mailto:"+email+"?subject=Reference Number:1234");
anchor.setReference("mailto:"+email+"?subject=Reference Number:1234");
para.add(anchor);
table.addCell(this.getVCell(3, para, 1, 4));
private PdfPCell getLCell(int cspan, String name, int... d) {
PdfPCell cell = new PdfPCell(new Phrase(name, normal_bold));
cell.setRowspan(1);
cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
cell.setColspan(cspan);
for (int i : d) {
cell.disableBorderSide(i);
}
return cell;
}
private PdfPCell getVCell(int cspan, Paragraph name, int... d) {
PdfPCell cell = new PdfPCell(new Phrase(name.getContent(), normal));
cell.setRowspan(1);
cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
cell.setColspan(cspan);
for (int i : d) {
cell.disableBorderSide(i);
}
return cell;
}
提前致谢!!!
答案 0 :(得分:2)
这样的事情必须有效......
Anchor anchor = new Anchor("sendMail");
anchor.setReference("mailto:"+email+"?subject=ReferenceNumber:1234");
para.add(anchor);
编辑全部取决于您需要的最终结果。但这对我有用:
private static Font bigFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
Paragraph para= new Paragraph("YOUR CONTENT", bigfont);
Anchor anchor = new Anchor("sendMail");
anchor.setReference("mailto:"+email+"?subject=ReferenceNumber:1234");
para.add(anchor);