Last active
August 19, 2022 13:02
-
-
Save djberg96/77bc6b5da52042d1ce3957423e57aa52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'hexapdf' | |
# Use local copy of http://foersom.com/net/HowTo/data/OoPdfFormExample.pdf | |
file = 'pdf_form_example.pdf' | |
doc = HexaPDF::Document.open(file) | |
page1 = doc.pages.first | |
widgets = page1[:Annots]&.filter{ |a| a[:Subtype] == :Widget } | |
# See what the widgets look like. | |
p widgets.map(&:form_field) | |
p widgets.map(&:form_field).map(&:concrete_field_type) | |
# Write some data into the form | |
given_name_text_box = widgets.first.form_field | |
given_name_text_box.field_value = "Daniel" | |
# Now save it | |
doc.write("test.pdf", validate: false, incremental: false, update_fields: true, optimize: false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment