PDF In-Depth

IAC - How to remove a single bookmark from a folder of PDFs using VB6

May 30, 1999


If you don't have it you should download the Acrobat SDK first up - and read through the IAC documentation. The demonstration is a simple program that allows you to remove a single bookmark from a folder of PDFs. You will need the VB6 runtimes to use this.

This code sample is posted here for the general benefit of the PDF development community. Attribution and usage guidelines are as noted in the code source; please respect the wishes of the author when using this code.

' How to remove a single bookmark from a folder full of PDFs
Option Explicit
' Author : Karl De Abrew
' Company : Planet PDF
' Date : 20 May, 1999
' URL : http://www.planetpdf.com/
' Version : 1.0
' Description: This is a simple demonstration of how a single
' bookmark can be removed from all the files in a given folder


Function RemoveBookmarkFromFile(strSourceFileName As String) As Boolean
On Error GoTo ErrorHandler
      Dim AcroApp As CAcroApp
      Dim AVDoc As CAcroAVDoc
      Dim PDDoc As CAcroPDDoc
      Dim PDBookmark As CAcroPDBookmark
      Set AcroApp = CreateObject("AcroExch.App")
' Open the PDF
      Set AVDoc = CreateObject("AcroExch.AVDoc")
      If AVDoc.Open(strSourceFileName, "") <> True Then
           RemoveBookmarkFromFile = False
           Exit Function
      End If
      Set PDDoc = AVDoc.GetPDDoc
      Set PDBookmark = CreateObject("AcroExch.PDBookmark")
' Get the bookmark requested
      If (PDBookmark.GetByTitle(PDDoc, m_txtBookmarkToRemove) = True) Then
      ' Kill the bookmark
      ' Perform a full save - this will remove optimising/linearising. Use &H5 for 

           If PDDoc.Save(&H1, strSourceFileName) <> True Then
                  RemoveBookmarkFromFile = False
                  Exit Function
           End If
      End If
' Close the PDF
      AVDoc.Close False
' Cleanup
      Set PDDoc = Nothing
      Set PDBookmark = Nothing
      Set AVDoc = Nothing
      Set AcroApp = Nothing

RemoveBookmarkFromFile = True
Exit Function

' All other errors handled here
If IsCriticalError Then
      RemoveBookmarkFromFile = False
      Exit Function
End If
End Function


Private Function IsCriticalError() As Boolean
      Dim strErrorMessage As String
      Select Case Err.Number ' Evaluate error number.
           Case Else
                  strErrorMessage = "Please contact 

info@planetpdf.com and inform them that" & Chr$(13) & _
                  "the error message reported by the operating system 

was " & Chr$(13) & _
                  Chr$(34) + Trim(Str(Err.Number)) & " " & 

Err.Description + Chr$(34)
                  MsgBox strErrorMessage, , "Conversion error" + 

           IsCriticalError = True
           Exit Function
      End Select
      IsCriticalError = False
End Function


Private Sub btnRemoveBookmarks_Click()
Dim strFile As String
Dim strFolder As String

' Set the source folder
strFolder = m_txtSourceFolder

' Grab the first file to process
strFile = Dir(strFolder + "*.pdf")

' Loop through all word files
While strFile <> ""
      ' Attempt to convert the file to PDF
      If (RemoveBookmarkFromFile(strFolder + strFile) = False) Then
           ' Hmmm, looks like something went wrong - let's prompt the user to 

see if they wish to quit
           If (MsgBox("There has been a problem with processing the file " + 

strFile + Chr(13) + "Do you wish to exit", vbYesNo) = vbYes) Then
           ' Finish up - let's get out of here
                  Exit Sub
           End If
      End If
      ' Grab the next file
          strFile = Dir
End Sub

PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Five visions of a PDF Day

In the world of PDFs or as we like to say Planet (of) PDF, a year isn't a real PDF year without an intense few days of industry knowledge sharing.

May 15, 2018
Platinum Sponsor

Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.


Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.