API referenceDigital Signatures

pdfFinishSignature

The external/deferred signing pair: prepare the

C
BOOL32 __stdcall pdfCloseAndSignFileExt(PPDF IPDF, TPDFSigParms* SigParms);
BOOL32 __stdcall pdfFinishSignature(PPDF IPDF, void* PKCS7Obj, uint32_t Length);
Delphi
function pdfCloseAndSignFileExt(const IPDF: PPDF; var SigParms: TPDFSigParms): LongBool; stdcall;
function pdfFinishSignature(const IPDF: PPDF; const PKCS7Obj: Pointer; Length: Cardinal): LongBool; stdcall;

Purpose. The external/deferred signing pair: prepare the document with a /ByteRange placeholder and hand the to-be-signed bytes back to the caller (e.g. for an HSM or remote signing service to compute the PKCS#7 externally, without this SDK ever touching a private key), then complete the write once the caller supplies the finished signature bytes.

Description. pdfCloseAndSignFileExt calls PrepareDeferredSign with the field's page/rect/visibility/name/reason/location (all narrowed from SigParms' WideString fields to RawByteString via AnsiString(WideString(...)) — the usual codepage-narrowing pattern) — this builds the signature field if needed, serializes with an empty /Contents placeholder, computes /ByteRange, and stashes the to-be-signed bytes (retrievable via pdfGetBuffer, V17) plus the patched-but-unsigned document internally (FDeferData) — no private key is touched by this SDK at all in this path. pdfFinishSignature takes the caller's already-computed PKCS#7 bytes, hex-encodes them into the reserved /Contents gap (same zero-pad/overflow-check logic as CloseAndSign), and writes the final signed file — setting the internal sign-process state to "finished" (consumed by pdfGetSignProcessResult, below).

Parameters.

ParameterDescription
IPDFDocument handle.
SigParmsField placement/name/reason/location (Unicode, narrowed to ANSI internally).
PKCS7Obj, Length*(FinishSignature only)* The externally-computed detached PKCS#7/CMS signature bytes.

Return value. True on success; False if no deferred-sign process is active (pdfFinishSignature called without a prior pdfCloseAndSignFileExt), the supplied signature is too large for the reserved placeholder, or the file write fails.

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
[return: MarshalAs(UnmanagedType.Bool)]
Area
Digital Signatures
Category

Core

Exported names

pdfFinishSignature

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.