gofpdi icon indicating copy to clipboard operation
gofpdi copied to clipboard

Unable to import PDF exported from browsers (Chromium/Firefox/Blink/Gecko)

Open vqvw opened this issue 3 years ago • 1 comments

Hello, this package is great, but I'm unable to import PDFs that have been exported from browsers.

It works completely fine when importing PDFs exported from jung-kurt/gofpdf, but if I try to import a PDF exported from Chromium or Firefox I get the following error:

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

goroutine 1 [running]:
github.com/phpdave11/gofpdi.(*PdfReader).resolveObject(0xc00010c4d0, 0x0)
        /mnt/Portable/Programming/Go/pkg/mod/github.com/phpdave11/[email protected]/reader.go:599 +0x19b
github.com/phpdave11/gofpdi.(*PdfReader).readPages(0xc00010c4d0)
        /mnt/Portable/Programming/Go/pkg/mod/github.com/phpdave11/[email protected]/reader.go:1228 +0x52
github.com/phpdave11/gofpdi.(*PdfReader).read(0xc00010c4d0)
        /mnt/Portable/Programming/Go/pkg/mod/github.com/phpdave11/[email protected]/reader.go:1622 +0x5e
github.com/phpdave11/gofpdi.(*PdfReader).init(0xc00010c4d0)
        /mnt/Portable/Programming/Go/pkg/mod/github.com/phpdave11/[email protected]/reader.go:75 +0x105
github.com/phpdave11/gofpdi.NewPdfReader({0x55f1ff, 0xc000016390})
        /mnt/Portable/Programming/Go/pkg/mod/github.com/phpdave11/[email protected]/reader.go:61 +0xdc
github.com/phpdave11/gofpdi.(*Importer).SetSourceFile(0xc00002b580, {0x55f1ff, 0x0})
        /mnt/Portable/Programming/Go/pkg/mod/github.com/phpdave11/[email protected]/importer.go:67 +0x6a
github.com/phpdave11/gofpdf/contrib/gofpdi.(*Importer).ImportPage(0xc00000e5b0, {0x597b58, 0xc000142000}, {0x55f1ff, 0x55d01b}, 0x2, {0x55e516, 0x9})
        /mnt/Portable/Programming/Go/pkg/mod/github.com/phpdave11/[email protected]/contrib/gofpdi/gofpdi.go:43 +0x4b
github.com/phpdave11/gofpdf/contrib/gofpdi.ImportPage(...)
        /mnt/Portable/Programming/Go/pkg/mod/github.com/phpdave11/[email protected]/contrib/gofpdi/gofpdi.go:115
main.main()
        /mnt/Portable/Programming/Go/src/github.com/barjoio/pdf-header-footer/main.go:14 +0x116
exit status 2

gofpdi version: v1.4.2

vqvw avatar Jan 20 '22 14:01 vqvw

Got the same error when importing a pdf generated with iText. Would be better if the function returned an error instead of panicking

anibaldeboni avatar Jun 28 '23 20:06 anibaldeboni