Extract Images from a PDF using VBA

CraigHK

New Member
Joined
Feb 15, 2020
Messages
1
Office Version
  1. 2013
Platform
  1. Windows
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
 

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,880
Office Version
  1. 365
Platform
  1. Windows
Cross posted Extract Images from a PDF using VBA

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 

chnoir

New Member
Joined
Oct 29, 2020
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I have the same problem that you had in february, did you find the coding to extract the images and can you help me on this matter. I am belgian and not profesional on this matther
Thank you in advance
Christian
 

Watch MrExcel Video

Forum statistics

Threads
1,122,437
Messages
5,596,118
Members
414,043
Latest member
thomas Stein

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top