Problems with creating bookmarks from content list

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Jajabings63
User
Posts: 25
Joined: Mon Feb 26, 2024 10:07 am

Problems with creating bookmarks from content list

Post by Jajabings63 »

Dear Community,
I have created bookmarks from the contents list of a document. Unfortunately, the pages are not numbered consecutively so that the jump addresses are not determined correctly.
I have not been able to find a solution with a Java script, as the jump instruction is not a property of the bookmark and I have not been able to get any further.
Does anyone have any ideas on how to solve this problem?
Thank you!
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19913
Joined: Mon Jan 12, 2009 8:07 am

Re: Problems with creating bookmarks from content list

Post by Stefan - PDF-XChange »

Hello Jajabings63,

Can you please provide us with an example of this type of file? As I am not sure I 100% understand the inconsequential arrangement and would appreciate if I can take a look at such a sample so that I can better understand what is happening!

Kind regards,
Stefan
Jajabings63
User
Posts: 25
Joined: Mon Feb 26, 2024 10:07 am

Re: Problems with creating bookmarks from content list

Post by Jajabings63 »

Hello Stefan,
I have automatically created the bookmarks from the table of contents in the attached file. Due to the file size, I have only extracted the table of contents and uploaded it as an attachment. As you can see, the jump addresses were created from the selected text in the table of contents. If the pages were numbered consecutively, the >jump addresses would also be correct. Only in my case, the file was not numbered consecutively, so the jump addresses do not correspond to the page number. I had tried to address the jump addresses via a Java script. But I did not succeed because the bookmark does not recognise a jump address object.
I hope you have now understood the problem. Of course I can adjust the jump addresses manually. But it would be easier using a script.

Greetings JaJaBings63






Test_Bookmark_from_Content.pdf
You do not have the required permissions to view the files attached to this post.
User avatar
Paul - PDF-XChange
Site Admin
Posts: 7370
Joined: Wed Mar 25, 2009 10:37 pm

Re: Problems with creating bookmarks from content list

Post by Paul - PDF-XChange »

Hi, Jajabings63

all the bookmarks I see have a Goto action set to page 1.

I am keen to test this with the full document, would you consider uploading it here: https://files.tracker-software.support/ ... asWaRrBYrY

It allows upload only, nobody can see your document except us. If you do upload your file there please let me know once the upload is complete and I will disable the file drop.
Best regards

Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com
User avatar
PHK
User
Posts: 1400
Joined: Tue Nov 24, 2020 4:02 pm

Re: Problems with creating bookmarks from content list

Post by PHK »

I sympathize with Jajabings63's problem here. As I understand it, the page numbers on the print TOC refer to the physical pages and there is no easy way of capturing those page numbers to set as Bookmark Destinations as one would see in the Bookmark Properties what OP calls "jumps." As OP states, it can be done (tediously) manually by setting each destination to the correct page in the PDF file in Properties but an 'automated' function would be very useful.

On the other hand, to create such a function does seem to be unusually challenging.
All best,

FringePhil
User avatar
Paul - PDF-XChange
Site Admin
Posts: 7370
Joined: Wed Mar 25, 2009 10:37 pm

Re: Problems with creating bookmarks from content list

Post by Paul - PDF-XChange »

Hi, PHK

it should be working and as I understand it the TOC should link to the correct pages.

Do you have a sample file that behaves differently? I was hoping to see Jajabings63's original and try from scratch.
Best regards

Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com
User avatar
PHK
User
Posts: 1400
Joined: Tue Nov 24, 2020 4:02 pm

Re: Problems with creating bookmarks from content list

Post by PHK »

Paul - Tracker Supp wrote: Mon Nov 04, 2024 10:58 pm Hi, PHK

it should be working and as I understand it the TOC should link to the correct pages.

Do you have a sample file that behaves differently? I was hoping to see Jajabings63's original and try from scratch.
I have not used it much. That is partly because I quickly got frustrated with it and decided it was not a priority for me. But I might try a few experiments with it to see what happens.

