pdfcpu icon indicating copy to clipboard operation
pdfcpu copied to clipboard

bookmarks.go : unnecessary check pagefrom

Open kaiceo opened this issue 3 years ago • 2 comments

https://github.com/pdfcpu/pdfcpu/blob/master/pkg/pdfcpu/bookmarks.go

line:245~247

if i == 0 && parentPageNr != nil && bm.PageFrom < *parentPageNr {
		  return nil, nil, 0, errCorruptedBookmarks
	  }

if i > 0 && bm.PageFrom < bms[i-1].PageFrom {
    return nil, nil, 0, errCorruptedBookmarks
}

in some case, current bookmark pagefrom num maybe larger than the last bookmark pagefrom num, the last bookmark do not must point the last page

kaiceo avatar Sep 02 '21 04:09 kaiceo

Hello!

Can you please provide a small sample file in order to reproduce this. Thank you

hhrutter avatar Sep 04 '21 07:09 hhrutter

f := "4wd-opt.pdf"
bms := []pdfcpu.Bookmark{{Title: "t1", PageFrom: 2}, {Title: "t2", PageFrom: 1}}
err := api.AddBookmarksFile(f, "o.pdf", bms, pdfcpu.NewDefaultConfiguration())
if err != nil {
	fmt.Println("add bookmark", err)
}

[root@10 test]# go run main.go add bookmark pdfcpu: corrupt bookmark

kaiceo avatar Sep 04 '21 08:09 kaiceo