Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB and pdf

Status
Not open for further replies.

Warnie

Technical User
Joined
Oct 4, 2001
Messages
52
Location
US
can pdf files be referenced thru Visual basic ??
 
'this is the code for the class I use to get info about a PDF file.

You'll have to set a reference to Adobe Acrobat 4.0 Type Library


Code:
Option Explicit

Enum PdfPageModes
    PDDontCare
    PDUseNone
    PDUseThumbs
    PDUseBookmarks
    PDFullScreen
End Enum

Dim msProblem   As String
Dim msFileName  As String
Dim mnNumPages  As Long
Dim mnPageMode  As PdfPageModes
Dim msTitle     As String
Dim msSubject   As String
Dim msAuthor    As String
Dim msKeywords  As String
Dim msCreator   As String
Dim msProducer  As String

Public Property Get FileName() As String
    FileName = msFileName
End Property

Public Property Get NumPages() As Long
    NumPages = mnNumPages
End Property

Public Property Get PageMode() As PdfPageModes
    PageMode = mnPageMode
End Property

Public Property Get Title() As String
    Title = msTitle
End Property

Public Property Get Subject() As String
    Subject = msSubject
End Property

Public Property Get Author() As String
    Author = msAuthor
End Property

Public Property Get Keywords() As String
    Keywords = msKeywords
End Property

Public Property Get Creator() As String
    Creator = msCreator
End Property

Public Property Get Producer() As String
    Producer = msProducer
End Property

Public Property Get Problem() As String
    Problem = msProblem
End Property

Public Function GetInfo(ByVal sFile As String) As Boolean
    Dim oDoc As Acrobat.CAcroPDDoc
    
    On Error GoTo ERRORHANDLER
    GetInfo = False
    
    If Dir(sFile) = "" Then
        msProblem = "Cannot find " & sFile
        Exit Function
    End If
    
    Set oDoc = CreateObject("AcroExch.PDDoc")
    With oDoc
        If .Open(sFile) Then
            msFileName = .GetFileName
            mnNumPages = CLng(.GetNumPages)
            mnPageMode = .GetPageMode
            msTitle = .GetInfo("Title")
            msSubject = .GetInfo("Subject")
            msAuthor = .GetInfo("Author")
            msKeywords = .GetInfo("Keywords")
            msCreator = .GetInfo("Creator")
            msProducer = .GetInfo("Producer")
            .Close
            GetInfo = True
        Else
            msProblem = "Cannot open " & sFile
        End If
    End With
    Set oDoc = Nothing
    Exit Function
    
ERRORHANDLER:
    msProblem = "Error reading file " & sFile & " --> " & Err.Description
End Function
 
From another small program I did when messing about with PDF files...

Code:
Private Sub mnuCreateThumbs_Click()
    Dim oDoc As Acrobat.CAcroPDDoc
    Dim sFile As String
    Dim nSave As Acrobat.PDSaveFlags
    Dim nPages As Long
    
    nSave = PDSaveFull
    
    sFile = GetFile("E:\Test")
    
    If sFile = "" Then Exit Sub
    lstActions.Clear
    Set oDoc = CreateObject("AcroExch.PDDoc")
    With oDoc
        If .Open(sFile) Then
            lstActions.AddItem "Creating thumbnails of " & sFile
            nPages = .GetNumPages
            If .CreateThumbs(0, nPages - 1) Then
                If .Save(nSave, sFile) Then
                    lstActions.AddItem "Created thumbnails of pages 1 to " & nPages
                Else
                    lstActions.AddItem "Cannot save " & sFile
                End If
            Else
                lstActions.AddItem "Cannot create thumbnails of pages 1 to " & nPages
            End If
            .Close
        Else
            lstActions.AddItem "Cannot open " & sFile, vbExclamation
        End If
    End With
    Set oDoc = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top