I hope OP can help you out with their original.
All best,

FringePhil
User avatar
Paul - PDF-XChange
Site Admin
Posts: 7370
Joined: Wed Mar 25, 2009 10:37 pm

Re: Problems with creating bookmarks from content list

Post by Paul - PDF-XChange »

Thanks PHK.

Jajabings63, it would seem you uploaded the same PDF. Thanks for providing it again, however we were looking for the original with all the pages.

The functionality should be working properly and we are keen to determine if the issue is the file or the software. We need the document with all the pages to test that they link properly as we believe they should.

Would it be possible to have that? You may redact any sensitive information first if needed as that should not impact the functionality we are testing.
Best regards

Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com
Jajabings63
User
Posts: 25
Joined: Mon Feb 26, 2024 10:07 am

Re: Problems with creating bookmarks from content list

Post by Jajabings63 »

Hallo Together,

I did the Upload!

I hope now you see the problem.

JaJaBings
User avatar
Paul - PDF-XChange
Site Admin
Posts: 7370
Joined: Wed Mar 25, 2009 10:37 pm

Re: Problems with creating bookmarks from content list

Post by Paul - PDF-XChange »

Hi, Jajabings63

thank you so much for that. I expect the team will be looking at that today.
Best regards

Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com
User avatar
PHK
User
Posts: 1400
Joined: Tue Nov 24, 2020 4:02 pm

Re: Problems with creating bookmarks from content list

Post by PHK »

PHK wrote: Mon Nov 04, 2024 9:48 pm I sympathize with Jajabings63's problem here. As I understand it, the page numbers on the print TOC refer to the physical pages and there is no easy way of capturing those page numbers to set as Bookmark Destinations as one would see in the Bookmark Properties what OP calls "jumps." As OP states, it can be done (tediously) manually by setting each destination to the correct page in the PDF file in Properties but an 'automated' function would be very useful.

On the other hand, to create such a function does seem to be unusually challenging.
On further thought and examination, I withdraw my comments quoted above.

On the other hand, I think I have a better understanding of jaja's issues. I note that the page numbering as presented in the produced TOC refers to the named title of those pages rather than the actual sequential virtual pages as seen in the Thumbnails panel. In a sense, that is not an issue so long as the page title is the same as the virtual sequence page of the stack. This also would work where there are gaps or mismatches between the source document numbering and the PDF page sequence. The PDF pages would need to be renumbered accordingly.

However, if the user as imposed non-sequential titles to the pages, the TOC will show those titles rather than the sequential number. And if the source document does not have page titles that are exactly like the sequential numbering, things can get confusing. But this might be a blessing, not a curse.

For instance, if a document (scanned or downloaded) has a few pages at the top of the stack that are outside of the main page-numbering regime there will be a disconnect. Those pages might be a title page, a TOC, an exhibits schedule, quotation sources, etc. So, the document's main numbering might not start until the tenth page or something. Therefore in that example, the produced TOC would not agree with the source document's TOC with an offset of 10. The way to over come this is use the Page Numbering tool

image.png

to create page titles that match to source document's numbering regime. So in this example, the user would redefine the page titles by starting the PDF page numbering to match the source document. This is not difficult to do and I hope this is the sort of solution jaja needs.
You do not have the required permissions to view the files attached to this post.
All best,

FringePhil
User avatar
PHK
User
Posts: 1400
Joined: Tue Nov 24, 2020 4:02 pm

Re: Problems with creating bookmarks from content list

Post by PHK »

On further thought, perhaps the way to address this issue is to understand that individual pages can be identified three slightly different ways: (i) the default way of assigning sequential numbers (1, 2, 3,...) that is done by the app and the sequential number appears as the page title or name; (ii) by using the Page Numbering tool; and (iii) by renaming the individual pages by using the F2 tool for each selected thumbnail, both of the latter methods are done by the user.

