UNPKG

chromiumly

Version:

A lightweight Typescript library that interacts with Gotenberg's different modules to convert a variety of document formats to PDF files.

94 lines 5.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MarkdownConverter = void 0; const common_1 = require("../../common"); const converter_utils_1 = require("../utils/converter.utils"); const converter_1 = require("./converter"); const main_config_1 = require("../../main.config"); /** * Class representing a Markdown converter that extends the base Converter class. * This class is used to convert HTML with markdown content to PDF using Gotenberg service. * * @extends Converter */ class MarkdownConverter extends converter_1.Converter { /** * Creates an instance of MarkdownConverter. * Initializes the converter with the Markdown conversion route. */ constructor() { super(main_config_1.ChromiumRoute.MARKDOWN); } /** * Converts HTML with markdown content to PDF. * * @param {Object} options - Conversion options. * @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be converted. * @param {PathLikeOrReadStream} options.markdown - PathLike or ReadStream of the Markdown content to be converted. * @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content. * @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content. * @param {PageProperties} [options.properties] - Page properties for the conversion. * @param {PdfFormat} [options.pdfFormat] - PDF format options. * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output. * @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the conversion. * @param {EmulatedMediaFeature[]} [options.emulatedMediaFeatures] - Override CSS media features (e.g. prefers-color-scheme). * @param {string} [options.waitDelay] - Delay before the conversion process starts. * @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the conversion. * @param {string} [options.waitForSelector] - CSS selector to wait for before completing the conversion. * @param {string} [options.userAgent] - User agent string to use during the conversion. * @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the conversion. * @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code. * @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion. * @param {number[]} [options.failOnResourceHttpStatusCodes] - Whether to fail on resource HTTP status code. * @param {string[]} [options.ignoreResourceHttpStatusDomains] - Domains to exclude from resource HTTP status code checks. * @param {boolean} [options.failOnResourceLoadingFailed] - Whether to fail on resource loading failed. * @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event. * @param {boolean} [options.generateDocumentOutline] - Whether to generate document outline. * @param {Metadata} options.metadata - Metadata to be written. * @param {Cookie[]} options.cookies - Cookies to be written. * @param {DownloadFrom} [options.downloadFrom] - Download a file from a URL. It must return a Content-Disposition header with a filename parameter. * @param {Split} [options.split] - Split the PDF into multiple files. * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a buffer */ async convert({ html, markdown, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, emulatedMediaFeatures, waitDelay, waitForExpression, waitForSelector, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, failOnResourceHttpStatusCodes, ignoreResourceHttpStatusDomains, failOnResourceLoadingFailed, skipNetworkIdleEvent, skipNetworkAlmostIdleEvent, generateDocumentOutline, metadata, cookies, downloadFrom, webhook, split, userPassword, ownerPassword, embeds, watermark, stamp, rotate }) { const data = new FormData(); await common_1.GotenbergUtils.addFile(data, html, 'index.html'); await common_1.GotenbergUtils.addFile(data, markdown, 'file.md'); await converter_utils_1.ConverterUtils.customize(data, { header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, emulatedMediaFeatures, waitDelay, waitForExpression, waitForSelector, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent, skipNetworkAlmostIdleEvent, metadata, cookies, downloadFrom, webhook, split, failOnResourceHttpStatusCodes, ignoreResourceHttpStatusDomains, failOnResourceLoadingFailed, generateDocumentOutline, userPassword, ownerPassword, embeds, watermark, stamp, rotate }); return common_1.GotenbergUtils.fetch(this.endpoint, data, main_config_1.Chromiumly.getGotenbergApiBasicAuthUsername(), main_config_1.Chromiumly.getGotenbergApiBasicAuthPassword(), main_config_1.Chromiumly.getCustomHttpHeaders(), main_config_1.Chromiumly.getGotenbergApiKey(), common_1.GotenbergUtils.buildWebhookHeaders(webhook)); } } exports.MarkdownConverter = MarkdownConverter; //# sourceMappingURL=markdown.converter.js.map