PDF In-Depth

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

May 30, 1999

Advertisement
Advertisement
 

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")
      AcroApp.Show
    
' 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
           PDBookmark.Destroy
    
      ' Perform a full save - this will remove optimising/linearising. Use &H5 for 

linearised
           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

'////////////////////////////////////////////////////
ErrorHandler:
' All other errors handled here
If IsCriticalError Then
      RemoveBookmarkFromFile = False
      Exit Function
Else
      Resume
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" + 

Str(Err.Number)
           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
Wend
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

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
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.

Features

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.