我必须将一些数据放入 PDF 中的表格中,其中包含电子邮件信息,需要在生成的 PDF 中放置 anchor ,以便单击该电子邮件时,会打开带有预填充主题的 Outlook 窗口并可以通过添加消息直接发送电子邮件。
引用网上的例子,我已经将内容放入一个段落并添加了一个 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;
}
<小时/>
提前致谢!!!
最佳答案
像这样的东西一定有效......
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);
关于java - 如何使用 itextpdf 在 PDF 中放置电子邮件 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26885163/