UNPKG

from-data-to-pdf

Version:

This library converts html files, URL and character string from html files to PDF files or PDF buffer.

107 lines (106 loc) 3.32 kB
/// <reference types="node" /> import * as puppeteer from "puppeteer"; import { Browser } from "puppeteer"; /** * @author DOUAL Sofian * @description Return a browser. * * @export * @returns { Promise<Browser> } */ export declare function initBrowser(): Promise<Browser>; /** * @author DOUAL Sofian * @description Close given browser. * * @export * @param { Browser } browser * @returns { Promise<void> } */ export declare function closeBrowser(browser: Browser): Promise<void>; /** * @author DOUAL Sofian * @description If path is undefined, returns an array of PDFS buffer. Otherwise, return the path of the saved PDF files. * * @export * @param { Browser } browser * @param { FileBuffer[] } targets * @param { string } [path] * @returns {Promise<FileBuffer>} */ export declare function generateBuffer(browser: Browser, targets: FileBuffer[], path?: string): Promise<FileBuffer[]>; /** * @author DOUAL Sofian * @description Save the buffer as a PDF file in <My project>/temp/generatedPDF/. * * @export * @param { FileBuffer[] } targets * @returns { Promise<FileBuffer[]> } */ export declare function savePDF(targets: FileBuffer[]): Promise<FileBuffer[]>; /** * @author DOUAL Sofian * @description Create folders ./temp, ./temp/target, ./temp/generatedPDF * * @returns { Promise<boolean> } */ export declare function initDefaultFolder(): Promise<boolean>; /** * @author DOUAL Sofian * @description Converts HTML files to string. * * @param { HTMLTarget[] } data * @param { string } [path] * @returns { Promise<FileBuffer[]> } */ export declare function fromHtmlFileToString(data: HTMLTarget[], path?: string): Promise<FileBuffer[]>; /** * @author DOUAL Sofian * @description Carries out the process without to get local files. * * @export * @param { FileBuffer[] } targets * @param { boolean } save * @param { path } [path] * @returns { Promise<FileBuffer[]> } */ export declare function getPdf(targets: FileBuffer[], save: boolean, path?: string): Promise<FileBuffer[]>; /** * @author DOUAL Sofian * @description Get html files and carries out the process. * * @export * @param { HTMLTarget[] } files * @param { boolean } save * @param { Path } [path] * @returns { Promise<FileBuffer[]> } */ export declare function fromHtmlFileToPdf(files: HTMLTarget[], save: boolean, path?: Path): Promise<FileBuffer[]>; /** * @author DOUAL Sofian * @description It returns the path of the app directory if path param does not exists. * Else if path param exists and it is a relative path, this method joins it with the path of app directory to finally returns the result as string. * Else if path param exists and it is an absolute path, this methods return it. * * @param { string } [path] * @returns { string } */ export declare function setPath(path?: string): string; export interface HTMLTarget { projectName: string; fileName: string; pdfOptions: puppeteer.PDFOptions; } export interface FileBuffer { name: string; url?: string; text?: string; buffer?: Buffer; options?: puppeteer.PDFOptions; pathOfsavedFile?: string; error?: any; } export interface Path { toGetFiles?: string; toSaveFiles?: string; }