1 |
|
2 |
|
3 | export type jsPDFConstructor = any;
|
4 | export type jsPDFDocument = any;
|
5 | export type Opts = {
|
6 | [key: string]: string | number;
|
7 | };
|
8 | declare class DocHandler {
|
9 | private readonly jsPDFDocument;
|
10 | readonly userStyles: Partial<Styles>;
|
11 | constructor(jsPDFDocument: jsPDFDocument);
|
12 | static setDefaults(defaults: UserOptions, doc?: jsPDFDocument | null): void;
|
13 | private static unifyColor;
|
14 | applyStyles(styles: Partial<Styles>, fontOnly?: boolean): void;
|
15 | splitTextToSize(text: string | string[], size: number, opts: Opts): string[];
|
16 | /**
|
17 | * Adds a rectangle to the PDF
|
18 | * @param x Coordinate (in units declared at inception of PDF document) against left edge of the page
|
19 | * @param y Coordinate (in units declared at inception of PDF document) against upper edge of the page
|
20 | * @param width Width (in units declared at inception of PDF document)
|
21 | * @param height Height (in units declared at inception of PDF document)
|
22 | * @param fillStyle A string specifying the painting style or null. Valid styles include: 'S' [default] - stroke, 'F' - fill, and 'DF' (or 'FD') - fill then stroke.
|
23 | */
|
24 | rect(x: number, y: number, width: number, height: number, fillStyle: "S" | "F" | "DF" | "FD"): any;
|
25 | getLastAutoTable(): Table | null;
|
26 | getTextWidth(text: string | string[]): number;
|
27 | getDocument(): any;
|
28 | setPage(page: number): void;
|
29 | addPage(): any;
|
30 | getFontList(): {
|
31 | [key: string]: string[] | undefined;
|
32 | };
|
33 | getGlobalOptions(): UserOptions;
|
34 | getDocumentOptions(): UserOptions;
|
35 | pageSize(): {
|
36 | width: number;
|
37 | height: number;
|
38 | };
|
39 | scaleFactor(): number;
|
40 | getLineHeightFactor(): number;
|
41 | getLineHeight(fontSize: number): number;
|
42 | pageNumber(): number;
|
43 | }
|
44 | declare class HookData {
|
45 | table: Table;
|
46 | pageNumber: number;
|
47 | pageCount: number;
|
48 | settings: Settings;
|
49 | doc: jsPDFDocument;
|
50 | cursor: Pos | null;
|
51 | constructor(doc: DocHandler, table: Table, cursor: Pos | null);
|
52 | }
|
53 | export declare class CellHookData extends HookData {
|
54 | cell: Cell;
|
55 | row: Row;
|
56 | column: Column;
|
57 | section: "head" | "body" | "foot";
|
58 | constructor(doc: DocHandler, table: Table, cell: Cell, row: Row, column: Column, cursor: Pos | null);
|
59 | }
|
60 | export type MarginPadding = {
|
61 | top: number;
|
62 | right: number;
|
63 | bottom: number;
|
64 | left: number;
|
65 | };
|
66 | export interface ContentInput {
|
67 | body: RowInput[];
|
68 | head: RowInput[];
|
69 | foot: RowInput[];
|
70 | columns: ColumnInput[];
|
71 | }
|
72 | export interface TableInput {
|
73 | id: string | number | undefined;
|
74 | settings: Settings;
|
75 | styles: StylesProps;
|
76 | hooks: HookProps;
|
77 | content: ContentInput;
|
78 | }
|
79 | export type Pos = {
|
80 | x: number;
|
81 | y: number;
|
82 | };
|
83 | export type PageHook = (data: HookData) => void | boolean;
|
84 | export type CellHook = (data: CellHookData) => void | boolean;
|
85 | export interface HookProps {
|
86 | didParseCell: CellHook[];
|
87 | willDrawCell: CellHook[];
|
88 | didDrawCell: CellHook[];
|
89 | willDrawPage: PageHook[];
|
90 | didDrawPage: PageHook[];
|
91 | }
|
92 | export interface Settings {
|
93 | includeHiddenHtml: boolean;
|
94 | useCss: boolean;
|
95 | theme: "striped" | "grid" | "plain";
|
96 | startY: number;
|
97 | margin: MarginPadding;
|
98 | pageBreak: "auto" | "avoid" | "always";
|
99 | rowPageBreak: "auto" | "avoid";
|
100 | tableWidth: "auto" | "wrap" | number;
|
101 | showHead: "everyPage" | "firstPage" | "never";
|
102 | showFoot: "everyPage" | "lastPage" | "never";
|
103 | tableLineWidth: number;
|
104 | tableLineColor: Color;
|
105 | horizontalPageBreak?: boolean;
|
106 | horizontalPageBreakBehaviour?: "immediately" | "afterAllRows";
|
107 | horizontalPageBreakRepeat?: string | number | string[] | number[] | null;
|
108 | }
|
109 | export interface StylesProps {
|
110 | styles: Partial<Styles>;
|
111 | headStyles: Partial<Styles>;
|
112 | bodyStyles: Partial<Styles>;
|
113 | footStyles: Partial<Styles>;
|
114 | alternateRowStyles: Partial<Styles>;
|
115 | columnStyles: {
|
116 | [key: string]: Partial<Styles>;
|
117 | };
|
118 | }
|
119 | export type ContentSettings = {
|
120 | body: Row[];
|
121 | head: Row[];
|
122 | foot: Row[];
|
123 | columns: Column[];
|
124 | };
|
125 | export declare class Table {
|
126 | readonly id?: string | number;
|
127 | readonly settings: Settings;
|
128 | readonly styles: StylesProps;
|
129 | readonly hooks: HookProps;
|
130 | readonly columns: Column[];
|
131 | readonly head: Row[];
|
132 | readonly body: Row[];
|
133 | readonly foot: Row[];
|
134 | pageNumber: number;
|
135 | finalY?: number;
|
136 | startPageNumber?: number;
|
137 | pageCount: number;
|
138 | constructor(input: TableInput, content: ContentSettings);
|
139 | getHeadHeight(columns: Column[]): number;
|
140 | getFootHeight(columns: Column[]): number;
|
141 | allRows(): Row[];
|
142 | callCellHooks(doc: DocHandler, handlers: CellHook[], cell: Cell, row: Row, column: Column, cursor: {
|
143 | x: number;
|
144 | y: number;
|
145 | } | null): boolean;
|
146 | callEndPageHooks(doc: DocHandler, cursor: {
|
147 | x: number;
|
148 | y: number;
|
149 | }): void;
|
150 | callWillDrawPageHooks(doc: DocHandler, cursor: {
|
151 | x: number;
|
152 | y: number;
|
153 | }): void;
|
154 | getWidth(pageWidth: number): number;
|
155 | }
|
156 | export declare class Row {
|
157 | readonly raw: HTMLTableRowElement | RowInput;
|
158 | readonly element?: HTMLTableRowElement;
|
159 | readonly index: number;
|
160 | readonly section: Section;
|
161 | readonly cells: {
|
162 | [key: string]: Cell;
|
163 | };
|
164 | spansMultiplePages: boolean;
|
165 | height: number;
|
166 | constructor(raw: RowInput | HTMLTableRowElement, index: number, section: Section, cells: {
|
167 | [key: string]: Cell;
|
168 | }, spansMultiplePages?: boolean);
|
169 | getMaxCellHeight(columns: Column[]): number;
|
170 | hasRowSpan(columns: Column[]): boolean;
|
171 | canEntireRowFit(height: number, columns: Column[]): boolean;
|
172 | getMinimumRowHeight(columns: Column[], doc: DocHandler): number;
|
173 | }
|
174 | export type Section = "head" | "body" | "foot";
|
175 | export declare class Cell {
|
176 | raw: HTMLTableCellElement | CellInput;
|
177 | styles: Styles;
|
178 | text: string[];
|
179 | section: Section;
|
180 | colSpan: number;
|
181 | rowSpan: number;
|
182 | contentHeight: number;
|
183 | contentWidth: number;
|
184 | wrappedWidth: number;
|
185 | minReadableWidth: number;
|
186 | minWidth: number;
|
187 | width: number;
|
188 | height: number;
|
189 | x: number;
|
190 | y: number;
|
191 | constructor(raw: CellInput, styles: Styles, section: Section);
|
192 | getTextPos(): Pos;
|
193 | getContentHeight(scaleFactor: number, lineHeightFactor?: number): number;
|
194 | padding(name: "vertical" | "horizontal" | "top" | "bottom" | "left" | "right"): number;
|
195 | }
|
196 | export declare class Column {
|
197 | raw: ColumnInput | null;
|
198 | dataKey: string | number;
|
199 | index: number;
|
200 | wrappedWidth: number;
|
201 | minReadableWidth: number;
|
202 | minWidth: number;
|
203 | width: number;
|
204 | constructor(dataKey: string | number, raw: ColumnInput | null, index: number);
|
205 | getMaxCustomCellWidth(table: Table): number;
|
206 | }
|
207 | export interface LineWidths {
|
208 | bottom: number;
|
209 | top: number;
|
210 | left: number;
|
211 | right: number;
|
212 | }
|
213 | export type FontStyle = "normal" | "bold" | "italic" | "bolditalic";
|
214 | export type StandardFontType = "helvetica" | "times" | "courier";
|
215 | export type CustomFontType = string;
|
216 | export type FontType = StandardFontType | CustomFontType;
|
217 | export type HAlignType = "left" | "center" | "right" | "justify";
|
218 | export type VAlignType = "top" | "middle" | "bottom";
|
219 | export type OverflowType = "linebreak" | "ellipsize" | "visible" | "hidden" | ((text: string | string[], width: number) => string | string[]);
|
220 | export type CellWidthType = "auto" | "wrap" | number;
|
221 | export interface Styles {
|
222 | font: FontType;
|
223 | fontStyle: FontStyle;
|
224 | overflow: OverflowType;
|
225 | fillColor: Color;
|
226 | textColor: Color;
|
227 | halign: HAlignType;
|
228 | valign: VAlignType;
|
229 | fontSize: number;
|
230 | cellPadding: MarginPaddingInput;
|
231 | lineColor: Color;
|
232 | lineWidth: number | Partial<LineWidths>;
|
233 | cellWidth: CellWidthType;
|
234 | minCellHeight: number;
|
235 | minCellWidth: number;
|
236 | }
|
237 | export type ThemeType = "striped" | "grid" | "plain" | null;
|
238 | export type PageBreakType = "auto" | "avoid" | "always";
|
239 | export type RowPageBreakType = "auto" | "avoid";
|
240 | export type TableWidthType = "auto" | "wrap" | number;
|
241 | export type ShowHeadType = "everyPage" | "firstPage" | "never" | boolean;
|
242 | export type ShowFootType = "everyPage" | "lastPage" | "never" | boolean;
|
243 | export type HorizontalPageBreakBehaviourType = "immediately" | "afterAllRows";
|
244 | export interface UserOptions {
|
245 | includeHiddenHtml?: boolean;
|
246 | useCss?: boolean;
|
247 | theme?: ThemeType;
|
248 | startY?: number | false;
|
249 | margin?: MarginPaddingInput;
|
250 | pageBreak?: PageBreakType;
|
251 | rowPageBreak?: RowPageBreakType;
|
252 | tableWidth?: TableWidthType;
|
253 | showHead?: ShowHeadType;
|
254 | showFoot?: ShowFootType;
|
255 | tableLineWidth?: number;
|
256 | tableLineColor?: Color;
|
257 | tableId?: string | number;
|
258 | head?: RowInput[];
|
259 | body?: RowInput[];
|
260 | foot?: RowInput[];
|
261 | html?: string | HTMLTableElement;
|
262 | columns?: ColumnInput[];
|
263 | horizontalPageBreak?: boolean;
|
264 | horizontalPageBreakRepeat?: string[] | number[] | string | number;
|
265 | horizontalPageBreakBehaviour?: HorizontalPageBreakBehaviourType;
|
266 | styles?: Partial<Styles>;
|
267 | bodyStyles?: Partial<Styles>;
|
268 | headStyles?: Partial<Styles>;
|
269 | footStyles?: Partial<Styles>;
|
270 | alternateRowStyles?: Partial<Styles>;
|
271 | columnStyles?: {
|
272 | [key: string]: Partial<Styles>;
|
273 | };
|
274 | /** Called when the plugin finished parsing cell content. Can be used to override content or styles for a specific cell. */
|
275 | didParseCell?: CellHook;
|
276 | /** Called before a cell or row is drawn. Can be used to call native jspdf styling functions such as `doc.setTextColor` or change position of text etc before it is drawn. */
|
277 | willDrawCell?: CellHook;
|
278 | /** Called after a cell has been added to the page. Can be used to draw additional cell content such as images with `doc.addImage`, additional text with `doc.addText` or other jspdf shapes. */
|
279 | didDrawCell?: CellHook;
|
280 | /** Called before starting to draw on a page. Can be used to add headers or any other content that you want on each page there is an autotable. */
|
281 | willDrawPage?: PageHook;
|
282 | /** Called after the plugin has finished drawing everything on a page. Can be used to add footers with page numbers or any other content that you want on each page there is an autotable. */
|
283 | didDrawPage?: PageHook;
|
284 | }
|
285 | export type ColumnInput = string | number | {
|
286 | header?: CellInput;
|
287 | title?: CellInput;
|
288 | footer?: CellInput;
|
289 | dataKey?: string | number;
|
290 | key?: string | number;
|
291 | };
|
292 | export type Color = [
|
293 | number,
|
294 | number,
|
295 | number
|
296 | ] | number | string | false;
|
297 | export type MarginPaddingInput = number | number[] | {
|
298 | top?: number;
|
299 | right?: number;
|
300 | bottom?: number;
|
301 | left?: number;
|
302 | horizontal?: number;
|
303 | vertical?: number;
|
304 | };
|
305 | export interface CellDef {
|
306 | rowSpan?: number;
|
307 | colSpan?: number;
|
308 | styles?: Partial<Styles>;
|
309 | content?: string | string[] | number;
|
310 | title?: string;
|
311 | _element?: HTMLTableCellElement;
|
312 | }
|
313 | declare class HtmlRowInput extends Array<CellDef> {
|
314 | _element: HTMLTableRowElement;
|
315 | constructor(element: HTMLTableRowElement);
|
316 | }
|
317 | export type CellInput = null | string | string[] | number | boolean | CellDef;
|
318 | export type RowInput = {
|
319 | [key: string]: CellInput;
|
320 | } | HtmlRowInput | CellInput[];
|
321 | export type autoTable = (options: UserOptions) => void;
|
322 | export declare function applyPlugin(jsPDF: jsPDFConstructor): void;
|
323 | declare function autoTable(d: jsPDFDocument, options: UserOptions): void;
|
324 | declare function __createTable(d: jsPDFDocument, options: UserOptions): Table;
|
325 | declare function __drawTable(d: jsPDFDocument, table: Table): void;
|
326 |
|
327 | export {
|
328 | autoTable as default,
|
329 | };
|
330 |
|
331 | export {};
|