Skip to content

cli: form filling fails for encrypted documents #758

@sbourlon

Description

@sbourlon
  • Your issue is based on the latest commit
$ git describe
v0.2.2-482-ge33b502
  • State your OS and OS version
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 23.10
Release:        23.10
Codename:       mantic
  • Issue

Hello Horst, pdfcpu can not export or fill forms with encrypted PDF files that have the form filling permissions. Usual graphical PDF editors like Acrobat Reader or Evince work fine. However, if I decrypt the PDF file with pdfcpu, then I can export and fill the PDF forms.

Is it the normal process to decrypt then fill the PDF (maybe that's what Evince does internally)?

  • Reproducing

Input: JSON form file (form.json):

{
  "forms": [
    {
      "radiobuttongroup": [
        {
          "name": "form1[0].Page1[0].ID_Sub[0].Left_sub[0].RadioButtonGroup_030[0]",
          "value": "0"
        }
      ]
    }
  ]
}

Script:

# PDF with the issue: Canadian Corporation Income Tax Return
# Source: https://www.canada.ca/en/revenue-agency/services/forms-publications/forms/t2.html
wget https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/t2/t2-fill-23e.pdf

# Exporting: error
go run cmd/pdfcpu/*.go form export t2-fill-23e.pdf export.json
# output:
# writing export.json...
# pdfcpu: operation restriced via pdfcpu's permission bits setting
# exit status 1

# Filling: error
go run cmd/pdfcpu/*.go form export t2-fill-23e.pdf export.json
# output:
# writing export.json...
# pdfcpu: operation restriced via pdfcpu's permission bits setting
# exit status 1

# Decrypting: ok
go run cmd/pdfcpu/*.go decrypt t2-fill-23e.pdf t2-fill-23e-decrypted.pdf
# output:
# writing t2-fill-23e-decrypted.pdf...
# optimizing...

# Exporting after decryption: ok
go run cmd/pdfcpu/*.go form export t2-fill-23e-decrypted.pdf export.json
# output
# writing export.json...
# optimizing...

# Filling after decryption: ok
go run cmd/pdfcpu/*.go form fill t2-fill-23e-decrypted.pdf form.json out.pdf
# writing out.pdf...
# optimizing...
# removing signature...
# filling...

PDF file info:

go run cmd/pdfcpu/*.go info t2-fill-23e.pdf
t2-fill-23e.pdf:
              Source: t2-fill-23e.pdf
         PDF version: 1.7
          Page count: 9
           Page size: 612.00 x 792.00 points
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
               Title: T2 Corporation Income Tax Return (2022 and later tax years)
              Author:
             Subject:
        PDF Producer: Designer 6.3
     Content creator: Designer 6.3
       Creation date: D:20230321110556-04'00'
   Modification date: D:20230322070852-04'00'
        Viewer Prefs: DisplayDocTitle = true
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
              Tagged: Yes
              Hybrid: No
          Linearized: No
  Using XRef streams: Yes
Using object streams: Yes
         Watermarked: No
          Thumbnails: No
                Form: Yes
     SignaturesExist: Yes
          AppendOnly: Yes
            Outlines: No
               Names: Yes
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
           Encrypted: Yes
         Permissions:
permission bits: 101100110100 (xB34)
Bit  3: true (print(rev2), print quality(rev>=3))
Bit  4: false (modify other than controlled by bits 6,9,11)
Bit  5: true (extract(rev2), extract other than controlled by bit 10(rev>=3))
Bit  6: true (add or modify annotations)
Bit  9: true (fill in form fields(rev>=3)
Bit 10: true (extract(rev>=3))
Bit 11: false (modify(rev>=3))
Bit 12: true (print high-level(rev>=3))

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions