Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addPageWatermark: ctx.PageDict(pageNr, consolidateRes) returns no error, but nil dictionary #866

Open
comzine opened this issue May 5, 2024 · 1 comment
Assignees

Comments

@comzine
Copy link

comzine commented May 5, 2024

OS: macOS 14.4.1
pdfcpu 0.8.0

I use api.AddWatermarksSliceMapFile(...) for printing stamps inside a pdf file. Unfortunately I get panics from

func mapassign_faststr(t *maptype, h *hmap, s string) unsafe.Pointer {
	if h == nil {
		panic(plainError("assignment to entry in nil map"))
	}

With debugging I found out, that the following is probably the reason for that:

func addPageWatermark(ctx *model.Context, pageNr int, wm model.Watermark) error {
	if pageNr > ctx.PageCount {
		return errors.Errorf("pdfcpu: invalid page number: %d", pageNr)
	}

	if log.DebugEnabled() {
		log.Debug.Printf("addPageWatermark page:%d\n", pageNr)
	}

	if wm.Update {
		if log.DebugEnabled() {
			log.Debug.Println("Updating")
		}
		if _, err := removePageWatermark(ctx, pageNr); err != nil {
			return err
		}
	}

	consolidateRes := false
	d, pageIndRef, inhPAttrs, err := ctx.PageDict(pageNr, consolidateRes)
	if err != nil {
		return err
	}

d is nil, but err is nil too.

@hhrutter
Copy link
Collaborator

hhrutter commented May 9, 2024

Can you share a test file in order to reproduce this?
There is a reason for returning nil for d when calling PageDict , maybe you pass in an invalid page number?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants