3 Years
Discussion Span
Last Post by LozeeS

NOTE: Make a Reference to Adobe Acrobat X.x Type Library
NOTE2: This is untested code since you need Acrobat Pro (AP) to automate Acrobat (or so I have read) and I don't have it.

If you have AP the following code should get you close to what you need.
It is possible that AP will name their objects a bit differently.

Option Explicit      '<<< first line of module/form
' Set Reference to Adobe Acrobat X.x Type Library

    Private Sub Command1_Click()
            Dim MyAcro As New AcroApp
            Dim MyPDF  As New AcroPDDoc
            Dim MyPage As AcroPDPage
            Dim MyPt As Acrobat.AcroPoint
            Dim MyRect As AcroRect
            Dim MyData As DataObject
            Dim strPathString As String
            Dim MyPath As String
            Dim SaveToPath As String

           MyPath = "C:\APath\AFile.PDF"
           mysavepath = "C:\MyPDFImagesPath"

            ' open the PDF
            MyPDF.Open (MyPath)
            Set MyPage = MyPDF.AcquirePage(0)

            ' Convert Point to Twips for document
            Set MyPt = New AcroPoint

            'Define the rectangle that contains the PDF form
            Set MyRect = New Acrobat.AcroRect

                MyRect.Top = 0

                MyRect.Left = 0

                MyRect.Right = MyPt.x

                MyRect.bottom = MyPt.y

               ' Copy the PDF image to the clip board
            Call MyPage.CopyToClipboard(MyRect, MyRect.Left, MyRect.Top, 100)

            ' Capture image from clip board to data object
            Set MyData = Clipboard.GetData(vbCFBitmap)

            'Save the data object
            SavePicture MyData, mysavepath

            ' Clean up

            Set MyAcro = Nothing
            Set MyPDF = Nothing
            Set MyPage = Nothing
            Set MyPt = Nothing
            Set MyRect = Nothing
            Set MyData = Nothing

    End Sub

Edited by Klahr_R


Yes, PDF files can be converted to images! But it's not a native capability of VB6. You'll need to obtain a third-party component to perform the conversion.

The alternative is to write your own software to decode and render PDF documents, not a trivial task. If you're prepared to spend the time and effort though, Adobe's PDF reference might be a good place to start:

The example below demonstrates how to render documents using VB6 with a component (the easy option):

Set doc = CreateObject("ABCpdf9.Doc")
doc.Read "example.pdf"
For i = 1 To doc.PageCount
  doc.PageNumber = i    
  doc.Rendering.Save "example-" & i & ".png"

The code makes use of ABCpdf.NET Professional, although any component which provides a COM interface and similar features should work just as well. Support for VB6 can be found in the legacy documentation for ABCpdf ASP, usually included with the installation package.


Like AffineMesh94464 mentioned, there are third-party components that are quite capable in regards to reading PDFs and saving images. Unfortunately, most of them stopped supporting vb6 in their new versions, but I found a post that suggests at least one of them still does: http://support.leadtools.com/CS/forums/41356/ShowPost.aspx
I haven't used VB6 recently so I did not actually try this post and it does talk about loading an image, but they claim the same code can be used for PDF files. Hope this helps.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.