Copy

CompatWorker

Stateful, Promise-like compatibility chain.

ON_THIS_PAGE
  1. Signature
  2. Methods
  3. from()
  4. Parameters
  5. Returns
  6. set()
  7. Parameters
  8. Returns
  9. using()
  10. Parameters
  11. Returns
  12. to()
  13. Parameters
  14. Returns
  15. toPdf()
  16. Parameters
  17. Returns
  18. toContainer()
  19. Parameters
  20. Returns
  21. toCanvas()
  22. Parameters
  23. Returns
  24. toImg()
  25. Parameters
  26. Returns
  27. save()
  28. Parameters
  29. Returns
  30. saveAs()
  31. Parameters
  32. Returns
  33. outputPdf()
  34. Parameters
  35. Returns
  36. output()
  37. Parameters
  38. Returns
  39. export()
  40. Parameters
  41. Returns
  42. outputImg()
  43. Parameters
  44. Returns
  45. get()
  46. Parameters
  47. Returns
  48. error()
  49. Parameters
  50. Returns
  51. then()
  52. Parameters
  53. Returns
  54. thenCore()
  55. Parameters
  56. Returns
  57. thenExternal()
  58. Parameters
  59. Returns
  60. run()
  61. Parameters
  62. Returns
  63. catch()
  64. Parameters
  65. Returns
  66. catchExternal()
  67. Parameters
  68. Returns

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>
SOURCE:20

Methods

from()

Sets the HTML source; canvas and image input stages are unsupported.

from(source: HtmlSource, type?: "string" | "element" | "canvas" | "img"): this;

Parameters

ParameterTypeRequiredDefaultDescription
sourceHtmlSourceYesNoneHTML string, mounted element, or ref-shaped value to render.
type"string" | "element" | "canvas" | "img"NoNoneRequested input or output type.

Returns

this
SOURCE:27

set()

Shallow-merges supported compatibility options and invalidates cached output.

set(options: Html2PdfOptions): this;

Parameters

ParameterTypeRequiredDefaultDescription
optionsHtml2PdfOptionsYesNoneOptions for this operation.

Returns

this
SOURCE:37

using()

Alias for set, retained for html2pdf.js chain compatibility.

using(options: Html2PdfOptions): this;

Parameters

ParameterTypeRequiredDefaultDescription
optionsHtml2PdfOptionsYesNoneOptions for this operation.

Returns

this
SOURCE:50

to()

Advances to PDF output for pdf or container targets.

to(target: "pdf" | "container" | "canvas" | "img"): this;

Parameters

ParameterTypeRequiredDefaultDescription
target"pdf" | "container" | "canvas" | "img"YesNoneTarget stage or preview element.

Returns

this
SOURCE:61

toPdf()

Schedules PDF rendering while preserving the fluent chain.

toPdf(): this;

Parameters

This API does not accept parameters.

Returns

this
SOURCE:67

toContainer()

Compatibility no-op; no intermediate snapshot container is exposed.

toContainer(): this;

Parameters

This API does not accept parameters.

Returns

this
SOURCE:73

toCanvas()

Always throws because full-page canvas output is intentionally unsupported.

toCanvas(): never;

Parameters

This API does not accept parameters.

Returns

never
SOURCE:78

toImg()

Always throws because raster image output is intentionally unsupported.

toImg(): never;

Parameters

This API does not accept parameters.

Returns

never
SOURCE:83

save()

Schedules a browser download using the explicit or configured filename.

save(filename?: string): this;

Parameters

ParameterTypeRequiredDefaultDescription
filenamestringNothis.options.filename ?? "file.pdf"Download filename.

Returns

this
SOURCE:88

saveAs()

Alias for save.

saveAs(filename?: string): this;

Parameters

ParameterTypeRequiredDefaultDescription
filenamestringNoNoneDownload filename.

Returns

this
SOURCE:94

outputPdf()

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

ParameterTypeRequiredDefaultDescription
typePdfOutputTypeNo"blob"Requested input or output type.

Returns

Promise<string \| Blob \| ArrayBuffer>
SOURCE:109

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

ParameterTypeRequiredDefaultDescription
typePdfOutputTypeNoNoneRequested input or output type.
_optionsunknownNoNoneOptions for this operation.
source"pdf" | "img"No"pdf"HTML string, mounted element, or ref-shaped value to render.

Returns

Promise<string \| Blob \| ArrayBuffer>
SOURCE:127

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

