Stateful, Promise-like compatibility chain.
The worker caches one PdfDocument until its source or options change.
Raster-only html2pdf.js stages fail explicitly rather than silently changing
the native PDF model.
Signature
export declare class CompatWorker implements PromiseLike<PdfDocument>Methods
from()
Sets the HTML source; canvas and image input stages are unsupported.
from(source: HtmlSource, type?: "string" | "element" | "canvas" | "img"): this;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
source | HtmlSource | Yes | None | HTML string, mounted element, or ref-shaped value to render. |
type | "string" | "element" | "canvas" | "img" | No | None | Requested input or output type. |
Returns
thisset()
Shallow-merges supported compatibility options and invalidates cached output.
set(options: Html2PdfOptions): this;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
options | Html2PdfOptions | Yes | None | Options for this operation. |
Returns
thisusing()
Alias for set, retained for html2pdf.js chain compatibility.
using(options: Html2PdfOptions): this;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
options | Html2PdfOptions | Yes | None | Options for this operation. |
Returns
thisto()
Advances to PDF output for pdf or container targets.
to(target: "pdf" | "container" | "canvas" | "img"): this;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
target | "pdf" | "container" | "canvas" | "img" | Yes | None | Target stage or preview element. |
Returns
thistoPdf()
Schedules PDF rendering while preserving the fluent chain.
toPdf(): this;Parameters
This API does not accept parameters.
Returns
thistoContainer()
Compatibility no-op; no intermediate snapshot container is exposed.
toContainer(): this;Parameters
This API does not accept parameters.
Returns
thistoCanvas()
Always throws because full-page canvas output is intentionally unsupported.
toCanvas(): never;Parameters
This API does not accept parameters.
Returns
nevertoImg()
Always throws because raster image output is intentionally unsupported.
toImg(): never;Parameters
This API does not accept parameters.
Returns
neversave()
Schedules a browser download using the explicit or configured filename.
save(filename?: string): this;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
filename | string | No | this.options.filename ?? "file.pdf" | Download filename. |
Returns
thissaveAs()
Alias for save.
saveAs(filename?: string): this;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
filename | string | No | None | Download filename. |
Returns
thisoutputPdf()
Resolves PDF output in a compatibility encoding.
outputPdf(type?: "blob"): Promise<Blob>;
outputPdf(type: "arraybuffer"): Promise<ArrayBuffer>;
outputPdf(type: StringPdfOutputType): Promise<string>;
outputPdf(type: PdfOutputType): Promise<string | Blob | ArrayBuffer>;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
type | PdfOutputType | No | "blob" | Requested input or output type. |
Returns
Promise<string \| Blob \| ArrayBuffer>output()
Routes generic html2pdf.js output requests to PDF output.
output(type?: "blob", options?: unknown, source?: "pdf"): Promise<Blob>;
output(type: "arraybuffer", options?: unknown, source?: "pdf"): Promise<ArrayBuffer>;
output(type: StringPdfOutputType, options?: unknown, source?: "pdf"): Promise<string>;
output(type: PdfOutputType | undefined, options: unknown, source: "img"): Promise<never>;
output(type?: PdfOutputType, options?: unknown, source?: "pdf" | "img"): Promise<string | Blob | ArrayBuffer>;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
type | PdfOutputType | No | None | Requested input or output type. |
_options | unknown | No | None | Options for this operation. |
source | "pdf" | "img" | No | "pdf" | HTML string, mounted element, or ref-shaped value to render. |
Returns
Promise<string \| Blob \| ArrayBuffer>export()
Alias for output.
export(type?: "blob", options?: unknown, source?: "pdf"): Promise<Blob>;
export(type: "arraybuffer", options?: unknown, source?: "pdf"): Promise<ArrayBuffer>;
export(type: StringPdfOutputType, options?: unknown, source?: "pdf"): Promise<string>;
export(type: PdfOutputType | undefined, options: unknown, source: "img"): Promise<never>;
export(type?: PdfOutputType, options?: unknown, source?: "pdf" | "img"): Promise<string | Blob | ArrayBuffer>;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
type | PdfOutputType | No | None | Requested input or output type. |
options | unknown | No | None | Options for this operation. |
source | "pdf" | "img" | No | None | HTML string, mounted element, or ref-shaped value to render. |
Returns
Promise<string \| Blob \| ArrayBuffer>outputImg()
Returns a rejected promise because raster image output is unsupported.
outputImg(): Promise<never>;Parameters
This API does not accept parameters.
Returns
Promise<never>get()
Resolves the cached PDF for pdf, or a configured compatibility option for
any other key, then optionally invokes the legacy callback.
get(key: string, callback?: (value: unknown) => void): Promise<unknown>;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
key | string | Yes | None | Compatibility option key. |
callback | (value: unknown) => void | No | None | Optional callback invoked with the resolved value. |
Returns
Promise<unknown>error()
Interrupts a chain by throwing the supplied message as an Error.
error(message: string): never;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
message | string | Yes | None | Human-readable error message. |
Returns
neverthen()
Makes the chain awaitable and resolves it to the cached PdfDocument.
then<TResult1 = PdfDocument, TResult2 = never>(onFulfilled?: ((value: PdfDocument) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
onFulfilled | ((value: PdfDocument) => TResult1 | PromiseLike<TResult1>) | null | No | None | Value passed to this API. |
onRejected | ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | No | None | Value passed to this API. |
Returns
Promise<TResult1 \| TResult2>thenCore()
Compatibility alias for then.
thenCore<TResult1 = PdfDocument, TResult2 = never>(onFulfilled?: ((value: PdfDocument) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
onFulfilled | ((value: PdfDocument) => TResult1 | PromiseLike<TResult1>) | null | No | None | Value passed to this API. |
onRejected | ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | No | None | Value passed to this API. |
Returns
Promise<TResult1 \| TResult2>thenExternal()
Compatibility alias for then.
thenExternal<TResult1 = PdfDocument, TResult2 = never>(onFulfilled?: ((value: PdfDocument) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
onFulfilled | ((value: PdfDocument) => TResult1 | PromiseLike<TResult1>) | null | No | None | Value passed to this API. |
onRejected | ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | No | None | Value passed to this API. |
Returns
Promise<TResult1 \| TResult2>run()
Compatibility alias for then.
run<TResult1 = PdfDocument, TResult2 = never>(onFulfilled?: ((value: PdfDocument) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
onFulfilled | ((value: PdfDocument) => TResult1 | PromiseLike<TResult1>) | null | No | None | Value passed to this API. |
onRejected | ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | No | None | Value passed to this API. |
Returns
Promise<TResult1 \| TResult2>catch()
Handles a failed chain while preserving PdfDocument as the success type.
catch<TResult = never>(onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<PdfDocument | TResult>;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
onRejected | ((reason: unknown) => TResult | PromiseLike<TResult>) | null | No | None | Value passed to this API. |
Returns
Promise<PdfDocument \| TResult>catchExternal()
Compatibility alias for catch.
catchExternal<TResult = never>(onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<PdfDocument | TResult>;Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
onRejected | ((reason: unknown) => TResult | PromiseLike<TResult>) | null | No | None | Value passed to this API. |
Returns
Promise<PdfDocument \| TResult>