Confusion can arise if only method (i) above is used and that does not conform to the numbering protocol of the original document when using the TOC tool. I think that is what jaja is experiencing.

But if method (ii) or (iii) above is used, then the TOC tool will use the user-defined title (or name). That can be useful if the user elects to create page titles that agree with the source document, whether scanned or downloaded.

It doesn't help, in my opinion, that the Page Numbering tool uses the word "Numbering." What it is really doing is creating new Titles for the pages which are visible in the Thumbnails panel although the true sequential page number is not. "Page Titling" or "Page Naming" would conform better to what the tool is actually doing, in my opinion, although user-defined numbers may be part of the title or name.
All best,

FringePhil
Jajabings63
User
Posts: 25
Joined: Mon Feb 26, 2024 10:07 am

Re: Problems with creating bookmarks from content list

Post by Jajabings63 »

I thought I could solve the problem with the following Java script. However, it appears that I cannot access the mouse-up action. Does anyone know what the problem is?
Of course the part in the script where the correct page is determined is still missing. But that is not a problem.

Code: Select all

function listBookmarkPageDestinations(bookmark, indent = "") {
    console.println(indent + "+- " + bookmark.name);

    // Überprüfen auf "Mouse Up"-Aktionen, die zu einer bestimmten Seite springen sollen
    if (bookmark.action && bookmark.action.type === "Named" && bookmark.action.action === "GoTo") {
        // Wenn eine GoTo-Aktion gefunden wird, lese das Ziel aus
        try {
            if (bookmark.action.dest) {
                let targetPageNum = bookmark.action.dest[0] + 1; // Seite ist 0-basiert
                console.println(indent + "    -> Sprung zu Seite: " + targetPageNum);
            } else {
                console.println(indent + "    -> Keine direkte Zielseite definiert.");
            }
        } catch (e) {
            console.println(indent + "    -> Fehler beim Auslesen der Sprungadresse: " + e.message);
        }
    } else {
        console.println(indent + "  -> Keine Mouse Up-Sprungaktion gefunden.");
    }

    // Durchlaufe alle untergeordneten Lesezeichen
    if (bookmark.children && bookmark.children.length > 0) {
        for (var i = 0; i < bookmark.children.length; i++) {
            listBookmarkPageDestinations(bookmark.children[i], indent + "  ");
        }
    }
}

// Starte das Skript am Lesezeichen-Root
if (this.bookmarkRoot.children && this.bookmarkRoot.children.length > 0) {
    for (var i = 0; i < this.bookmarkRoot.children.length; i++) {
        listBookmarkPageDestinations(this.bookmarkRoot.children[i]);
    }
} else {
    console.println("Keine Lesezeichen im Dokument gefunden.");
}
Mathew
User
Posts: 606
Joined: Thu Jun 19, 2014 7:30 pm

Re: Problems with creating bookmarks from content list

Post by Mathew »

Where did you find the documentation for the .action property of bookmarks? I don't think that's implemented in PDFX-Change. At least, if I enumerate the properties I only get
  • children
    color
    doc
    name
    open
    parent
    style

Code: Select all

for (let i in this.bookmarkRoot.children[0]) console.println(i);
The above matches the javascript API:
image.png
It would, however, be a fantastic addition to have access to something like .action, especially if it were possible to set GoTo actions that would update with page additions. I think I posted it as a feature request somewhere. The only actions that I've been able to add to bookmarks are javascript actions.

To find the page that the actions point to, my workaround is to use .execute() method on the bookmark, and then see what the page number is. A bit messy, slow and roundabout, and if there's no action associated with the bookmark, it will return the current page.
You do not have the required permissions to view the files attached to this post.
Jajabings63
User
Posts: 25
Joined: Mon Feb 26, 2024 10:07 am

Re: Problems with creating bookmarks from content list

