Convert acrobat 9.0 PDF to Image .PNG Using VBA Code (2 Viewers)

Dvorak Pietrek

New member
Local time
Today, 11:17
Joined
Sep 6, 2025
Messages
10
Hi everyone!

Could someone please help me convert a PDF file to PNG format using Acrobat? I want to open the file with Acrobat 9.0 and then convert or export it to PNG format. If you could provide me with a simple VBA example, I would be very grateful. Please, keep it simple as I'm new to this kind of programming.
 
Hi everyone!

Could someone please help me convert a PDF file to PNG format using Acrobat? I want to open the file with Acrobat 9.0 and then convert or export it to PNG format. If you could provide me with a simple VBA example, I would be very grateful. Please, keep it simple as I'm new to this kind of programming.
What exactly have you tried so far? Do you have a copy of Adobe Acrobat 9.0 already? Have you investigated whether it even has that capability?

VBA is a Microsoft Office product. Does Acrobat 9.0 even use VBA?
 
What exactly have you tried so far? Do you have a copy of Adobe Acrobat 9.0 already? Have you investigated whether it even has that capability?

VBA is a Microsoft Office product. Does Acrobat 9.0 even use VBA?
If I'm asking, it's because I have Acrobat. I have the full version of Acrobat and have used VBA before. Read what I posted and you'll see what I need.
 
You might be able to do it using a shell command to open the file with acrobat and save as a png. I don’t use acrobat so refer to the acrobat documentation

Perhaps ChatGPT can help
 
Well done @xavier.batlle

Did you get that from a Google?, that is what I would do.
Yes, I found it on my Google search first page.
I also read it's possible to achieve it using PPT automation (Not tested):

Code:
Sub SavePDFAsPng(sPathToPDF As String, sPathToPNG As String)
Dim oPres As Presentation
Dim oSh As Shape
' Height/Width are hardcoded here
' You could get trickier and bring the PDF into any presentation
' once to get its proportions, delete it, set the slide size to the same
' proportions, then re-insert the PDF
Dim sngWidth As Single
Dim sngHeight As Single

    sngWidth = 612
    sngHeight = 792
    Set oPres = Presentations.Add
    With oPres
        With .PageSetup ' set it to 8.5x11
            .SlideHeight = sngHeight ' 11in * 72 points per inch
            .SlideWidth = sngWidth
        End With
        .Slides.AddSlide 1, .SlideMaster.CustomLayouts(1)

        With .Slides(1)
        Set oSh = .Shapes.AddOLEObject(0, 0, sngWidth, sngHeight, , sPathToPDF)
        Call .Export(sPathToPNG, "PNG")
        End With
        .Saved = True
        .Close

    End With
End Sub

Sub TestSavePDFAsPng()
    Call SavePDFAsPng("C:\Temp\MyTest.pdf", "C:\Temp\MyTest.PNG")
End Sub
 
This function uses PPT automation in MS ACCESS to convert A PDF to a PNG file. No Acrobat needed. (Tested) :

Code:
'Set a reference to the Microsoft PowerPoint xx.0 Object Library:
'In the VBA editor (press Alt + F11),
'Go to Tools > References...,
'Find and check Microsoft PowerPoint xx.0 Object Library (where xx depends on your Office version)
'Example: Microsoft PowerPoint 16.0 Object Library (Office 365)

Sub SavePDFAsPng(sPathToPDF As String, sPathToPNG As String)
Dim ppApp As PowerPoint.Application
Dim oPres As PowerPoint.Presentation
Dim oSh As Shape
' Height/Width are hardcoded here
' You could get trickier and bring the PDF into any presentation
' once to get its proportions, delete it, set the slide size to the same
' proportions, then re-insert the PDF
Dim sngWidth As Single
Dim sngHeight As Single

    sngWidth = 612
    sngHeight = 792
  
    ' Start PowerPoint
    Set ppApp = New PowerPoint.Application

    Set oPres = ppApp.Presentations.Add
    With oPres
        With .PageSetup ' set it to 8.5x11
            .SlideHeight = sngHeight ' 11in * 72 points per inch
            .SlideWidth = sngWidth
        End With
      
        .Slides.AddSlide 1, .SlideMaster.CustomLayouts(1)

        With .Slides(1)
            Set oSh = .Shapes.AddOLEObject(0, 0, sngWidth, sngHeight, , sPathToPDF)
            Call .Export(sPathToPNG, "PNG")
        End With
        .Saved = True
    End With
  
    Set ppApp = Nothing
 