ParameterTypeRequiredDefaultDescription
typePdfOutputTypeNoNoneRequested input or output type.
optionsunknownNoNoneOptions for this operation.
source"pdf" | "img"NoNoneHTML string, mounted element, or ref-shaped value to render.

Returns

Promise<string \| Blob \| ArrayBuffer>
SOURCE:138

outputImg()

Returns a rejected promise because raster image output is unsupported.

outputImg(): Promise<never>;

Parameters

This API does not accept parameters.

Returns

Promise<never>
SOURCE:143

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

ParameterTypeRequiredDefaultDescription
keystringYesNoneCompatibility option key.
callback(value: unknown) => voidNoNoneOptional callback invoked with the resolved value.

Returns

Promise<unknown>
SOURCE:151

error()

Interrupts a chain by throwing the supplied message as an Error.

error(message: string): never;

Parameters

ParameterTypeRequiredDefaultDescription
messagestringYesNoneHuman-readable error message.

Returns

never
SOURCE:160

then()

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

ParameterTypeRequiredDefaultDescription
onFulfilled((value: PdfDocument) => TResult1 | PromiseLike<TResult1>) | nullNoNoneValue passed to this API.
onRejected((reason: unknown) => TResult2 | PromiseLike<TResult2>) | nullNoNoneValue passed to this API.

Returns

Promise<TResult1 \| TResult2>
SOURCE:165

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

ParameterTypeRequiredDefaultDescription
onFulfilled((value: PdfDocument) => TResult1 | PromiseLike<TResult1>) | nullNoNoneValue passed to this API.
onRejected((reason: unknown) => TResult2 | PromiseLike<TResult2>) | nullNoNoneValue passed to this API.

Returns

Promise<TResult1 \| TResult2>
SOURCE:173

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

ParameterTypeRequiredDefaultDescription
onFulfilled((value: PdfDocument) => TResult1 | PromiseLike<TResult1>) | nullNoNoneValue passed to this API.
onRejected((reason: unknown) => TResult2 | PromiseLike<TResult2>) | nullNoNoneValue passed to this API.

Returns

Promise<TResult1 \| TResult2>
SOURCE:181

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

ParameterTypeRequiredDefaultDescription
onFulfilled((value: PdfDocument) => TResult1 | PromiseLike<TResult1>) | nullNoNoneValue passed to this API.
onRejected((reason: unknown) => TResult2 | PromiseLike<TResult2>) | nullNoNoneValue passed to this API.

Returns

Promise<TResult1 \| TResult2>
SOURCE:189

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

ParameterTypeRequiredDefaultDescription
onRejected((reason: unknown) => TResult | PromiseLike<TResult>) | nullNoNoneValue passed to this API.

Returns

Promise<PdfDocument \| TResult>
SOURCE:197

catchExternal()

Compatibility alias for catch.

catchExternal<TResult = never>(onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<PdfDocument | TResult>;

Parameters

ParameterTypeRequiredDefaultDescription
onRejected((reason: unknown) => TResult | PromiseLike<TResult>) | nullNoNoneValue passed to this API.

Returns

Promise<PdfDocument \| TResult>
SOURCE:202
ON_THIS_PAGE
  1. Signature
  2. Methods
  3. from()
  4. Parameters
  5. Returns
  6. set()
  7. Parameters
  8. Returns
  9. using()
  10. Parameters
  11. Returns
  12. to()
  13. Parameters
  14. Returns
  15. toPdf()
  16. Parameters
  17. Returns
  18. toContainer()
  19. Parameters
  20. Returns
  21. toCanvas()
  22. Parameters
  23. Returns
  24. toImg()
  25. Parameters
  26. Returns
  27. save()
  28. Parameters
  29. Returns
  30. saveAs()
  31. Parameters
  32. Returns
  33. outputPdf()
  34. Parameters
  35. Returns
  36. output()
  37. Parameters
  38. Returns
  39. export()
  40. Parameters
  41. Returns
  42. outputImg()
  43. Parameters
  44. Returns
  45. get()
  46. Parameters
  47. Returns
  48. error()
  49. Parameters
  50. Returns
  51. then()
  52. Parameters
  53. Returns
  54. thenCore()
  55. Parameters
  56. Returns
  57. thenExternal()
  58. Parameters
  59. Returns
  60. run()
  61. Parameters
  62. Returns
  63. catch()
  64. Parameters
  65. Returns
  66. catchExternal()
  67. Parameters
  68. Returns
html2realpdf documentationCopyright © Imggion
DOCUMENTATION_TREE