Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion types/pdfmake/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
38 changes: 38 additions & 0 deletions types/pdfmake/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down
62 changes: 62 additions & 0 deletions types/pdfmake/test/pdfmake-examples-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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" },
Expand Down Expand Up @@ -2538,6 +2599,7 @@ const toc: TDocumentDefinitions = {
numberStyle: { bold: true },
sortBy: "page",
sortLocale: "cs",
outlines: true,
},
},
{
Expand Down
3 changes: 3 additions & 0 deletions types/pdfmake/test/pdfmake-module-server-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(""));