End Sub

Sub TestSavePDFAsPng()
    Call SavePDFAsPng("C:\Tmp\MyTest.pdf", "C:\Tmp\MyTest.PNG")
End Sub
 
The function original code is from this page:
same page Agnes get it's answer.
agnes.jpg
 
Let's get to the point. I need VBA code to open a file in Acrobat and save it as a .PNG.
If you have Adobe Professional (not Adobe Reader!) you can use this code by Christos Samaras, just change line 8 to match your pdf folder (keep the \*pdf part).

Code:
Option Explicit
Option Private Module

Sub ExportAllPDFs()

    Dim StrFile As String
    
    StrFile = Dir("C:\PdfFolder\*pdf")
    
    Do While Len(StrFile) > 0
        SavePDFAs StrFile, "jpeg"
        StrFile = Dir
    Loop
    
End Sub

Private Sub SavePDFAs(PDFPath As String, FileExtension As String)
    
    '---------------------------------------------------------------------------------------
    'Saves a PDF file as other format using Adobe Professional.
    
    'In order to use the macro you must enable the Acrobat library from VBA editor:
    'Go to Tools -> References -> Adobe Acrobat xx.0 Type Library, where xx depends
    'on your Acrobat Professional version (i.e. 9.0 or 10.0) you have installed to your PC.
    
    'Alternatively you can find it Tools -> References -> Browse and check for the path
    'C:\Program Files\Adobe\Acrobat xx.0\Acrobat\acrobat.tlb
    'where xx is your Acrobat version (i.e. 9.0 or 10.0 etc.).
    
    'By Christos Samaras
    'Date: 30/03/2013
    'http://www.myengineeringworld.net
    '---------------------------------------------------------------------------------------
    
    Dim objAcroApp      As Acrobat.AcroApp
    Dim objAcroAVDoc    As Acrobat.AcroAVDoc
    Dim objAcroPDDoc    As Acrobat.AcroPDDoc
    Dim objJSO          As Object
    Dim boResult        As Boolean
    Dim ExportFormat    As String
    Dim NewFilePath     As String
        
    'Initialize Acrobat by creating App object.
    Set objAcroApp = CreateObject("AcroExch.App")
    
    'Set AVDoc object.
    Set objAcroAVDoc = CreateObject("AcroExch.AVDoc")
    
    'Open the PDF file.
    boResult = objAcroAVDoc.Open(PDFPath, "")
        
    'Set the PDDoc object.
    Set objAcroPDDoc = objAcroAVDoc.GetPDDoc
    
    'Set the JS Object - Java Script Object.
    Set objJSO = objAcroPDDoc.GetJSObject
    
    'Check the type of conversion.
    Select Case LCase(FileExtension)
        Case "eps": ExportFormat = "com.adobe.acrobat.eps"
        Case "html", "htm": ExportFormat = "com.adobe.acrobat.html"
        Case "jpeg", "jpg", "jpe": ExportFormat = "com.adobe.acrobat.jpeg"
        Case "jpf", "jpx", "jp2", "j2k", "j2c", "jpc": ExportFormat = "com.adobe.acrobat.jp2k"
        Case "docx": ExportFormat = "com.adobe.acrobat.docx"
        Case "doc": ExportFormat = "com.adobe.acrobat.doc"
        Case "png": ExportFormat = "com.adobe.acrobat.png"
        Case "ps": ExportFormat = "com.adobe.acrobat.ps"
        Case "rft": ExportFormat = "com.adobe.acrobat.rft"
        Case "xlsx": ExportFormat = "com.adobe.acrobat.xlsx"
        Case "xls": ExportFormat = "com.adobe.acrobat.spreadsheet"
        Case "txt": ExportFormat = "com.adobe.acrobat.accesstext"
        Case "tiff", "tif": ExportFormat = "com.adobe.acrobat.tiff"
        Case "xml": ExportFormat = "com.adobe.acrobat.xml-1-00"
        Case Else: ExportFormat = "Wrong Input"
    End Select
    
    'Check if the format is correct and there are no errors.
    If ExportFormat <> "Wrong Input" And Err.Number = 0 Then
        
        'Format is correct and no errors.
        
        'Set the path of the new file. Note that Adobe instead of xls uses xml files.
        'That's why here the xls extension changes to xml.
        If LCase(FileExtension) <> "xls" Then
            NewFilePath = WorksheetFunction.Substitute(PDFPath, ".pdf", "." & LCase(FileExtension))
        Else
            NewFilePath = WorksheetFunction.Substitute(PDFPath, ".pdf", ".xml")
        End If
        
        'Save PDF file to the new format.
        boResult = objJSO.SaveAs(NewFilePath, ExportFormat)
        
        'Close the PDF file without saving the changes.
        boResult = objAcroAVDoc.Close(True)
        
        'Close the Acrobat application.
        boResult = objAcroApp.Exit
        
    Else
        
        'Something went wrong, so close the PDF file and the application.
        
        'Close the PDF file without saving the changes.
        boResult = objAcroAVDoc.Close(True)
        
        'Close the Acrobat application.
        boResult = objAcroApp.Exit

    End If
        
    'Release the objects.
    Set objAcroPDDoc = Nothing
    Set objAcroAVDoc = Nothing
    Set objAcroApp = Nothing
        
