java - 如何使用 itextpdf 在 PDF 中放置电子邮件 anchor

标签 java pdf itext anchor

我必须将一些数据放入 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/

相关文章:

c# - iTextSharp HTMLWorker ParseHTML Tablestyle 和 PDFStamper

java - 具有通用参数的接口(interface) - 无法编译

java - Mapper 的意外输出

javascript - PDF Javascript - 设置字段值

pdf - StackOverflowError 应用 Alfresco 规则将 Word Doc 转换为 PDF 时

c# - 我可以使用 iTextSharp 填写加密的 PDF 吗?

java - 如何在不由 Micronaut 管理的类中使用 beans?

java - Eclipse 语法突出显示 Java Struts Hibernate Web 应用程序

django - 在 EmailMultiAlternatives 中, Attach 和 Attach_alternative 两者同时不起作用

java - 如何使用 itext 增加 PDF 表格某些部分而不是整个表格的单元格空间?