API referenceImages

pdfGetImageCount

Count the number of embedded images inside an arbitrary

C
int32_t __stdcall pdfGetImageCountA(PPDF IPDF, const char* FileName);
int32_t __stdcall pdfGetImageCountW(PPDF IPDF, const wchar_t* FileName);
int32_t __stdcall pdfGetImageCountEx(PPDF IPDF, void* Buffer, uint32_t BufSize);
Delphi
function pdfGetImageCountA(const IPDF: PPDF; const FileName: PAnsiChar): Integer; stdcall;
function pdfGetImageCountW(const IPDF: PPDF; const FileName: PWideChar): Integer; stdcall;
function pdfGetImageCountEx(const IPDF: PPDF; Buffer: Pointer; BufSize: Cardinal): Integer; stdcall;

Purpose. Count the number of embedded images inside an arbitrary external PDF file or buffer — unrelated to the currently open document's own image list (see pdfGetImageObjCount above for that).

Description. IPDF is accepted by all three variants but never consulted — this is a standalone file/buffer scanning utility (ApiCountImages) that works even with a null or invalid document handle; it opens/parses FileName (or Buffer/BufSize for Ex) as its own, independent PDF and counts image XObjects found within, entirely unconnected to IPDF's own document state. A non-existent file (A/W) or empty/null buffer (Ex) returns 0 without raising an error through IPDF's error-log mechanism (since IPDF is never touched).

Parameters.

ParameterDescription
IPDFAccepted but never consulted — the scan is entirely independent of this handle's document state.
FileName*(A/W)* Path to an external PDF file to scan.
Buffer, BufSize*(Ex)* In-memory PDF bytes to scan.

Return value. The number of image XObjects found in the target file/buffer; 0 if it doesn't exist/parse or contains none.

See also. pdfGetImageObjCount (the unrelated, current-document counterpart).

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern int pdfGetImageCount(IntPtr IPDF, [MarshalAs(UnmanagedType.LPStr)] string FileName);
public static extern int pdfGetImageCountA(IntPtr IPDF, [MarshalAs(UnmanagedType.LPStr)] string FileName);
public static extern int pdfGetImageCountW(IntPtr IPDF, [MarshalAs(UnmanagedType.LPWStr)] string FileName);
Area
Images
Category

Getters

Exported names

pdfGetImageCount pdfGetImageCountA pdfGetImageCountW

String variants

The …A form takes UTF-8, …W takes UTF-16; a bare name aliases the ANSI form.

See working code

Worked examples — complete programs in ten languages.