Welcome Guest Search | Active Topics | Sign In | Register

Help with Creating BookMarks for an exisitng PDF Document Options
Darrell Reinke
Posted: Wednesday, August 31, 2011 5:09:53 PM
Rank: Advanced Member
Groups: Member

Joined: 7/18/2008
Posts: 76
Good Afternoon,

I am new to the EO.pdf object and I am trying to create some code that will open an existing PDF document and places bookmarks at specific pages within the document. The code below will open the PDF document and create the first bookmark correctly, however, I don't know the syntax to place the second bookmark at a specific page (It takes me to a new page altogether -- New AcmPageBreak()).

For example, the PDF document contains two merged documents. I know that the second PDF document starts on page 4 of the merged PDF and I would like to place another bookmark starting at page 4.


Any assistance would be greatly appreciated.

Code: Visual Basic.NET
'Create a new PdfDocument
               Dim doc As New PdfDocument(asFileName)

               'Create a new AcmRender object
               Dim render As New AcmRender(doc)

               'BookMark 1 -- How do I set the Page Number of this Break????
               Dim acmBookMarkContent As New AcmContent
               render.Render(acmBookMarkContent, New AcmPageBreak())
               Dim bookmark As New PdfBookmark("Student Living Weekly Reporting")
               'Initializes the bookmark's Destination property
               bookmark.Destination = acmBookMarkContent.CreateDestination()
               doc.Bookmarks.Add(bookmark)

               'BookMark 2 -- How do I set the Page Number of this Break????
               Dim acmBookMarkContent2 As New AcmContent
               render.Render(acmBookMarkContent2, New AcmPageBreak())
               Dim bookmark2 As New PdfBookmark("Summary of Sources")
               'Initializes the bookmark's Destination property
               bookmark2.Destination = acmBookMarkContent2.CreateDestination()
               doc.Bookmarks.Add(bookmark2)

               doc.Save(asFileName)
eo_support
Posted: Wednesday, August 31, 2011 5:19:36 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You don't really need to use AcmRender to create PdfBookmark object. You would just create a PdfBookmark object and then set the bookmark's Destination property.

Thanks!
Darrell Reinke
Posted: Wednesday, August 31, 2011 6:07:36 PM
Rank: Advanced Member
Groups: Member

Joined: 7/18/2008
Posts: 76
Haven't quit got the syntax down yet. The following code below creates the bookmarks, however, I still havn't been able to figure out how to set the page number for the bookmark? I hope I am not too far off from the answer.

Thank you for your help.

Code: Visual Basic.NET
'Create a new PdfDocument
               Dim doc As New PdfDocument(asFileName)

               Dim bookmark As New PdfBookmark("Student Living Weekly Reporting")
               'Initializes the bookmark's Destination property
               Dim pdfPage As New PdfPage
               Dim pdfDest As New PdfDestination(pdfPage, PdfDestFitMode.EntirePage)
               bookmark.Destination = pdfDest
               doc.Bookmarks.Add(bookmark)

               'BookMark 2 -- How do I set the Page Number of this Break????
               Dim acmBookMarkContent2 As New AcmContent

               Dim bookmark2 As New PdfBookmark("Summary of Sources")
               'Initializes the bookmark's Destination property
               Dim pdfPage2 As New PdfPage
               Dim pdfDest2 As New PdfDestination(pdfPage, PdfDestFitMode.EntirePage)
               bookmark.Destination = pdfDest2
               doc.Bookmarks.Add(bookmark2)

               doc.Save(asFileName)
Darrell Reinke
Posted: Wednesday, August 31, 2011 6:22:35 PM
Rank: Advanced Member
Groups: Member

Joined: 7/18/2008
Posts: 76
I am really close now.... Finally figured out how to reference the page within the PDF document, however, once the bookmarks render, they are still now pointing to the correct location.

Also, do you have a method that will allow us to save the PDF docuement with the BookMarks displayed?

Code: Visual Basic.NET
'Create a new PdfDocument
               Dim doc As New PdfDocument(asFileName)

               Dim bookmark As New PdfBookmark("RREEF Student Living Weekly Reporting")
               'Initializes the bookmark's Destination property
               Dim pdfPage As PdfPage = doc.Pages(0)
               Dim pdfDest As New PdfDestination(pdfPage, PdfDestFitMode.None)
               bookmark.Destination = pdfDest
               doc.Bookmarks.Add(bookmark)

               'BookMark 2 -- How do I set the Page Number of this Break????
               Dim acmBookMarkContent2 As New AcmContent

               Dim bookmark2 As New PdfBookmark("Summary of Sources")
               'Initializes the bookmark's Destination property
               Dim pdfPage2 As PdfPage = doc.Pages(2)
               Dim pdfDest2 As New PdfDestination(pdfPage2, PdfDestFitMode.EntirePage)
               bookmark.Destination = pdfDest2

               doc.Bookmarks.Add(bookmark2)

               doc.Save(asFileName)
eo_support
Posted: Wednesday, August 31, 2011 6:32:05 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You need to set doc.ViewerPreference.NonFullScreenPageMode to UseOutlines.

Thanks
Darrell Reinke
Posted: Thursday, September 1, 2011 12:48:33 PM
Rank: Advanced Member
Groups: Member

Joined: 7/18/2008
Posts: 76
Thank you for your assistance. I have provided a snippet of code that I hope someone on your site can use for future reference when creating bookmarks within an existing PDF document. You can obviously place the bookmark creation within a look, but thought this would provide a good reference for anyone new to the EO.PDF object.

Code: Visual Basic.NET
'Create a new PdfDocument
               Dim doc As New PdfDocument(asFileName)
               If Not (doc Is Nothing) Then
                  Dim bookmark As New PdfBookmark("BookMark1")
                  If Not (bookmark Is Nothing) Then
                     'Initializes the bookmark's Destination property
                     Dim pdfPage As New PdfPage
                     If Not (pdfPage Is Nothing) Then
                        pdfPage = doc.Pages(0) 'Pages are Zero based, so page 1 has an index of 0
                        Dim pdfDest As New PdfDestination(pdfPage, PdfDestFitMode.EntirePage)
                        If Not (pdfDest Is Nothing) Then
                           bookmark.Destination = pdfDest
                           doc.Bookmarks.Add(bookmark)
                        End If
                     End If
                  End If

                  'BookMark 2
                  Dim bookmark2 As New PdfBookmark("BookMark2")
                  If Not (bookmark2 Is Nothing) Then
                     Dim pdfPage2 As New PdfPage
                     If Not (pdfPage2 Is Nothing) Then
                        pdfPage2 = doc.Pages(2) 'Pages are Zero based, so page 3 has an index of 2, etc
                        'Initializes the bookmark's Destination property
                        Dim pdfDest2 As New PdfDestination(pdfPage2, PdfDestFitMode.EntirePage)
                        If Not (pdfDest2 Is Nothing) Then
                           bookmark2.Destination = pdfDest2
                           doc.Bookmarks.Add(bookmark2)
                        End If
                     End If
                  End If

                  'This will make the bookmarks visible
                  doc.PageMode = PdfPageMode.UseOutlines
                  'Save the Changes to PDF Document
                  doc.Save(asFileName)
eo_support
Posted: Thursday, September 1, 2011 1:02:45 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Fabulous! Thanks for sharing!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.