/** * Word-to-PDF Bridge * * Converts a Word document (`DocxDocument`) to PDF. * * The bridge is a thin translation layer: * * DocxDocument * │ * │ layoutDocumentFull() ← @word/layout * ▼ * LayoutDocument (positioned PageContent variants) * │ * │ renderLayoutDocumentToPdf() ← ./render-layout-to-pdf * ▼ * PdfDocumentBuilder → bytes * * Every flow decision (line wrapping, page breaks, table sizing, * float positioning) lives in `@word/layout`. This file only handles * option mapping, optional chart-renderer auto-detection, and the * final `builder.build()` serialization. * * Like `excel-bridge.ts`, this is the ONLY file in the PDF module that * imports from `@word`. * * @example * ```typescript * import { readDocx } from "excelts/word"; * import { docxToPdf } from "excelts/pdf"; * * const doc = await readDocx(docxBytes); * const pdfBytes = await docxToPdf(doc); * ``` */ import type { Chart, DocxDocument } from "../word/types.js"; import type { PdfPageBuilder } from "./builder/document-builder.js"; /** Options for DOCX → PDF conversion. */ export interface DocxToPdfOptions { /** Page width in points (default: from document sectPr or 612 US Letter). */ readonly pageWidth?: number; /** Page height in points (default: from document sectPr or 792 US Letter). */ readonly pageHeight?: number; /** Top margin in points (default: from sectPr or 72). */ readonly marginTop?: number; /** Bottom margin in points (default: from sectPr or 72). */ readonly marginBottom?: number; /** Left margin in points (default: from sectPr or 72). */ readonly marginLeft?: number; /** Right margin in points (default: from sectPr or 72). */ readonly marginRight?: number; /** Default font family (default: "Helvetica"). */ readonly defaultFont?: string; /** Default font size in points (default: 11). */ readonly defaultFontSize?: number; /** * Header band distance from the top edge of the page, in points * (default: section's `pgMar.header`, or 36pt / 0.5"). * * Header paragraphs are laid out starting at this y-offset from the * page top. Overriding it moves the entire header band — useful when * the source document declares no section properties or you want to * tighten / loosen the header position without touching `marginTop`. */ readonly headerMargin?: number; /** * Footer band distance from the bottom edge of the page, in points * (default: section's `pgMar.footer`, or 36pt / 0.5"). * * The footer band's top sits at `pageHeight - footerMargin`. The * footnote stack (if any) is placed directly above this line. */ readonly footerMargin?: number; /** * Optional high-quality chart renderer callback. * * When provided, Word charts are rendered using the injected renderer * instead of the built-in simplified renderer. This allows consumers * to plug in the Excel chart renderer for publication-quality output: * * ```typescript * import { installChartSupport } from "excelts/chart"; * import { createWordChartPdfRenderer } from "excelts/pdf"; * installChartSupport(); * const pdfBytes = await docxToPdf(doc, { * chartRenderer: createWordChartPdfRenderer() * }); * ``` * * The callback receives the original Word `Chart` definition (taken * from the source `ChartContent`), a `PdfPageBuilder`, and the * destination rectangle in PDF coordinates. The implementation * should draw the chart into the rectangle. * * Return `false` to decline a chart. The translator then falls back * to the built-in layout-aware Excel renderer (which also handles * `chartEx` charts), then to the inline `LayoutChart.svg` if present, * and finally to a placeholder rectangle with the chart title * centred. Return `void` or `true` to indicate the chart was handled. * * Note: `chartEx` charts (sunburst / treemap / waterfall / funnel / * boxWhisker / …) never reach this `Chart`-typed callback because * there is no classic `Chart` instance to pass. They are rendered by * the built-in layout-aware renderer instead (full vector output when * `installChartSupport()` has been called). */ readonly chartRenderer?: (chart: Chart, page: PdfPageBuilder, rect: { x: number; y: number; width: number; height: number; }) => boolean | void; } /** * Convert a `DocxDocument` to PDF bytes. * * @param doc - The DOCX document model (from `readDocx` or `Document.build()`). * @param options - Page geometry, fonts, optional chart renderer, … * @returns PDF bytes ready to write to disk or stream over HTTP. */ export declare function docxToPdf(doc: DocxDocument, options?: DocxToPdfOptions): Promise;