gofpdi
gofpdi copied to clipboard
Error while inserting a random PDF to another PDF
I am getting a nil
pointer error on resolveObjects
method while I am inserting an existing pdf to a new pdf
package main
import "github.com/signintech/gopdf"
func main() {
gPdf := gopdf.GoPdf{}
gPdf.Start(gopdf.Config{PageSize: *gopdf.PageSizeA4}) //595.28, 841.89 = A4
pdf := gPdf.ImportPage("/tmp/documents/agreement.pdf", 1, "/MediaBox")
gPdf.UseImportedTemplate(pdf, 0, 0, 150, 0)
_ = gPdf.WritePdf("/tmp/documents/see-all.pdf")
}
StackTrace:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1003d8a5c]
goroutine 1 [running]:
github.com/phpdave11/gofpdi.(*PdfReader).resolveObject(0x140000b4210, 0x0)
/Users/vishaljain/go/pkg/mod/github.com/phpdave11/[email protected]/reader.go:599 +0x13c
github.com/phpdave11/gofpdi.(*PdfReader).readPages(0x140000b4210)
/Users/vishaljain/go/pkg/mod/github.com/phpdave11/[email protected]/reader.go:1228 +0x4c
github.com/phpdave11/gofpdi.(*PdfReader).read(0x140000b4210)
/Users/vishaljain/go/pkg/mod/github.com/phpdave11/[email protected]/reader.go:1622 +0x4c
github.com/phpdave11/gofpdi.(*PdfReader).init(0x140000b4210)
/Users/vishaljain/go/pkg/mod/github.com/phpdave11/[email protected]/reader.go:75 +0x11c
github.com/phpdave11/gofpdi.NewPdfReader({0x1003f9d75, 0x3d})
/Users/vishaljain/go/pkg/mod/github.com/phpdave11/[email protected]/reader.go:61 +0xc4
github.com/phpdave11/gofpdi.(*Importer).SetSourceFile(0x1400009e040, {0x1003f9d75?, 0x5000?})
/Users/vishaljain/go/pkg/mod/github.com/phpdave11/[email protected]/importer.go:69 +0x80
github.com/signintech/gopdf.(*GoPdf).ImportPage(0x140000cc000, {0x1003f9d75?, 0x0?}, 0x0?, {0x1003f0cbc, 0x9})
/Users/vishaljain/go/pkg/mod/github.com/signintech/[email protected]/gopdf.go:1387 +0x40
main.main()
/Users/vishaljain/go/src/pdftester/main.go:9 +0xcc
exit status 2
If we can add a nil check on the method it would be really helpful, on this specific file
Facing the same issue. An solutions?
seems to be fixed by this code in a fork: https://github.com/phpdave11/gofpdi/commit/7591c1ffd5b41753b4591967abc34ff504da34d3 https://github.com/happyreturns/gofpdi