Post by Jajabings63 »

Dear Community,

I have developed a Java script that makes the desired changes to the bookmarks.
The search words (page, chapter) must be adapted according to the conditions in the document.
Have fun with it!

Code: Select all

// JavaScript Document
var pageCount = this.numPages; 
var searchAnchor = "page:"; 
var lastFoundPage = 0; // Variable to store the last found page
var foundPageNum = 0; // Reset found page number
var storedPageNum = 0; // Variable to store the chapter number

function adjustBookmarkByAnchor(bookmark) {
    // Execute the bookmark to determine the target page
    try {
        bookmark.execute();
    } catch (e) {
        console.println("Error executing bookmark '" + bookmark.name + "': " + e.message);
        return;
    }

    // Save the old target page
    var oldTargetPage = this.pageNum;

    // Iterate over all pages, starting from the last found page
    for (var i = lastFoundPage; i < pageCount; i++) {

        // Iterate over words on the page
        for (var j = 0; j < this.getPageNumWords(i); j++) {
            var word = this.getPageNthWord(i, j, false).trim().toLowerCase();

            if (word === "chapter:") {
                // Check the next word and store it if it's a number
                var nextWord = this.getPageNthWord(i, j + 1, false).trim();
                if (!isNaN(parseInt(nextWord, 10))) {
                    storedPageNum = parseInt(nextWord, 10) - 1;
                }
            } else if (word === "page:") {
                // Check if the word after "page" is a number
                var nextWord = this.getPageNthWord(i, j + 1, false).trim();
                if (!isNaN(parseInt(nextWord, 10))) {
                    foundPageNum = parseInt(nextWord, 10) - 1;
                } else if (storedPageNum !== -1) {
                    foundPageNum = storedPageNum; // Use chapter number if no number follows "page"
                }
            }
        }

        // Check if the found page exceeds the old target page, to update found page
        if (foundPageNum > oldTargetPage) {
            console.println("Target page: " + (oldTargetPage + 1));
            console.println("Found page: " + (foundPageNum + 1));
            break;
        }

        // Check and set the new page if necessary
        if (oldTargetPage == foundPageNum) {
            bookmark.setAction("this.pageNum = " + i + ";"); 
            console.println("Bookmark " + bookmark.name + " updated from page " + (oldTargetPage + 1) + " to page " + (i + 1) + ".");
            lastFoundPage = i;
            break; // End loop once a match is found
        }
    }

    // If the bookmark has children, iterate through them recursively
    if (bookmark.children != undefined) {
        for (var k = 0; k < bookmark.children.length; k++) {
            adjustBookmarkByAnchor(bookmark.children[k]);
        }
    }
}

// Main program: iterate over all bookmarks
console.println("Starting bookmark adjustment...");
for (var m = 0; m < this.bookmarkRoot.children.length; m++) {
    adjustBookmarkByAnchor(this.bookmarkRoot.children[m]);
}

app.alert("Bookmarks have been adjusted.");
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11292
Joined: Wed Jan 03, 2018 6:52 pm

Problems with creating bookmarks from content list

Post by Daniel - PDF-XChange »

:)
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Jajabings63
User
Posts: 25
Joined: Mon Feb 26, 2024 10:07 am

Re: Problems with creating bookmarks from content list

Post by Jajabings63 »

I have a request for the development team.
When developing the bookmarks from the table of contents, the software checks whether the page listed in the table of contents is less than or equal to the document page number. In cases where the pages are not numbered consecutively and have jumps, this means that all references with a larger number are not developed. This point should be corrected. Thank you!
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11292
Joined: Wed Jan 03, 2018 6:52 pm

Re: Problems with creating bookmarks from content list

Post by Daniel - PDF-XChange »

Hello, Jajabings63

