Skip to content

Error while inserting a random PDF to another PDF #61

@Vishalj32

Description

@Vishalj32

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/gofpdi@v1.0.14-0.20211212211723-1f10f9844311/reader.go:599 +0x13c
github.com/phpdave11/gofpdi.(*PdfReader).readPages(0x140000b4210)
        /Users/vishaljain/go/pkg/mod/github.com/phpdave11/gofpdi@v1.0.14-0.20211212211723-1f10f9844311/reader.go:1228 +0x4c
github.com/phpdave11/gofpdi.(*PdfReader).read(0x140000b4210)
        /Users/vishaljain/go/pkg/mod/github.com/phpdave11/gofpdi@v1.0.14-0.20211212211723-1f10f9844311/reader.go:1622 +0x4c
github.com/phpdave11/gofpdi.(*PdfReader).init(0x140000b4210)
        /Users/vishaljain/go/pkg/mod/github.com/phpdave11/gofpdi@v1.0.14-0.20211212211723-1f10f9844311/reader.go:75 +0x11c
github.com/phpdave11/gofpdi.NewPdfReader({0x1003f9d75, 0x3d})
        /Users/vishaljain/go/pkg/mod/github.com/phpdave11/gofpdi@v1.0.14-0.20211212211723-1f10f9844311/reader.go:61 +0xc4
github.com/phpdave11/gofpdi.(*Importer).SetSourceFile(0x1400009e040, {0x1003f9d75?, 0x5000?})
        /Users/vishaljain/go/pkg/mod/github.com/phpdave11/gofpdi@v1.0.14-0.20211212211723-1f10f9844311/importer.go:69 +0x80
github.com/signintech/gopdf.(*GoPdf).ImportPage(0x140000cc000, {0x1003f9d75?, 0x0?}, 0x0?, {0x1003f0cbc, 0x9})
        /Users/vishaljain/go/pkg/mod/github.com/signintech/gopdf@v0.18.0/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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions