I am trying to extract images from a PDF in Excel VBA. I am able to extract all of the text page by page with no problem (code below). I have searched for sample code or an explanation of how to extract images but the only sample code I found did not work. Does anybody know how to extract images one by one from a PDF and save each image to a folder (which would be specified in the VBA code) using just VBA (without any third party software)? I would appreciate any information.
VBA Code:
Sub GetText()
Dim aApp As Acrobat.AcroApp
Dim av_doc As AcroAVDoc
Dim pdf_doc As AcroPDDoc
Dim sel_text As AcroPDTextSelect
Dim X as Variant
Dim Y As Long
Dim pageNumber, pageContent, content
Set aApp = CreateObject("AcroExch.App") Set av_doc = CreateObject("AcroExch.AVDoc")
If av_doc.Open("C:\VBA\PDF\Pages.pdf", vbNull) <> True Then Stop
Set av_doc = aApp.GetActiveDoc
Set pdf_doc = av_doc.GetPDDoc
' Iterate through the document page by page
For X = 0 To pdf_doc.GetNumPages - 1
Set pageNumber = pdf_doc.AcquirePage(X)
Set pageContent = CreateObject("AcroExch.Hilitelist")
On Error Resume Next
If pageContent.Add(0, 9000) <> True Then Stop
Set sel_text = pageNumber.CreatePageHilite(pageContent)
On Error GoTo 0
' Iterate through page word by word
For Y = 0 To sel_text.GetNumText - 1
' Display each word in a cell on spreadsheet
Cells(Y + 1, X + 1) = sel_text.GetText(Y)
Next Y
Next X
'Close and Release
av_doc.Close False
aApp.Exit
Set sel_text = Nothing
Set pdf_doc = Nothing
Set av_doc = Nothing
Set pageNumber = Nothing
End Sub