Nothing Special   »   [go: up one dir, main page]

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

outline tree validation #626

Closed
petervwyatt opened this issue May 25, 2023 · 6 comments
Closed

outline tree validation #626

petervwyatt opened this issue May 25, 2023 · 6 comments
Assignees

Comments

@petervwyatt
Copy link

Command: pdfcpu validate --mode=strict -v outline-test.pdf
for attached PDF outline-test.pdf
results in validation failure message: Fatal: pdfcpu: validateOutlineTree: corrupted child list 11 <> 14
from:

github.com/pdfcpu/pdfcpu/pkg/pdfcpu/validate.validateOutlineTree
        /Users/horstrutter/Documents/pdfcpu/pkg/pdfcpu/validate/outlineTree.go:148

when using:

pdfcpu: v0.4.1 dev
build : 2023-05-06T21:02:34Z
commit: 0342a83

The internal PDF is shown here:
image

I'm not understanding the failure message, but I do not believe there is anything wrong with the outline tree as specified by obj 11, obj 13 or obj 14.

Also (separately): I don't think the validation code is checking the absolute value of Count vs the number of entries at each level. If I change it to -9 or 99 there is no validation failure either in relaxed or strict mode.

@asciim0
Copy link
asciim0 commented May 30, 2023

A quick question - while your test showed that this doesn't trigger the error, the standard states (in table 150) that the Count value cannot be negative: "(Required if the document has any open outline entries) Total number of visible outline items at all levels of the outline. The value cannot be negative. This entry shall be omitted if there are no open outline items
Would you consider the negative value in Count an error? Or am I understanding the PDF or the standard wrong (very likely)?

@petervwyatt
Copy link
Author

Count exists in 2 places in outlines (sorry if my original report was unclear as to which Count I was referring to!):

  1. in the "root" Outline Dictionary (Table 150)
  2. in Outline Item Dictionaries - i.e. the nodes of the bookmarks (Table 151).

In the Outline Dictonary PDF says "Total number of visible outline items at all levels of the outline. The value cannot be negative.
This entry shall be omitted if there are no open outline items
." so this is always >= 0.

However in Outline Item Dictionaries, an algorithm is given that can result in a negative value (I guess technically it is no longer strictly a count) - the text ends with "If the outline item is closed, Count is negative and its absolute value is the number of descendants that would be visible if the outline item were opened."

@hhrutter hhrutter changed the title Incorrect strict validation failure for outline trees outline tree validation Jul 1, 2023
@hhrutter
Copy link
Collaborator
hhrutter commented Jul 4, 2023

@petervwyatt

I have a problem with the defnition of "Count" for outline item dicts.

ISO/DIS 32000-2:2020(E) states:
... If the outline item is closed, Count is negative and its absolute value is the number of descendants that would be visible if the outline item were opened....

It is unclear to me how to validate a negative "Count".

Are we talking about the number of immediate descendents that may be visible or the maximum including any derived descendents thay may be visible eg. when the whole outline hierarchy for a node is expanded?

@petervwyatt
Copy link
Author

The Adobe PDF 1.3 has a slightly clearer explanation:

(Required if the item has any descendants) If the item is open, the total number of its open descendants at all lower levels of the outline hierarchy. If the item is closed, a negative integer whose absolute value specifies how many descendants would appear if the item were reopened.

so it covers all descendants, but you need to take into account the open/closed-ness of those descendants. This is consistent across all Counts in outlines.

@hhrutter
Copy link
Collaborator
hhrutter commented Jul 4, 2023

OK - So if I have an open outline tree in my viewer and close one intermediary node, then PDF just wants to store the negated number of visible descendents and multiplies the current Count by -1.

That way next time I open the file and click on that outline item to open it the open/closedness from before the collapsing gets recalled.

Please correct me if I am wrong, ..seems like a negative Count has to be the negative counterpart of the result of the recursion needed to calculate the number of visible descendents in the first place.

@hhrutter
Copy link
Collaborator
hhrutter commented Jul 4, 2023

This is fixed with latest commit.

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

3 participants