How to read Outline Dictionary of current document?

74 views
Skip to first unread message

Yan Pashkovsky

unread,
Apr 26, 2016, 3:43:18 PM4/26/16
to libHaru
High everyone! :)

I want to be able to read outline structure of current document and store it somewhere, then create new outline item and make it root and link this outline to the new root.
For example I read pdf with this outline dictionary:
1.Header
1.1someheader
1.2another header
I want to make output pdf with such outline:
1.Top header
1.1.Header
1.1.1someheader
1.1.2another header

There is no read_outline function. Do you know is it possible to do with libharu?

Kind regards,
Yan

Bill Horger

unread,
Apr 26, 2016, 4:10:01 PM4/26/16
to LibHaru Group
You can create a Table of Contents (aka Outline) by saving the link to pages as they are added to the document.

The relevant function names are:
HPDF_CreateOutline
HPDF_Outline_SetOpened
HPDF_CreateOutline
HPDF_Page_CreateDestination
HPDF_Destination_SetFit
HPDF_Outline_SetDestination

Some declarations first:
static HPDF_Page    current_page;    // use this for annotating in a bookmark
static HPDF_Page    PageIndex[MAX_PDF_PAGES];    // for annotation
static HPDF_Outline    Outline[MAX_PDF_PAGES];
static char            *BookmarkText[MAX_PDF_PAGES]/*[MAX_BOOKMARK_TEXT]*/;
static int            current_pages_indexed = 0;


My function to create the running account of the book marks is:
void    PDFAddPageToOutline(char *bookmarktext)
{
    char *localtext = (char *) calloc(1,strlen(bookmarktext)+1);
    if(current_pages_indexed < MAX_PDF_PAGES)
    {
        strcpy(localtext,bookmarktext);
        BookmarkText[current_pages_indexed] = localtext;
        PageIndex[current_pages_indexed] = current_page;        // save the current page pointer
        ++current_pages_indexed;
    }// bump the index
}

And the code just before I close and save the PDF file is:
    if(current_pages_indexed)
    {
        root = HPDF_CreateOutline(pdf,NULL,"Pages Available",NULL);
        HPDF_Outline_SetOpened(root,HPDF_TRUE);
        for(i=0;i<current_pages_indexed;++i)
        {
            Outline[i] = HPDF_CreateOutline(pdf,root,BookmarkText[i],NULL);
            free(BookmarkText[i]);
        }
        for(i=0;i<current_pages_indexed;++i)
        {
            dst=HPDF_Page_CreateDestination(PageIndex[i]);
            // HPDF_Destination_SetXYZ(dst,0,HPDF_Page_GetHeight(PageIndex[i]),1);
            HPDF_Destination_SetFit(dst);    // Fit the bookmarked page in the space available
            HPDF_Outline_SetDestination(Outline[i],dst);
        }
    }

This code requires a few more defines, etc. but should serve as a guide on how one can do this.


--
--
---
libHaru.org development mailing list
To unsubscribe, send email to libharu-u...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "libHaru" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libharu+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages