Page 1 of 1

Split PDF on bookmarks - get bookmark page

Posted: Mon Jun 27, 2016 4:14 pm
by swmclean
I am evaluating GDPicture as a potential tool to use for PDF manipulation.

We have a task to split large PDF files at their internal bookmarks, resulting in multiple, separate PDF files.

I have successfully parsed the list of bookmarks (as directed by your SDK) and can obtain the title, text, etc.

Code: Select all

private static void ReadBookmarks(int bookmarkId, int level)
{
    while (true)
    {
        Console.WriteLine("Title: [{0}]{1}Level: [{2}]{1}",
            _pdf.GetBookMarkTitle(bookmarkId), Environment.NewLine, level);
        if (_pdf.GetBookMarkChildCount(bookmarkId) > 0)
        {
            ReadBookmarks(_pdf.GetBookMarkFirstChildID(bookmarkId), level + 1);
        }
        bookmarkId = _pdf.GetBookMarkNextID(bookmarkId);
        if (bookmarkId == 0) break;
    }
}
There is no member for the destination page, though, so I cannot identify the page numbers in order to split the file.

I have also followed the instructions given elsewhere in the forum to parse the annotations as actions to obtain the page references.

Unfortunately, the bookmarks are not recognized as annotations (GetAnnotationCount returns 0). Because of this, that recommendation (given on several similar posts to this one) is not helpful.

It appears that you typically intend bookmarks to be accessed in your viewer. My files, however, must be handled programmatically.

Is there a method when parsing a PDF to access the destination page and location of a PDF bookmark and split the file on that location.

Re: Split PDF on bookmarks - get bookmark page

Posted: Tue Jun 28, 2016 5:28 pm
by delbeke
Hi swmclean

You have miss GetActionPageDestination
(see: https://www.gdpicture.com/guides/gdpicture/web ... ation.html)

use the bookmarkId as the first parameter.

Hope this help

Re: Split PDF on bookmarks - get bookmark page

Posted: Tue Jun 28, 2016 6:01 pm
by swmclean
Hi delbeke,

No, in fact, I did not miss that. However, since I do not have an actionId (I would have to start from an annotation to get that, and I have zero annotations), I cannot execute that method.

To be clear, I did already read the numerous other responses where the same recommendation was given. It appears to assume that all bookmarks are also annotations. They are not. Because there is no actionId associated with the bookmark (it's not an annotation), this method will not work.

Re: Split PDF on bookmarks - get bookmark page

Posted: Wed Jun 29, 2016 9:53 am
by delbeke
Hi swmclean

You are right. Sorry.

You must use GetBookMarkActionID before calling GetActionPageDestination.
(see : https://www.gdpicture.com/guides/gdpicture/web ... ionID.html)

something like
int actionID = _pdf.GetBookMarkActionID (bookmarkId);
PdfActionType pdfActionType = _pdf.GetActionType(actionID);
_pdf.GetActionPageDestination(actionID, out destinationType, out pageNum, out left, out top, out right, out bottom, out zoom);

Jean-Luc

Re: Split PDF on bookmarks - get bookmark page

Posted: Wed Jun 29, 2016 2:19 pm
by swmclean
Ah - I did miss that, so I am able to identify the destination.
Now for part 2 - Am I able to break the PDF on the bookmarks or just on the pages where they appear?

Re: Split PDF on bookmarks - get bookmark page

Posted: Wed Jun 29, 2016 6:20 pm
by delbeke
Hi swmclean

It 's up to you to split your pdf with your own way.
The bookmarks can only help you to point to a page.
If you make an ordered list of the pointeds pages, you can find the starting and the ending pages for your splits.

Jean-Luc

Re: Split PDF on bookmarks - get bookmark page

Posted: Wed Jun 29, 2016 6:25 pm
by swmclean
Yes, I have already figured out how to split on the pages. I was wondering if I could split at the bookmarks instead.