【问题标题】:iText 7 - put values of variables into the text of pdfiText 7 - 将变量的值放入 pdf 的文本中
【发布时间】:2023-04-09 20:40:01
【问题描述】:

有没有办法在 PDF 文件中添加标签或变量之类的东西?

我正在通过 Java 上的 iText 7 从模板 pdf 制作欢迎页面,但我一直坚持个性化它。

我希望 loginpassword 是可变值

    PdfWriter writer = new PdfWriter("source.pdf");
    PdfDocument pdf = new PdfDocument(writer);
    Document document = new Document(pdf);

    document.add(new Paragraph("Thank you for registration, Dear " + login + "!"));
    document.add(new Paragraph("That is your password: " + pass)
    document.close();

,其中loginpass 分配给“_____”

这里是我如何更改登录名和密码的实际值并创建新 PDF 文件的伪代码

    PdfDocument pdfDoc = new PdfDocument(new PdfReader("source.pdf"), new PdfWriter(dest));
    Document document = new Document(pdfDoc);

    login = inputtedLogin; // pseudocode
    pass = inputtedPass;  // pseudocode
    Print text;          // pseudocode

    document.close();

【问题讨论】:

    标签: java itext itext7


    【解决方案1】:

    这取决于您的确切用例。 但是你可能想看看 pdf 表格。 http://developers.itextpdf.com/examples/form-examples/clone-filling-out-forms

    基本上,这可以让您;

    • 创建一次文档(使用表单)
    • 加载文档
    • 填写表单字段
    • 展平文档(以消除交互性)

    【讨论】:

    • 谢谢,我想这就是我需要的。但我有一个关于 form.getField("Name") 的问题。名称是字段的名称还是什么?如果是,如何声明这些字段?
    • 原来是错的或者是我的问题。因为我只需要更改某些单词的值
    • 以上链接现在无效,使用这个-> kb.itextpdf.com/home/it7kb/examples/filling-out-forms
    猜你喜欢
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 2012-09-20
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多