百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

pdf-forms

> 编程语言
开源

使用 pdftk 填写 PDF 表单 (http://www.accesspdf.com/pdftk/)。

303 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

使用 pdftk 填写 PDF 表单 (http://www.accesspdf.com/pdftk/)。

pdf-forms

http://github.com/jkraemer/pdf-forms/

Description

Fill out PDF forms with pdftk.

Installation

You'll need a working pdftk binary. Either get a binary package from http://www.pdflabs.com/tools/pdftk-server/ and install it, or run apt-get install pdftk if you're on Debian or similar.

After that, add pdf-forms to your Gemfile or manually install the gem. Nothing unusual here.

Using the Java port of PDFTK

The PDFTK package was dropped from most (all?) current versions of major Linux distributions. As contributed in this issue, you can use the Java version of PDFTK with this gem, as well. Just create a small shell script:

bash
#!/bin/sh
MYSELF=`which "$0" 2>/dev/null`
[ $? -gt 0 -a -f "$0" ] && MYSELF="./$0"
java=java
if test -n "$JAVA_HOME"; then
    java="$JAVA_HOME/bin/java"
fi
exec "$java" $java_args -jar $MYSELF "$@"
exit 1

Next, concatenate the wrapper script and the Jar file, and you end up with an executable that can be used with pdf-forms:

cat stub.sh pdftk-all.jar > pdftk.run && chmod +x pdftk.run

Usage

FDF/XFdf creation

ruby
require 'pdf_forms'
fdf = PdfForms::Fdf.new :key => 'value', :other_key => 'other value'
# use to_pdf_data if you just want the fdf data, without writing it to a file
puts fdf.to_pdf_data
# write fdf file
fdf.save_to 'path/to/file.fdf'

To generate XFDF instead of FDF instantiate PdfForms::XFdf instead of PdfForms::Fdf

Query form fields and fill out PDF forms with pdftk

…

Any options shown above can also be set when initializing the PdfForms instance. In this case, options given to fill_form will override the global options.

Field names with HTML entities

In case your form's field names contain HTML entities (like Stra&#223;e Hausnummer), make sure you unescape those before using them, i.e. CGI.unescapeHTML(name). Thanks to @phoet for figuring this out in #65.

Non-ASCII Characters (UTF8 etc) are not displayed in the filled out PDF

First, try to use the replacement_font option and specify the font that's not being displayed. If it doesn't work, check if the field value has been stored properly in the output PDF using pdftk output.pdf dump_data_fields_utf8.

If it has been stored but is not rendered, your input PDF lacks the proper font for your kind of characters. Re-create it and embed any necessary fonts. If the value has not been stored, there is a problem with filling out the form, either on your side, of with this gem.

Also see UTF-8 chars are not displayed in the filled PDF

Prior Art

The FDF generation part is a straight port of Steffen Schwigon's PDF::FDF::Simple perl module. Didn't port the FDF parsing, though ;-)

License

Created by Jens Kraemer and licensed under the MIT License.

Issues· 6 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言