在 R 中填写 PDF 表单?

ADF*_*ADF 7 forms pdf r fdf

我正在寻找一种在 R 中自动填写 PDF 表单的方法。我找不到为此而编写的包。有选择吗?

我能想到的替代解决方案:

  1. 使用 R 将包含文本的 PDF 叠加到空白 PDF 模板上。
  2. 使用 R 生成可由其他软件或不同语言的代码读取的 FDF 文件。

所有这些事情在 Python 中似乎都是可行的。然而,我的组织强烈倾向于 R,并且过去一直依赖软件开发人员编写 C# 来填写表格。我希望使用 R 来跳过这一步。

谢谢!

Oga*_*anM 4

Staplr包现在支持此get_fields功能set_fields。请注意,要使其工作,必须安装pdftk 服务器并位于您的路径中

get_fields从 pdf 中返回您可以修改的字段及其类型的列表

set_fields允许您根据您的修改填写表格。请参阅下面的代码示例

pdfFile = system.file('testForm.pdf',package = 'staplr')

fields = get_fields(pdfFile)
# You'll get a list of fields that the pdf contains 
# along with some additional information about the fields.

# You make modifications in any of the fields by
fields$TextField1$value = 'this is text'

# and apply the changes you have made in a new file
set_fields(pdfFile, 'newFile.pdf', fields)
Run Code Online (Sandbox Code Playgroud)

注意:目前 staplr 的 github 版本有尚未纳入 CRAN 的修复,这些修复会影响 staplr 用非英语字母书写的能力。为了获得最佳体验,您可能需要通过执行以下操作来安装它

devtools::install_github('pridiltal/staplr')
Run Code Online (Sandbox Code Playgroud)

  • 您只需下载它并将其放置在您的 PATH 中的某个位置,或者将其添加到您的 PATH 中。您可以从高级系统设置 -> 环境变量 -> 系统变量 -> 路径更改路径。这是针对 Windows 8/10 的。 (3认同)