Thank you for the suggestion, I am not certain that I follow what you mean here, Could I perhaps ask for a sample file showing the issue, with some illustrative screenshots to help clarify what the problem I am looking for is exactly? With that I can definitely bring it to the Dev team if it is something unexpected.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Jajabings63
User
Posts: 25
Joined: Mon Feb 26, 2024 10:07 am

Re: Problems with creating bookmarks from content list

Post by Jajabings63 »

Hi Daniel,

it's always the same file I just uploaded.

Greetings
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11292
Joined: Wed Jan 03, 2018 6:52 pm

Re: Problems with creating bookmarks from content list

Post by Daniel - PDF-XChange »

Hello, Jajabings63

Okay I do see the file, however, I am still not following the report. Could you please elaborate on what exactly is being done, and showcase what is wrong about the output? What is the final expectation here, or in your eyes, what would be the "correct" way to do this?

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Jajabings63
User
Posts: 25
Joined: Mon Feb 26, 2024 10:07 am

Re: Problems with creating bookmarks from content list

Post by Jajabings63 »

Dear Daniel,
I will try to describe the problem in more detail.
If you create bookmarks from a table of contents, the table of contents including the page referred to in the table of contents is selected and the menu item for creating bookmarks from the table of contents is called up. The bookmarks are then created automatically. If you do this with my example file, all bookmarks are created up to the point where the table of contents refers to a page that is larger than the document page number.
The problem is that in a document where the page numbers are not numbered consecutively and therefore from a certain reference in the table of contents, this refers to a page number that is greater than the total page number, the bookmark for this page is no longer created because I assume that the programme checks whether the page referred to in the table of contents is less than or equal to the document page number.
Since I have written a Java script that corrects the jump addresses to the correct page, the subsequent bookmarks must be added manually. If all bookmarks are created, regardless of whether the reference points to a page that is greater than the document page number, my Java script could be used without manually adding the missing bookmarks.
Thank you!

JaJaBings
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11292
Joined: Wed Jan 03, 2018 6:52 pm

Re: Problems with creating bookmarks from content list

Post by Daniel - PDF-XChange »

Hello, Jajabings63

Thank you for the added explanation. If I am understanding, what you need is essentially a checkbox in the "Create bookmarks from ToC" menu, which says "Create bookmarks with no GoTo action for entries that have an invalid page number".

This would result in a number of bookmarks (essentially all of them beyond your "VII.1.5" bookmark), being created as empty bookmarks with no action at all, and only a name?

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Jajabings63
User
Posts: 25
Joined: Mon Feb 26, 2024 10:07 am

Re: Problems with creating bookmarks from content list

Post by Jajabings63 »

Hello Daniel,

no, I would like the bookmarks to be created with the page number specified in the table of contents. Then I would correct the jump address with my Java script.

Greetings JaJaBings
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11292
Joined: Wed Jan 03, 2018 6:52 pm

Re: Problems with creating bookmarks from content list

Post by Daniel - PDF-XChange »

Hello, Jajabings63

Understood, I cannot make any promises, but I have raised the topic with the Dev team. Perhaps we can see this offering in the future.

[Edit]
That got a very quick response, According to the PDF specification, all Goto actions must refer to an existing page object. We cannot adhere to the spec and create such links beyond the end of the document. As such, the request has been unfortunately, rejected.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Mathew
User
Posts: 606
Joined: Thu Jun 19, 2014 7:30 pm

Re: Problems with creating bookmarks from content list

Post by Mathew »

A workaround could be to add a large number of blank pages at the end of the document, generate the bookmarks, then delete the extra pages.

There's a feature request to be able to get/set destination through javascript that would make a script to do this work: viewtopic.php?p=177622#p177622 If there was an .action property (as in @jajabings63 script above) that had properties such as destination/script/zoom/etc that one could get/set that would open a lot of options for scripting bookmarks.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11292
Joined: Wed Jan 03, 2018 6:52 pm

Problems with creating bookmarks from content list

Post by Daniel - PDF-XChange »

:)
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com