/** * Simplified PDF generation API. * * Provides a concise way to create PDFs from plain data — no need to manually * construct Map objects, compute bounds, or specify cell types. * * @example Simplest — pass a 2D array: * ```typescript * import { pdf } from "@cj-tech-master/excelts/pdf"; * * const bytes = await pdf([ * ["Product", "Revenue"], * ["Widget", 1000], * ["Gadget", 2500] * ]); * ``` * * @example With options: * ```typescript * const bytes = await pdf([ * ["Name", "Score"], * ["Alice", 95], * ["Bob", 87] * ], { showGridLines: true, title: "Scores" }); * ``` * * @example Multiple sheets: * ```typescript * const bytes = await pdf({ * sheets: [ * { name: "Sales", data: [["Product", "Revenue"], ["Widget", 1000]] }, * { name: "Costs", data: [["Item", "Amount"], ["Rent", 500]] } * ] * }); * ``` * * @example With column widths and styles: * ```typescript * const bytes = await pdf({ * name: "Report", * columns: [{ width: 25 }, { width: 15 }], * data: [ * ["Product", "Revenue"], * ["Widget", "$1,000"] * ] * }); * ``` */ import { type PdfExportOptions } from "./types.js"; /** A cell value: string, number, boolean, Date, null, or a styled cell object. */ export type PdfCellValue = string | number | boolean | Date | null | undefined | PdfCell; /** A cell with an explicit value and optional style overrides. */ export interface PdfCell { value: string | number | boolean | Date | null | undefined; bold?: boolean; italic?: boolean; fontSize?: number; fontColor?: string; fillColor?: string; align?: "left" | "center" | "right"; } /** A row is an array of cell values. */ export type PdfRow = PdfCellValue[]; /** Column configuration. */ export interface PdfColumn { width?: number; header?: string; } /** An image to embed in a sheet. */ export interface PdfImage { /** Raw image bytes (JPEG or PNG). */ data: Uint8Array; /** Image format. */ format: "jpeg" | "png"; /** * Top-left column position (0-indexed). * This is relative to the final sheet grid — if column headers are used, * they occupy the first row, so data starts at row 1. */ col: number; /** * Top-left row position (0-indexed). * This is relative to the final sheet grid — if column headers are used, * row 0 is the header row, and data rows start at row 1. */ row: number; /** Image width in pixels. */ width: number; /** Image height in pixels. */ height: number; } /** A single sheet definition. */ export interface PdfSheet { name?: string; columns?: (PdfColumn | number)[]; data: PdfRow[]; images?: PdfImage[]; } /** A multi-sheet document definition. */ export interface PdfBook { title?: string; author?: string; sheets: PdfSheet[]; } /** * The input to {@link pdf} — can be: * - A 2D array (single sheet) * - A sheet object `{ name?, columns?, data, images? }` * - A workbook object `{ sheets: [...] }` */ export type PdfInput = PdfRow[] | PdfSheet | PdfBook; /** * Generate a PDF. * * Accepts anything from a plain 2D array to a multi-sheet workbook. * Yields to the event loop between each output page during layout and rendering. * * @param input - 2D array, sheet object, or workbook object * @param options - PDF export options (page size, margins, etc.) * @returns Promise of PDF file as Uint8Array */ export declare function pdf(input: PdfInput, options?: PdfExportOptions): Promise;