[]
        
(Showing Draft Content)

DsPdfConfig

DsPdfJS API v9.1.0


DsPdfJS API / DsPdfConfig

Class: DsPdfConfig

Global configuration for DsPdfJS WebAssembly initialization.

DsPdfJS supports two configuration mechanisms:

  1. Preload configuration via the global DSPDF_CONFIG object. This is useful when configuration must be applied before the library is imported.

  2. Runtime configuration via static properties of DsPdfConfig after the library has been loaded.

The preload configuration is read lazily on first access and is not re-evaluated afterwards.

Example:

// Pre-load configuration
globalThis.DSPDF_CONFIG = {
  wasmUrl: "/assets/DsPdf.wasm",
  licenseKey: "YOUR_LICENSE_KEY"
};

// Post-load configuration
import { DsPdfConfig } from "@mescius/ds-pdf";
DsPdfConfig.verbose = true;

Accessors

verbose

Get Signature

get static verbose(): boolean

Enables detailed console logging during WASM discovery and initialization. Use this to debug loading issues or verify fallback behavior.

Default: false

Example:

DsPdfConfig.verbose = true;
Returns

boolean

Set Signature

set static verbose(v): void

Enables detailed console logging during WASM discovery and initialization. Use this to debug loading issues or verify fallback behavior.

Default: false

Example:

DsPdfConfig.verbose = true;
Parameters
v

boolean

Returns

void


wasmFactory

Get Signature

get static wasmFactory(): any

Custom factory for creating and initializing the DsPdf WASM module.

If defined, this function overrides the default initialization process. Must return a Promise resolving to a fully initialized MainModule.

Useful for:

  • CDN or remote WASM hosting
  • Custom build or environment setup
  • Mocking during unit tests

Example:

DsPdfConfig.wasmFactory = async () => {
  const wasmBinary = await (await fetch("https://cdn.example.com/DsPdf.wasm")).arrayBuffer();
  return createDsPdfModule({ wasmBinary });
};
Returns

any

Set Signature

set static wasmFactory(v): void

Custom factory for creating and initializing the DsPdf WASM module.

If defined, this function overrides the default initialization process. Must return a Promise resolving to a fully initialized MainModule.

Useful for:

  • CDN or remote WASM hosting
  • Custom build or environment setup
  • Mocking during unit tests

Example:

DsPdfConfig.wasmFactory = async () => {
  const wasmBinary = await (await fetch("https://cdn.example.com/DsPdf.wasm")).arrayBuffer();
  return createDsPdfModule({ wasmBinary });
};
Parameters
v

any

Returns

void


wasmUrl

Get Signature

get static wasmUrl(): string | undefined

The URL specifying where to load the DsPdf WebAssembly binary from.

Example:

DsPdfConfig.wasmUrl = "https://cdn.example.com/v2.0/DsPdf.wasm";
Returns

string | undefined

Set Signature

set static wasmUrl(v): void

The URL specifying where to load the DsPdf WebAssembly binary from.

Example:

DsPdfConfig.wasmUrl = "https://cdn.example.com/v2.0/DsPdf.wasm";
Parameters
v

string | undefined

Returns

void

Methods

setLicenseKey()

static setLicenseKey(key?): Promise<void>

Sets or validates the license key. The required key depends on the runtime environment.

Behavior:

  • If key is provided, validates and applies it. Any preloaded key (from DSPDF_CONFIG) is cleared.
  • If key is omitted, validates the preloaded key.
  • If undefined is passed, removes any previously set license key and ignores the preloaded one.

You can optionally preconfigure the license key before the library loads:

// Pre-load configuration (before initializing DsPdf)
globalThis.DSPDF_CONFIG = {
  wasmUrl: "/assets/DsPdf.wasm",
  licenseKey: "YOUR_LICENSE_KEY"
};

Examples:

await setLicenseKey(key);        // validates and applies the provided license key
await setLicenseKey(undefined);  // removes any previously set license key
await setLicenseKey();           // validates the preloaded license key

Parameters

key?

string

License key to validate and apply.

Returns

Promise<void>

Throws

Error if license validation fails.