pdfcpu / pdfcpu

A PDF processor written in Go.

Home Page:http://pdfcpu.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bookmark export does not list/export single first-level bookmark

xelan opened this issue · comments

Bookmark export does not list/export single first-level bookmark

Please ensure the following:

  • Your issue is based on the latest commit

Tested with:

pdfcpu: v0.7.0 dev
commit: f783bf23 (2024-04-15T12:17:46Z)
base  : go1.22.1
pdfcpu: v0.8.0 dev
commit: 576f15e (2024-04-24T22:27:04Z)
base  : go1.22.0
  • State your OS and OS version

Debian 11, Debian 12

For PDFs with only one first-level bookmark, that bookmark is not shown in list/export. However, it's descendants are included in the export.

example2.pdf

pdfcpu bookmarks export example2.pdf && cat out.json

Expected:

{
	"header": {
		"source": "example2.pdf",
		"version": "pdfcpu v0.8.0 dev",
		"creation": "2024-04-29 13:16:12 CEST",
		"author": "Jane Doe",
		"creator": "Example Creator",
		"producer": "Example Producer"
	},
	"bookmarks": [
		{
			"title": "Awesome PDF",
			"page": 1,
			"kids": [
				{
					"title": "Section 1",
					"page": 1
				},
                                {
					"title": "Section 2",
					"page": 1
				}
			]
		}
	]
}

Actual:

{
	"header": {
		"source": "example2.pdf",
		"version": "pdfcpu v0.8.0 dev",
		"creation": "2024-04-29 13:16:12 CEST",
		"author": "Jane Doe",
		"creator": "Example Creator",
		"producer": "Example Producer"
	},
	"bookmarks": [
		{
			"title": "Section 1",
			"page": 1
		},
		{
			"title": "Section 2",
			"page": 1
		}
	]
}

Another testfile with one first-level bookmark (which is omitted by pdfcpu bookmarks export)
bookmarks-only-h1.pdf

Thank you very much for investigating this issue😊

The behaviour of this was based on Apple Preview's, now it is based on Acrobat Reader's.
Fixed with latest commit!

Thank you very much for the quick fix!