Skip to content

Font issue during form filling  #636

@JaDuyve

Description

@JaDuyve

Font issue during form filling

  • Based on latest commit: vs 0.4.1 commit a7fd28e
  • Version OS: macOS 13.4 (22F66)
  • Pdf writer:
    • creator: Adobe InDesign
    • producer: macOS Version 13.2.1 (Build 22D68) Quartz PDFContext, AppendMode 1.1

First thanks for fixing the previews issue I made 😄 (Issue #572), It took a while for me to test it out, but I think I found another issue.

I have sent the PDF and the used JSON export representing the available fields via email.
I have validated the PDF with pdfcpu and the PDF seems valid (validate.log).
Furthermore, I'm able to open the PDF in macOS preview.

At first, I got an error because ArialMT font was not available inside the PDF and on my Mac.
After installing font ArialMT via pdfcpu I get the following error and the program panic's.

Short example code that produces the error

package main

import (
	"github.com/pdfcpu/pdfcpu/pkg/api"
	"log"
)

func main() {

	err := api.FillFormFile("infile.pdf", "form.json", "outfile.pdf", nil)
	if err != nil {
		log.Fatal(err)
	}
}

Error message


panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1325b7f]

goroutine 1 [running]:
github.com/pdfcpu/pdfcpu/pkg/pdfcpu/primitives.ensureCorrectFontIndRef(0xc0001e0e40, 0xc000c87468, {0xc0000ab814, 0x7}, 0xc0000ec538?)
        /Users/jaduyve/go/pkg/mod/github.com/pdfcpu/[email protected]/pkg/pdfcpu/primitives/font.go:305 +0x7f
github.com/pdfcpu/pdfcpu/pkg/pdfcpu/primitives.extractFormFontDetails(0xc0001e0e40, {0xc000a62c2f, 0x7}, 0x1?)
        /Users/jaduyve/go/pkg/mod/github.com/pdfcpu/[email protected]/pkg/pdfcpu/primitives/font.go:377 +0x42f
github.com/pdfcpu/pdfcpu/pkg/pdfcpu/primitives.(*TextField).calcFontFromDA(0xc000c76c60, 0x11?, {0xc0000fa6e0, 0x5, 0x0?}, 0xc000a23920?)
        /Users/jaduyve/go/pkg/mod/github.com/pdfcpu/[email protected]/pkg/pdfcpu/primitives/textField.go:268 +0x465
github.com/pdfcpu/pdfcpu/pkg/pdfcpu/primitives.NewTextField(0xc000c87748?, 0x11256bf?, {0xc000c71690, 0x9}, 0x0, 0xc000c63640?)
        /Users/jaduyve/go/pkg/mod/github.com/pdfcpu/[email protected]/pkg/pdfcpu/primitives/textField.go:915 +0x196
github.com/pdfcpu/pdfcpu/pkg/pdfcpu/primitives.refreshTextFieldAP(0xc0001e0e40, 0x151cd58?, {0xc000c71690?, 0xc000080900?}, 0x15?, 0x0?, 0xc000c877b0?)
        /Users/jaduyve/go/pkg/mod/github.com/pdfcpu/[email protected]/pkg/pdfcpu/primitives/textField.go:966 +0x2c
github.com/pdfcpu/pdfcpu/pkg/pdfcpu/primitives.EnsureTextFieldAP(0x1469660?, 0xc000a238f0?, {0xc000c71690, 0x9}, 0xf0?, 0xc000d01200?)
        /Users/jaduyve/go/pkg/mod/github.com/pdfcpu/[email protected]/pkg/pdfcpu/primitives/textField.go:991 +0x93
github.com/pdfcpu/pdfcpu/pkg/pdfcpu/form.fillTextField(0xc000080900?, 0xc000c718c0?, {0x149d32e?, 0xc000c878a0?}, {0xc000c71878?, 0x8?}, {0x0, 0x0}, 0x1, 0x1, ...)
        /Users/jaduyve/go/pkg/mod/github.com/pdfcpu/[email protected]/pkg/pdfcpu/form/fill.go:923 +0x247
github.com/pdfcpu/pdfcpu/pkg/pdfcpu/form.fillTx(0xc0001e0e40, 0x15?, {0x149d32e, 0x2}, {0xc000c71878, 0x8}, 0x60?, 0xc0000f9e00?, 0xc000c87968?, 0xc000c6c520, ...)
        /Users/jaduyve/go/pkg/mod/github.com/pdfcpu/[email protected]/pkg/pdfcpu/form/fill.go:961 +0x205
github.com/pdfcpu/pdfcpu/pkg/pdfcpu/form.fillWidgetAnnots(0xc0001e0e40, {0xc0000b4800, 0x15, 0x20}, 0x1015010?, {0xc000b61488?, 0xc000b2d6b0?}, 0x0?, 0x0?, 0xc000c6c520, ...)
        /Users/jaduyve/go/pkg/mod/github.com/pdfcpu/[email protected]/pkg/pdfcpu/form/fill.go:1024 +0x347
github.com/pdfcpu/pdfcpu/pkg/pdfcpu/form.FillForm(0xc0001e0e40, 0x0?, 0x0, 0x13ec200?)
        /Users/jaduyve/go/pkg/mod/github.com/pdfcpu/[email protected]/pkg/pdfcpu/form/fill.go:1064 +0x211
github.com/pdfcpu/pdfcpu/pkg/api.FillForm({0x15235d8, 0xc000012520}, {0x1521ca0, 0xc000012518}, {0x1521cc0, 0xc000012528}, 0x100c61e?)
        /Users/jaduyve/go/pkg/mod/github.com/pdfcpu/[email protected]/pkg/api/form.go:521 +0x426
github.com/pdfcpu/pdfcpu/pkg/api.FillFormFile({0x1478f76, 0xa}, {0x1478564?, 0x60?}, {0x147993d, 0xb}, 0x0?)
        /Users/jaduyve/go/pkg/mod/github.com/pdfcpu/[email protected]/pkg/api/form.go:594 +0x3a5
main.main()
        /Users/jaduyve/Development/side-projects/go/pdftil/main.go:10 +0x45

Export of font list command

$ pdfcpu font list

Corefonts:
  Courier
  Courier-Bold
  Courier-BoldOblique
  Courier-Oblique
  Helvetica
  Helvetica-Bold
  Helvetica-BoldOblique
  Helvetica-Oblique
  Symbol
  Times-Bold
  Times-BoldItalic
  Times-Italic
  Times-Roman
  ZapfDingbats

Userfonts(/Users/jaduyve/Library/Application Support/pdfcpu/fonts):
  ArialMT (399 glyphs)
  Roboto-Regular (1294 glyphs)
  Unifont-JPMedium (57393 glyphs)
  UnifontMedium (57090 glyphs)
  UnifontUpperMedium (12584 glyphs)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions