uintptr_t __stdcall pdfGetCanvasDC(PPDF IPDF, int32_t CanvasWidth, int32_t CanvasHeight);
int32_t __stdcall pdfGetCanvasDCEx(PPDF IPDF, int32_t CanvasWidth, int32_t CanvasHeight, int32_t ReferenceDC);
function pdfGetCanvasDC(const IPDF: PPDF; CanvasWidth, CanvasHeight: Integer): NativeUInt; stdcall;
function pdfGetCanvasDCEx(const IPDF: PPDF; CanvasWidth, CanvasHeight, ReferenceDC: Integer): Integer; stdcall;
Purpose. Create an in-memory GDI device context sized CanvasWidth x CanvasHeight for the caller to draw into with standard Windows GDI calls, later captured into the PDF via pdfLoadFromCanvasDC/ pdfNewPageFromCanvasDC below.
Description. pdfGetCanvasDC returns the real, usable DC handle (as a NativeUInt/uintptr_t) from CreateCanvasDCH. pdfGetCanvasDCEx does not — despite creating the identical canvas via the same CreateCanvasDCH call, it discards the actual handle and returns only a 1/0 success flag, making the created DC unreachable by any means through this entry point; a caller cannot actually draw into the canvas pdfGetCanvasDCEx creates, since its real HDC value is never surfaced. ReferenceDC is additionally accepted but never passed to CreateCanvasDCH at all.
Parameters.
| Parameter | Description |
|---|---|
IPDF | Document handle. |
CanvasWidth, CanvasHeight | Canvas pixel dimensions. |
ReferenceDC | *(Ex only)* Accepted but never consulted. |
Return value. pdfGetCanvasDC: the real, usable GDI DC handle; 0 if IPDF is invalid. pdfGetCanvasDCEx: 1 on success, 0 on failure — never the actual DC handle, making this variant unusable for its apparent purpose.
Remarks. Use pdfGetCanvasDC, not pdfGetCanvasDCEx, to obtain a drawable canvas.
See also. pdfLoadFromCanvasDC.
C# (P/Invoke)
public static extern UIntPtr pdfGetCanvasDC(IntPtr IPDF, int CanvasWidth, int CanvasHeight);
Getters
pdfGetCanvasDC
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.