« Return to Thread: Bookmarks

Re: Bookmarks

by William Rickards :: Rate this Message:

Reply to Author | View in Thread

This is VB.net code that I use to insert bookmarks that refer to specific pages.
Just creating the outline objects creates the bookmarks.
First you get a reference to the bookmark root, then you add
hierarchical outline objects based on action objects.

Let's say you have a pdfwriter object, m_wrtReport, and a contentbyte
reference, m_objContentByte.

      Dim objOutlineRoot As iTextSharp.text.pdf.PdfOutline
      Dim objOutline As iTextSharp.text.pdf.PdfOutline
      Dim objSubOutline As iTextSharp.text.pdf.PdfOutline
      Dim objAction As iTextSharp.text.pdf.PdfAction

            ' get bookmarks root
            objOutlineRoot = m_objContentByte.RootOutline

            ' add page 1 bookmark
            objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(1,
New iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH),
m_wrtReport)
            objOutline = New
iTextSharp.text.pdf.PdfOutline(objOutlineRoot, objAction, "Page 1")

            ' now add suboutlines for page 2 and 3
            objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(2,
New iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH),
m_wrtReport)
            objSubOutline = New
iTextSharp.text.pdf.PdfOutline(objOutline, objAction, "Page 2")

            objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(3,
New iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH),
m_wrtReport)
            objSubOutline = New
iTextSharp.text.pdf.PdfOutline(objOutline, objAction, "Page 3")

            ' add page 4 bookmark
            objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(4,
New iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH),
m_wrtReport)
            objOutline = New
iTextSharp.text.pdf.PdfOutline(objOutlineRoot, objAction, "Page 4")

            ' now add suboutlines for page 5
            objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(5,
New iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH),
m_wrtReport)
            objSubOutline = New
iTextSharp.text.pdf.PdfOutline(objOutline, objAction, "Page 5")


Will Rickards



On Wed, Apr 22, 2009 at 9:55 AM, johntheface <lace.john@...> wrote:

>
> I have an app that creates a PDF document using iTextSharp. After the
> document has been created I need to add bookmarks to it. I don't want to add
> any extra pages I just want bookmarks that will take to user to a certain
> page when they click on it. I have found lots of examples online but I
> haven't been able to get it working. I'm aware I'm supposed to use the
> PdfOutline object but I've been trying different examples for days and can't
> get it working. Just to get me started could someone tell me how to add a
> bookmark structure to an existing PDF document without adding any extra
> pages. eg the following structure for a 5 page document:
>
> |---Page 1
> |      |
> |      --- Page 2
> |      |
> |      --- Page 3
> |
> |---Page 4
> |      |
>       --- Page 5
>
> Thanks in advance
> --
> View this message in context: http://www.nabble.com/Bookmarks-tp23175463p23175463.html
> Sent from the itextsharp-questions mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> Stay on top of everything new and different, both inside and
> around Java (TM) technology - register by April 22, and save
> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
> 300 plus technical and hands-on sessions. Register today.
> Use priority code J9JMT32. http://p.sf.net/sfu/p
> _______________________________________________
> itextsharp-questions mailing list
> itextsharp-questions@...
> https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
>

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
itextsharp-questions mailing list
itextsharp-questions@...
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions

 « Return to Thread: Bookmarks