Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creator: PDF form builder #30

Closed
gunnsth opened this issue Dec 6, 2018 · 1 comment
Closed

Creator: PDF form builder #30

gunnsth opened this issue Dec 6, 2018 · 1 comment
Labels

Comments

@gunnsth
Copy link
Contributor

gunnsth commented Dec 6, 2018

A simple way to build forms should be present in the creator package. Together with tables etc it should provide a an easy way to make PDF forms using the creator. Advanced support for forms exists in package model although the use is pretty low level and will serve as the basis for this.

Should support:

  • Input text form (text fields 12.7.4.3 PDF32000_2008).
  • Checkboxes (12.7.4.2.3)
  • Radio group selection (12.7.4.2.4)
  • Buttons (12.7.4.2.4)
  • Dropdown menu - Choice fields (12.7.4.4)

Basic API ideas:

c := creator.New()
form := c.NewForm()  // Serves as the AcroForm for the document represented by `c`.

tf := form.NewTextField("field_name1")  // occupies available width with some default height
tf.SetDefaultText("Enter your name")
// can force certain width with tf.SetWidth(100)
// tf.SetRelHeight(1.2)  1.2 X fontheight
c.Draw(tf)

cf := form.NextCheckboxField("checkbox_male")
cf.SetText("Male")
cf.SetChecked(false)
c.Draw(tf)   // Draws at current position

cf = form.NextCheckboxField("checkbox_female")
cf.SetText("Female")
cf.SetChecked(false)
c.Draw(tf)   // Draws at current position

The drawing does not involve adding anything to the page contentstream, but rather creating Fields in the AcroForms (that refer the page) and the actual content goes into widget annotations. The annotations should also be added to the page dictionaries Annots array.

For arranging fields it would in many cases make sense to place inside a Table to arrange nicely over the page.

@gunnsth gunnsth transferred this issue from unidoc/unidoc May 24, 2019
@anovik
Copy link

anovik commented Nov 20, 2024

It has been implemented in annotator package (and available from creator). NewTextField, NewCheckboxField, etc.

It is possible to add fields to AcroForm as well.

@anovik anovik closed this as completed Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants