UNPKG

@jackiemacklein/nettz-utils

Version:

Serviços de imagem, e-mail, códigos de barras, utilitários numéricos e componentes React para apps Node.js com TypeScript

108 lines (107 loc) 3.85 kB
import { PaperFormat } from "puppeteer"; /** * @author Jackiê Macklein * @company Onside tecnologia/Nettz * @copyright Todos direitos reservados. * @description Geração de PDF a partir de uma URL ou conteúdo HTML */ export type PrintType = "thermal" | "a4" | "a5" | "letter" | "legal" | "receipt" | "label" | "custom"; interface PrintPreset { format: PaperFormat; margin: { bottom: number; left: number; right: number; top: number; }; preferCSSPageSize: boolean; displayHeaderFooter: boolean; customWidth?: number; customHeight?: number; } export declare const PRINT_PRESETS: Record<PrintType, PrintPreset>; export interface PageToPDFProps { url?: string; customStyle?: string; specificElement?: string; pages?: string; margin?: { bottom: number; left: number; right: number; top: number; }; displayHeaderFooter?: boolean; preferCSSPageSize?: boolean; format?: PaperFormat; content?: string; returnBuffer?: boolean; printType?: PrintType; customWidth?: number; customHeight?: number; } export declare function pageToPDF({ url, customStyle, specificElement, pages, margin, displayHeaderFooter, preferCSSPageSize, format, content, returnBuffer, printType, customWidth, customHeight, }: PageToPDFProps): Promise<string | Buffer>; /** * Função auxiliar para gerar PDF para impressora térmica (cupom) */ export declare function generateThermalPDF(props: Omit<PageToPDFProps, "printType">): Promise<string | Buffer>; /** * Função auxiliar para gerar PDF para papel A4 */ export declare function generateA4PDF(props: Omit<PageToPDFProps, "printType">): Promise<string | Buffer>; /** * Função auxiliar para gerar PDF para recibo pequeno */ export declare function generateReceiptPDF(props: Omit<PageToPDFProps, "printType">): Promise<string | Buffer>; /** * Função auxiliar para gerar PDF para etiqueta */ export declare function generateLabelPDF(props: Omit<PageToPDFProps, "printType">): Promise<string | Buffer>; /** * Função auxiliar para gerar PDF com dimensões customizadas */ export declare function generateCustomSizePDF(props: Omit<PageToPDFProps, "printType" | "customWidth" | "customHeight"> & { width: number; height: number; }): Promise<string | Buffer>; /** * Função auxiliar para obter as configurações de um tipo de impressão */ export declare function getPrintPreset(printType: PrintType): PrintPreset; /** * Função auxiliar para listar todos os tipos de impressão disponíveis */ export declare function getAvailablePrintTypes(): PrintType[]; export interface HtmlInjectProps { data: Record<string, any>; variables: { key: string; column_name: string; table_alias: string; function: string; }[]; htmlContent: string; } /** * @author Jackiê Macklein * @company Onside tecnologia/Nettz * @copyright Todos direitos reservados. * @description Injeção de variáveis em um conteúdo HTML * @param {HtmlInjectProps} props * @returns {string} * @example * const htmlContent = ` * <h1>{{name}}</h1> * <p>{{age}}</p> * `; * const data = { name: "John", age: 30 }; * const data2 = {person: { name: "John", age: 30 }}; * const variables = [{ key: "name", column_name: "name", table_alias: "", function: "" }]; * const variables2 = [{ key: "name", column_name: "name", table_alias: "person", function: "" }]; * const result = htmlInject({ data: data, variables: variables, htmlContent: htmlContent }); * const result2 = htmlInject({ data: data2, variables: variables2, htmlContent: htmlContent }); * result === "<h1>John</h1><p>30</p>" * result2 === "<h1>John</h1><p>30</p>" */ export declare function htmlInject({ data, variables, htmlContent, }: HtmlInjectProps): string; export {};