unidoc / unipdf

Golang PDF library for creating and processing PDF files (pure go)
https://unidoc.io
Other
2.59k stars 253 forks source link

[BUG] Form Filling does not accomodate page rotation #352

Closed AMcPherran closed 4 years ago

AMcPherran commented 4 years ago

Description

When UniPDF is used to fill the AcroForm on a PDF which has been rotated, the values filled into the fields do not conform to the page's rotation.

Expected Behavior

The values filled into a rotated PDF form are rotated to match the orientation of the fields.

Actual Behavior

Steps to reproduce the behavior:

  1. Get the pdf_form_fill_json example code ready to run (link )
  2. Download the attached 90Degrees.pdf and 90Degrees.json files, and place them in your unipdf-examples/forms directory.
  3. Run go run pdf_form_fill_json.go 90Degrees.pdf 90Degrees.json Filled90Degrees.pdf to fill the form.
  4. Open Filled90Degrees.pdf, and observe that the text filled into the field does not match the rotation of the page, and may even appear cut off.
  5. Observe similar results with the attached 270Degrees.pdf + 270Degrees.json

Attachments

90Degrees.pdf 90Degrees.json:

[
    {
        "name": "Text4",
        "value": "Testing123!"
    }
]

270Degrees.pdf 270Degrees.json:

[
    {
        "name": "Text5",
        "value": "Testing123!"
    }
]
github-actions[bot] commented 4 years ago

Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, other issues go into our backlog where they are assessed and fitted into the roadmap when suitable. If you need to get this done, consider buying a license which also enables you to use it in your commercial products. More information can be found on https://unidoc.io/

gunnsth commented 4 years ago

@AMcPherran We are looking at this. Can you provide similar PDFs with other fields, such as combo boxes, checkboxes too? A mix of fields including text fields, would be great so we can test those properly.

tmlbl commented 4 years ago

Here is a document I created with more field types that is rotated

FieldTypesRotated.pdf

AMcPherran commented 4 years ago

@gunnsth I tested out the PDF provided by @tmlbl with v3.8.0 and found that Text fields are all properly rotated now, but the other field types (like the checkbox) are not. I haven't tested the image fields, dropdowns, or radio buttons yet FilledFieldTypesRotated.pdf

gunnsth commented 4 years ago

@AMcPherran Did you use the standard example with field appearance set as:

fieldAppearance := annotator.FieldAppearance{OnlyIfMissing: true, RegenerateTextFields: true}

Typically correct appearances are already available in forms for static fields such as checkboxes, dropdowns, radio buttons.

I generated the appearance with those default options (as per the example) and in that case the appearance was correct. out.pdf

Note that text is most important to regenerate since it is most dynamic. The form creators such as Adobe create desired appearances for all display options for fields with finite number of states (e.g. checkbox: appearance, unchecked appearance).

In your output PDF it seems like the tick mark looks a bit different. Did you customize it? That would force appearance regeneration (in which the problem is with the appearance generation). By setting OnlyIfMissing: false we can identify more issues with appearance generation as it forces appearance generation of each field, instead of relying on the appearance generation already provided by the form creator for each state.