End Sub

WARNING I HAVE NOT YET TESTED IT MYSELF, AND SO CAUTION IS REQUIRED HERE
 
it is easy if you have Debenu (Foxit SDK), just small number of lines:
Code:
Private Sub test()
    Dim lic As String: lic = "xxxxxxxxxxxxxxxxxxxxxxxxx"
    Dim iNumPages As Integer
    Dim sPdf  As String, sOut As String
    Dim qp As DebenuPDFLibrary64AX1811.PDFLibrary
    Set qp = New DebenuPDFLibrary64AX1811.PDFLibrary
    qp.UnlockKey lic
    sPdf = Environ("userprofile") & "\downloads\praise_him.pdf"
    sOut =  Environ("userprofile") & "\documents\image.png"
    qp.LoadFromFile sPdf, ""
    'get number of pages
    iNumPages = qp.PageCount
    
    'RenderDocumentToFile DPI, startPage, endPage, Option=5 (png), Output filename
    qp.RenderDocumentToFile 75, 1, iNumPages, 5, sOut
    
    MsgBox "Look in the Output folder for the image."

End Sub
 
Yes, I found it on my Google search first page.
I also read it's possible to achieve it using PPT automation (Not tested):

Code:
Sub SavePDFAsPng(sPathToPDF As String, sPathToPNG As String)
Dim oPres As Presentation
Dim oSh As Shape
' Height/Width are hardcoded here
' You could get trickier and bring the PDF into any presentation
' once to get its proportions, delete it, set the slide size to the same
' proportions, then re-insert the PDF
Dim sngWidth As Single
Dim sngHeight As Single

    sngWidth = 612
    sngHeight = 792
    Set oPres = Presentations.Add
    With oPres
        With .PageSetup ' set it to 8.5x11
            .SlideHeight = sngHeight ' 11in * 72 points per inch
            .SlideWidth = sngWidth
        End With
        .Slides.AddSlide 1, .SlideMaster.CustomLayouts(1)

        With .Slides(1)
        Set oSh = .Shapes.AddOLEObject(0, 0, sngWidth, sngHeight, , sPathToPDF)
        Call .Export(sPathToPNG, "PNG")
        End With
        .Saved = True
        .Close

    End With
End Sub

Sub TestSavePDFAsPng()
    Call SavePDFAsPng("C:\Temp\MyTest.pdf", "C:\Temp\MyTest.PNG")
End Sub
i will try. Thanks
 

Users who are viewing this thread

Back
Top Bottom