API referenceImages

pdfSaveImageToFile

Write the currently selected image's (via pdfSelectImage,

C
int32_t __stdcall pdfSaveImageToFileA(PPDF IPDF, const char* FileName);
int32_t __stdcall pdfSaveImageToFileW(PPDF IPDF, const wchar_t* FileName);
const char* __stdcall pdfSaveImageToString(PPDF IPDF);
Delphi
function pdfSaveImageToFileA(const IPDF: PPDF; FileName: PAnsiChar): Integer; stdcall;
function pdfSaveImageToFileW(const IPDF: PPDF; FileName: PWideChar): Integer; stdcall;
function pdfSaveImageToString(const IPDF: PPDF): PAnsiChar; stdcall;

Purpose. Write the currently selected image's (via pdfSelectImage, Image Objects and Introspection) raw bytes to a file, or return them as an in-memory buffer.

Description. Both resolve the target image through SelectedImageH - 1 — not FImageCount - 1 like pdfGetImageBuffer above. pdfSaveImageToFile writes the image's original encoded bytes verbatim to FileName. pdfSaveImageToString copies the same bytes into a document-owned transient buffer (GapRetA, overwritten on next use) and returns a pointer to it. Both fail if no image is currently selected (pdfSelectImage was never called, or was cleared with ImageID=0).

Parameters.

ParameterDescription
IPDFDocument handle.
FileName*(SaveToFile only)* Output file path.

Return value. pdfSaveImageToFile: 1 on success, 0 if no image is selected or the write failed. pdfSaveImageToString: pointer to the byte buffer, or nil if no image is selected.

See also. pdfSelectImage, pdfGetImageBuffer (the last-inserted-image counterpart — a different target).

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern int pdfSaveImageToFileW(IntPtr IPDF, IntPtr FileName);
public static extern int pdfSaveImageToFile(IntPtr IPDF, IntPtr FileName);
public static extern int pdfSaveImageToFileA(IntPtr IPDF, IntPtr FileName);
Area
Images
Category

Core

Exported names

pdfSaveImageToFileW pdfSaveImageToFile pdfSaveImageToFileA

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.