API reference › PDF/A & Conformance
pdfAddJavaScript
Add a document-level named JavaScript entry (the
int32_t __stdcall pdfAddJavaScriptA(PPDF IPDF, const char* Name, const char* Script);
int32_t __stdcall pdfAddJavaScriptW(PPDF IPDF, const char* Name, const wchar_t* Script);
function pdfAddJavaScriptA(const IPDF: PPDF; const Name, Script: PAnsiChar): Integer; stdcall;
function pdfAddJavaScriptW(const IPDF: PPDF; const Name: PAnsiChar; const Script: PWideChar): Integer; stdcall;
Purpose. Add a document-level named JavaScript entry (the /Names /JavaScript name tree — document-open/document-level scripts, consumed by the SDK's own real BESEN-based JS engine, JavaScript, FDF Import, Usage Rights, and Custom Data).
Description. Name is ANSI-only in both variants — there is no Unicode script-name parameter at all (unlike Script, which the W form narrows via AnsiString(WideString(Script)) before storage, and whose Unicode flag is separately recorded — per an inline comment, "JS is virtually always ASCII; narrow the wide script for storage, flag Unicode" — a deliberate, reasoned narrowing choice, not an oversight, since PDF's own /JS string encoding for non-ASCII content requires a UTF-16BE-with-BOM literal string rather than a plain narrow one, and the Unicode flag presumably drives that choice at serialization).
Parameters.
| Parameter | Description |
|---|---|
IPDF | Document handle. |
Name | The script's name-tree key — ANSI-only in both variants. |
Script | The JavaScript source; W form narrowed to ANSI for storage with a separate Unicode flag recorded. |
Return value. A handle/index on success; 0 on failure.
C# (P/Invoke)
public static extern int pdfAddJavaScriptA(IntPtr IPDF, [MarshalAs(UnmanagedType.LPStr)] string Name, [MarshalAs(UnmanagedType.LPStr)] string Script);
public static extern int pdfAddJavaScriptW(IntPtr IPDF, [MarshalAs(UnmanagedType.LPStr)] string Name, [MarshalAs(UnmanagedType.LPWStr)] string Script);
Content Creation
pdfAddJavaScriptA
pdfAddJavaScriptW
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.