创建 PDF 表单
把看起来像印刷品的文档,变成可在屏幕上填写的表单。
这款工具完全在你的浏览器中运行。文件从不上传,你可以在浏览器的网络标签中亲自验证这一点。 亲自验证:打开浏览器的网络标签观察。你会看到一个查询你是否还有剩余任务的小请求,只包含工具名称和一段哈希,绝不会包含文件。
这款工具的作用
This adds real form fields to a document that has none. You draw each field where it belongs on the rendered page, and the file that comes out carries named AcroForm fields that any reader can fill - not text boxes drawn as artwork. Positions are chosen by dragging rather than typed as numbers, because a field belongs to a spot on the page and no set of coordinates would be quicker or more accurate than putting a box where the line already is.
Use it when a form keeps getting printed, filled by hand and scanned back: a leave request, a delivery note, a membership application, a supplier questionnaire. It is also what you want after designing a form in Word or InDesign, where the layout is right but nothing is fillable.
工作原理
- Drop the PDF onto this page. It is rendered so you work on the page you can see.
- Leave the proposal option on for a first pass, then accept, move or delete what it suggests.
- Drag out any further fields and set what each one needs: its kind, a name, a tooltip, whether it is required, and the choices for a dropdown or a radio group.
- Check the names. Two fields sharing a name are one field in PDF, which is right for a radio group and a bug anywhere else.
- Press Create form and download the fillable document.
Six kinds of field are offered and five of them are created here: a text box, a tick box, a radio group, a dropdown and a scrolling option list. A signature field is refused rather than faked, because pdf-lib can read one but not create one, and a hand-built signature field with no byte range shows in readers as a broken signature rather than an empty one. Sign PDF adds a real one.
Every field created here gets a hairline border and a pale wash, and its appearance stream is generated before anyone clicks it. This is not decoration. A field with no border and no background renders as an invisible rectangle, the person opening your form sees a blank page, clicks nothing, and concludes the form does not work.
A text box taller than 32 points is made multiline automatically, so a comments box wraps instead of scrolling one line sideways. The label you give a field is written as its tooltip, which is the only label a field carries in the file itself - readers show it on hover and screen readers read it out, so it is worth filling in even when the printed text beside the box says the same thing.
Up to 500 fields in one pass, and the names have to be unique except within a radio group, where sharing a name is what makes the buttons mutually exclusive. Automatic proposal looks for the marks that mean write here - long horizontal rules, empty boxes, rows of dots - and it proposes rather than applies, because a wrong field is more annoying to remove than a missing one is to add.
The page is rendered, the fields are placed and the document is written entirely inside your browser. A blank internal form and a signed one are treated the same way, since neither is transmitted at any point.
这款工具做不到的事
- Calculated fields, validation rules and any other JavaScript behaviour are not created. Fields here hold what someone types; they do not add a column of figures or check a format.
常见问题
- 我能添加哪些种类的字段?
- 文本框、复选框、单选按钮组、下拉列表和滚动选项列表。高于 32 磅的文本框会变成多行,让较长的答案换行。同一组里的单选按钮共享一个名称,这正是选中一个就清除其余的原理;其他每个字段都需要各自的名称。
- 自动字段建议有多准?
- 明显的情况它找得很好:用来写名字的横线、可勾选的空方框、一排圆点。它无法知道某条线是签名线而非姓名字段,所以只是建议,由你确认。在密集划线的表格上它会过度建议,这是有意为之的失败方向——删除一个建议只需一次点击,而发现漏掉一个字段,得等填表人来抱怨。
- 这份表单能在每个 PDF 阅读器里用吗?
- 它使用 AcroForm 字段,这是 Acrobat、预览、Chrome、Firefox、Edge 和常见移动阅读器都支持的格式。因为每个字段的外观都写进了文件,所以点击前它在所有阅读器里看起来都一样。有差别的是精细程度:有些阅读器把可填字段高亮成蓝色,有些不会,少数较老的移动阅读器会显示字段却不让你打字。
- 我能添加签名字段吗?
- 这里不能,这是有意的。背后什么都没有的签名字段,会被阅读器显示成损坏的签名,而不是等待签署的空框。请用 PDF 签名,它会按格式要求的顺序把字段和签名一起创建。如果你只需要一处能画标记的地方,一个高文本框或一条普通横线就够了。
- 为了构建表单,我的文档会被上传吗?
- 不会。页面由 PDF.js 在你的浏览器里渲染,字段由 pdf-lib 在 Web Worker 里写入,成品在本地生成。这也包括人们通常用来做表单的内部模板,而那往往是最不想放到别人服务器上的东西。