diff --git a/types/pdfmake/index.d.ts b/types/pdfmake/index.d.ts index 507e810d0f7b14..3dd74e255accc3 100644 --- a/types/pdfmake/index.d.ts +++ b/types/pdfmake/index.d.ts @@ -9,8 +9,8 @@ import { TVirtualFileSystem, } from "./interfaces"; -export type { TCreatedPdf }; export type { Alignment, Content, CustomTableLayout, Size, Style, Table, TableCell, TableLayout } from "./interfaces"; +export type { TCreatedPdf }; export function createPdf( documentDefinitions: TDocumentDefinitions, @@ -38,4 +38,13 @@ export function addVirtualFileSystem(vfs: TVirtualFileSystem): void; */ export function addFontContainer(fontContainer: TFontContainer): void; +/** + * **Note:** Only supported in Node.js. + */ +export function setUrlAccessPolicy(callback: (url: string) => boolean): void; +/** + * **Note:** Only supported in Node.js. + */ +export function setLocalAccessPolicy(callback: (path: string) => boolean): void; + export as namespace pdfMake; diff --git a/types/pdfmake/interfaces.d.ts b/types/pdfmake/interfaces.d.ts index ba65d2e761c2c1..6498a8fd644634 100755 --- a/types/pdfmake/interfaces.d.ts +++ b/types/pdfmake/interfaces.d.ts @@ -528,6 +528,13 @@ export interface TableCellProperties { * Defaults to `1`. */ overlayOpacity?: number | null | undefined; + + /** + * Vertical alignment of the cell's content. + * + * Defaults to `top`. + */ + verticalAlignment?: "top" | "middle" | "bottom" | undefined; } /** @@ -1016,6 +1023,24 @@ export interface ContentText extends ContentLink, ContentBase, ForbidOtherElemen * below one another, but as inline text in a single paragraph. */ text: Content; + /** + * Adds this node to the PDF outline/bookmark tree. + * + * Outlines are hierarchical navigation entries shown in the PDF viewer. + */ + outline?: boolean; + /** + * Overrides the displayed bookmark label. + */ + outlineText?: string; + /** + * Marks the bookmark as expanded/opened by default. + */ + outlineExpanded?: boolean; + /** + * Assigns this bookmark to the parent entry with the given `id`. + */ + outlineParentId?: string; } /** @@ -1024,6 +1049,14 @@ export interface ContentText extends ContentLink, ContentBase, ForbidOtherElemen export interface ContentColumns extends ContentBase, ForbidOtherElementProperties<"columns"> { /** Divides the given elements into multiple columns. */ columns: Column[]; + /** + * Enables snaking columns (newspaper-style columns), where content flows vertically through the first column + * and continues at the top of the next columns as needed. Only the first column should contain content; + * the remaining columns act as empty overflow targets. + * + * Note: Recursive snaking columns are not supported. + */ + snakingColumns?: boolean; } /** @@ -1669,6 +1702,11 @@ export interface TableOfContent { * Defaults to the system locale. */ sortLocale?: string | undefined; + + /** + * If set to `true`, adds all items to outlines / bookmarks (any existing outline settings on texts are respected) + */ + outlines?: boolean | undefined; } /** diff --git a/types/pdfmake/test/pdfmake-examples-tests.ts b/types/pdfmake/test/pdfmake-examples-tests.ts index 7f2407e878e522..d564f8519b87f0 100644 --- a/types/pdfmake/test/pdfmake-examples-tests.ts +++ b/types/pdfmake/test/pdfmake-examples-tests.ts @@ -404,6 +404,19 @@ const columnsSimple: TDocumentDefinitions = { }, }; +const columnsSnake: TDocumentDefinitions = { + content: [ + { + columns: [ + { text: "Long content", width: "*" }, + { text: "", width: "*" }, + { text: "", width: "*" }, + ], + snakingColumns: true, + }, + ], +}; + const images: TDocumentDefinitions = { content: [ "pdfmake (since it's based on pdfkit) supports JPEG and PNG format", @@ -2423,6 +2436,18 @@ const tables: TDocumentDefinitions = { ], }, }, + { + table: { + headerRows: 1, + widths: ["*", "auto", 100, "*"], + + body: [ + ["First", "Second", "Third", "The last one"], + ["Value 1", "Value 2", "Value 3", "Value 4"], + [{ text: "Bold value", verticalAlignment: "middle" }, "Val 2", "Val 3", "Val 4"], + ], + }, + }, ], styles: { header: { @@ -2454,6 +2479,42 @@ const tables: TDocumentDefinitions = { }, }; +const outlinesAndBookmarks: TDocumentDefinitions = { + content: [ + { + text: "First header in bookmarks", + outline: true, + }, + { + text: "Second header with custom bookmark", + outline: true, + outlineText: "Custom bookmark text", + }, + { + text: "Structured bookmarks", + id: "structured-bookmarks", + outline: true, + outlineExpanded: true, + }, + { + text: "First subheader", + outline: true, + outlineParentId: "structured-bookmarks", + }, + { + text: "Second subheader", + outline: true, + outlineParentId: "structured-bookmarks", + }, + { + text: "Third subheader", + outline: true, + outlineParentId: "structured-bookmarks", + id: "third-subheader", + }, + ], +}; + const textDecorations: TDocumentDefinitions = { content: [ { text: "Higlighted text", fontSize: 18, background: "yellow" }, @@ -2538,6 +2599,7 @@ const toc: TDocumentDefinitions = { numberStyle: { bold: true }, sortBy: "page", sortLocale: "cs", + outlines: true, }, }, { diff --git a/types/pdfmake/test/pdfmake-module-server-tests.ts b/types/pdfmake/test/pdfmake-module-server-tests.ts index 8322f5649c7734..011aff4940dc23 100755 --- a/types/pdfmake/test/pdfmake-module-server-tests.ts +++ b/types/pdfmake/test/pdfmake-module-server-tests.ts @@ -36,3 +36,6 @@ pdfMake.setProgressCallback(progress => console.log("Creating pdf: ", progress * pdfMake.createPdf(dd, options).write("fileName.pdf").then(() => { console.log("PDF file written"); }); + +pdfMake.setUrlAccessPolicy(url => url.startsWith("")); +pdfMake.setLocalAccessPolicy(path => path.startsWith(""));