UNPKG

node-weasyprint

Version:

A NodeJS wrapper for [WeasyPrint](https://doc.courtbouillon.org/weasyprint/stable/index.html)

120 lines (119 loc) 4.39 kB
/// <reference types="node" /> /// <reference types="node" /> import { ChildProcess } from "child_process"; type Size = "images" | "fonts" | "all" | "none"; type WeasyPrintOptions = { /** * Force the input character encoding (e.g. `encoding: "utf-8"`). */ encoding?: string; /** * Filename or URL of a user cascading stylesheet (see Stylesheet Origins) to add to the document (e.g. `stylesheet: "print.css"`). Multiple stylesheets are allowed by passing an array. */ stylesheet?: string | string[]; /** * Set the media type to use for @media. Defaults to print. */ mediaType?: string; /** * Set the base for relative URLs in the HTML input. Defaults to the input’s own URL, or the current directory for stdin. */ baseUrl?: string; /** * Adds an attachment to the document. The attachment is included in the PDF output. This option can be used multiple times by passing an array. */ attachment?: string | string[]; /** * PDF file identifier, used to check whether two different files are two different versions of the same original document. */ pdfIdentifier?: string; /** * PDF variant to generate (e.g. `pdfVariant: "pdf/a-3b"`). */ pdfVariant?: string; /** * PDF version number (default is 1.7). */ pdfVersion?: string; /** * Include custom HTML meta tags in PDF metadata. */ customMetadata?: boolean; /** * Follow HTML presentational hints. */ presentationalHints?: boolean; /** * Optimize the size of generated documents. Supported types are images, fonts, all and none. This option can be used multiple times by passing an array, all adds all allowed values, none removes all previously set values. */ optimizeSize?: Size | Size[]; /** * Show warnings and information messages. */ verbose?: boolean; /** * Show debugging messages. */ debug?: boolean; /** * Hide logging messages. */ quiet?: boolean; /** * Show the version number. Other options and arguments are ignored. */ version?: boolean; /** * Show the command-line usage. Other options and arguments are ignored. */ help?: boolean; }; export type WeasyPrintFileOutputOptions = { /** The command to use, if `weasyprint` is not in your path, or if you want to use another command. */ command?: string; /** A filename to write to. */ output: string; /** Nothing to buffer—it’s writing to a file. */ buffer?: undefined; } & WeasyPrintOptions; export type WeasyPrintStreamOptions = { /** The command to use, if `weasyprint` is not in your path, or if you want to use another command. */ command?: string; /** Don’t include an output, so it writes to stdout. */ output?: undefined; /** Return the actual stream. */ buffer?: undefined; } & WeasyPrintOptions; export type WeasyPrintBufferOptions = { /** The command to use, if `weasyprint` is not in your path, or if you want to use another command. */ command?: string; /** Don’t include an output, so it writes to stdout. */ output?: undefined; /** Write to a buffer and return the buffer */ buffer: true; } & WeasyPrintOptions; /** * Create a PDF from the passed input and get a buffer of the result. * * @param input The html string, or URL of the page, to turn into a PDF. * @param options The configuration for the command. * @returns A promise that resolves to the result of the command. */ declare function weasyprint(input: string, options: WeasyPrintBufferOptions): Promise<Buffer>; /** * Create a PDF from the passed input and write it to a file. * * @param input The html string, or URL of the page, to turn into a PDF. * @param options The configuration for the command. * @returns A promise that resolves when finished. */ declare function weasyprint(input: string, options: WeasyPrintFileOutputOptions): Promise<void>; /** * Create a PDF from the passed input and get a stream with the result. * * @param input The html string, or URL of the page, to turn into a PDF. * @param options The configuration for the command. * @returns A stream with the result. */ declare function weasyprint(input: string, options?: WeasyPrintStreamOptions): ChildProcess; export default weasyprint;