API referencePDF/A & Conformance

pdfAddJavaScript

Add a document-level named JavaScript entry (the

C
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);
Delphi
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.

ParameterDescription
IPDFDocument handle.
NameThe script's name-tree key — ANSI-only in both variants.
ScriptThe 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)

wrappers/dotnet/LumasPdf.cs
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);
Area
PDF/A & Conformance
Category

Content Creation

Exported names

pdfAddJavaScriptA pdfAddJavaScriptW

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.