/** * Excel-to-PDF Bridge * * Converts Excel Workbook data into the PDF module's independent data model. * This is the ONLY file in the PDF module that imports from @excel. * It also imports from @word/bridge/excel-bridge for Word chart → ChartModel mapping. * * @example * ```typescript * import { Workbook } from "excelts"; * import { excelToPdf } from "excelts/pdf"; * * const workbook = new Workbook(); * // ... build workbook ... * const pdf = await excelToPdf(workbook); * ``` */ import type { Chart, RegionMapDataOptions } from "../excel/chart/index.js"; import type { Workbook } from "../excel/workbook.browser.js"; import type { LayoutChart } from "../word/layout/layout-model.js"; import type { Chart as WordChart } from "../word/types.js"; import { type PdfPageBuilder } from "./builder/document-builder.js"; import { type PdfExportOptions } from "./types.js"; /** * Export an Excel Workbook directly to PDF. * * This is a convenience function that converts the Workbook to the PDF module's * data model and then generates the PDF. * Yields to the event loop between each output page during layout and rendering. * * @param workbook - An Excel Workbook instance * @param options - PDF export options * @returns Promise of PDF file as a Uint8Array */ export declare function excelToPdf(workbook: Workbook, options?: PdfExportOptions): Promise; /** * Options for {@link chartToPdf}. */ export interface ChartToPdfOptions { /** PDF page width in points. Default: max(chart width + 72, 400). */ pageWidth?: number; /** PDF page height in points. Default: max(chart height + 72, 300). */ pageHeight?: number; /** Chart render width in points. Default: 520. */ width?: number; /** Chart render height in points. Default: 360. */ height?: number; /** * Left margin in points between the chart and the page edge. Default: 36. * Used as top margin too so the chart sits in a 36-pt gutter. */ margin?: number; /** * Force rasterisation even for classic charts. Default: `false` * (classic charts render as vector PDF content; ChartEx charts * also render as vector when their layout IDs are supported — see * `VECTOR_PDF_CHART_EX_LAYOUT_IDS` and the "ChartEx PDF" note in * `src/modules/excel/README.md`). When `true`, all chart types go * through the SVG → PNG → image-XObject raster pipeline. */ forceRaster?: boolean; /** PNG raster scale multiplier when rasterising. Default: 2 (for crisp text). */ rasterScale?: number; /** Document metadata forwarded to the resulting PDF. */ title?: string; author?: string; /** * ChartEx `regionMap` data. When supplied, the vector PDF path * uses the TopoJSON polygons (matched via `match` rules) instead * of the centroid preview. Ignored for non-regionMap layouts and * when the chart rasterises. Mirrors `renderChartExSvg`'s * `regionMap` option so a single caller-side object works for * both backends. */ regionMap?: RegionMapDataOptions; } /** * Render a single {@link Chart} to a standalone one-page PDF. * * The output is a **zero-dependency deterministic preview**, not an * Excel-pixel-perfect rendering. Use this for server-side reports, * thumbnails, and CI artefacts where the goal is a recognisable chart * without a headless Office dependency. When pixel-identical output * matters (publication-grade reports, Excel/LibreOffice-compatible * formatting), round-trip the `.xlsx` through * `soffice --convert-to pdf` — the byte-preserving round-trip in this * library makes that a safe handoff. See `src/modules/excel/README.md` * → "Rendering scope" for the complete boundary list. * * Classic charts take the **vector** path: the chart is drawn directly * onto the page via `drawChartPdf`, so text stays selectable and shapes * remain resolution-independent. ChartEx charts whose layout IDs are in * `VECTOR_PDF_CHART_EX_LAYOUT_IDS` also take the vector path via * `drawChartExPdf`; unsupported layouts (if any) and charts where * `forceRaster: true` is set fall through to the SVG → PNG → image-XObject * raster pipeline. * * Lives in `excel-bridge.ts` because invoking the PDF builder from the * chart module would cross the Layer 4 → Layer 5 import boundary * documented in `AGENTS.md`. Consumers import it from * `@cj-tech-master/excelts/pdf` alongside `excelToPdf`. */ export declare function chartToPdf(chart: Chart, options?: ChartToPdfOptions): Promise; /** * Create a chart renderer callback for use with `docxToPdf`. * * This factory returns a function that converts Word Chart definitions * into Excel's internal ChartModel and renders them using the full * Excel chart rendering engine (8000+ lines of vector drawing logic). * * Requires `installChartSupport()` to have been called. * * @example * ```typescript * import { installChartSupport } from "excelts/chart"; * import { docxToPdf, createWordChartPdfRenderer } from "excelts/pdf"; * * installChartSupport(); * const pdfBytes = await docxToPdf(doc, { * chartRenderer: createWordChartPdfRenderer() * }); * ``` */ export declare function createWordChartPdfRenderer(): (chart: WordChart, page: PdfPageBuilder, rect: { x: number; y: number; width: number; height: number; }) => void; /** * Create a layout-aware chart renderer for use as the internal * `RenderLayoutOptions.chartRenderer` of the Word→PDF bridge. * * Unlike {@link createWordChartPdfRenderer} (which only sees the inner * classic `Chart` model), this renderer receives the full * {@link LayoutChart} and therefore handles **both** chart families * with the full Excel rendering engine: * * - Classic `` (`chartKind === "chart"`) → `wordChartToChartModel` * → `drawChartPdf` (vector). * - Modern `` ChartEx (`chartKind === "chartEx"`, * e.g. sunburst / treemap / waterfall / funnel / boxWhisker / * histogram / pareto / regionMap) → `parseChartEx` → `drawChartExPdf` * (vector) when the layout is vector-capable, otherwise the * pre-rendered SVG carried on the `LayoutChart` is left for the * translator's fallback. * * Returns `false` to decline a chart so the translator's built-in * fallback (inline SVG, then a titled placeholder box) takes over. This * keeps "fail soft" behaviour: a chart the engine can't draw still * renders *something* rather than a blank slot. * * Requires `installChartSupport()` to have been called. */ export declare function createWordLayoutChartPdfRenderer(): (chart: LayoutChart, page: PdfPageBuilder, rect: { x: number; y: number; width: number; height: number; }) => boolean | void;