0
# Configuration and Styling
1
2
Comprehensive configuration system with built-in themes, custom styling options, and layout controls for creating professionally styled PDF tables.
3
4
## Capabilities
5
6
### UserOptions Interface
7
8
Complete configuration interface providing all available options for table generation and styling.
9
10
```typescript { .api }
11
interface UserOptions {
12
// Content Options
13
/** Header rows data */
14
head?: RowInput[];
15
/** Body rows data */
16
body?: RowInput[];
17
/** Footer rows data */
18
foot?: RowInput[];
19
/** HTML table element or selector to parse */
20
html?: string | HTMLTableElement;
21
/** Column definitions for data mapping */
22
columns?: ColumnInput[];
23
/** Unique identifier for the table */
24
tableId?: string | number;
25
26
// Layout Options
27
/** Starting Y position on the page, or false to start immediately after previous content */
28
startY?: number | false;
29
/** Table margins */
30
margin?: MarginPaddingInput;
31
/** Table width behavior: 'auto' (full width), 'wrap' (content width), or specific number */
32
tableWidth?: TableWidthType;
33
/** Page break behavior for the table */
34
pageBreak?: PageBreakType;
35
/** Row page break behavior */
36
rowPageBreak?: RowPageBreakType;
37
/** When to show the header: 'everyPage', 'firstPage', or 'never' */
38
showHead?: ShowHeadType;
39
/** When to show the footer: 'everyPage', 'lastPage', or 'never' */
40
showFoot?: ShowFootType;
41
42
// Table Border Options
43
/** Width of table border lines */
44
tableLineWidth?: number;
45
/** Color of table border lines */
46
tableLineColor?: Color;
47
48
// HTML Parsing Options
49
/** Include hidden HTML elements when parsing */
50
includeHiddenHtml?: boolean;
51
/** Use CSS styles from HTML when parsing */
52
useCss?: boolean;
53
54
// Horizontal Page Break Options
55
/** Enable horizontal page breaks for wide tables */
56
horizontalPageBreak?: boolean;
57
/** Columns to repeat on each horizontal page */
58
horizontalPageBreakRepeat?: string[] | number[] | string | number;
59
/** When to perform horizontal page breaks */
60
horizontalPageBreakBehaviour?: HorizontalPageBreakBehaviourType;
61
62
// Styling Options
63
/** Predefined theme */
64
theme?: ThemeType;
65
/** Default cell styles */
66
styles?: Partial<Styles>;
67
/** Header cell styles */
68
headStyles?: Partial<Styles>;
69
/** Body cell styles */
70
bodyStyles?: Partial<Styles>;
71
/** Footer cell styles */
72
footStyles?: Partial<Styles>;
73
/** Alternating row styles */
74
alternateRowStyles?: Partial<Styles>;
75
/** Column-specific styles */
76
columnStyles?: { [key: string]: Partial<Styles> };
77
78
// Hook Functions
79
/** Called after parsing cell content */
80
didParseCell?: CellHook;
81
/** Called before drawing a cell */
82
willDrawCell?: CellHook;
83
/** Called after drawing a cell */
84
didDrawCell?: CellHook;
85
/** Called before drawing a page */
86
willDrawPage?: PageHook;
87
/** Called after drawing a page */
88
didDrawPage?: PageHook;
89
}
90
```
91
92
### Styles Interface
93
94
Complete styling options for cells including fonts, colors, alignment, and borders.
95
96
```typescript { .api }
97
interface Styles {
98
/** Font family */
99
font: FontType;
100
/** Font style */
101
fontStyle: FontStyle;
102
/** Font size in points */
103
fontSize: number;
104
/** Text color */
105
textColor: Color;
106
/** Background fill color */
107
fillColor: Color;
108
/** Horizontal text alignment */
109
halign: HAlignType;
110
/** Vertical text alignment */
111
valign: VAlignType;
112
/** Cell padding */
113
cellPadding: MarginPaddingInput;
114
/** Border line color */
115
lineColor: Color;
116
/** Border line width */
117
lineWidth: number | Partial<LineWidths>;
118
/** Cell width behavior */
119
cellWidth: CellWidthType;
120
/** Minimum cell height */
121
minCellHeight: number;
122
/** Minimum cell width */
123
minCellWidth: number;
124
/** Text overflow behavior */
125
overflow: OverflowType;
126
}
127
```
128
129
### Built-in Themes
130
131
Pre-configured themes providing professional styling out of the box.
132
133
```typescript { .api }
134
type ThemeType = "striped" | "grid" | "plain" | null;
135
136
/**
137
* Get theme configuration
138
* @param name - Theme name
139
* @returns Theme style definitions
140
*/
141
function getTheme(name: ThemeName): { [key: string]: Partial<Styles> };
142
143
/**
144
* Get default base styles
145
* @param scaleFactor - PDF scale factor
146
* @returns Default style configuration
147
*/
148
function defaultStyles(scaleFactor: number): Styles;
149
```
150
151
**Usage Examples:**
152
153
```typescript
154
// Striped theme (default)
155
autoTable(doc, {
156
head: [['Name', 'Score']],
157
body: [['Alice', 95], ['Bob', 87]],
158
theme: 'striped',
159
});
160
161
// Grid theme with borders
162
autoTable(doc, {
163
head: [['Name', 'Score']],
164
body: [['Alice', 95], ['Bob', 87]],
165
theme: 'grid',
166
});
167
168
// Plain theme (minimal styling)
169
autoTable(doc, {
170
head: [['Name', 'Score']],
171
body: [['Alice', 95], ['Bob', 87]],
172
theme: 'plain',
173
});
174
```
175
176
### Custom Styling
177
178
#### Basic Style Customization
179
180
```typescript
181
autoTable(doc, {
182
head: [['Product', 'Price', 'Stock']],
183
body: [
184
['Laptop', '$999', '15'],
185
['Phone', '$599', '23'],
186
],
187
styles: {
188
fontSize: 12,
189
font: 'helvetica',
190
textColor: [0, 0, 0],
191
fillColor: [255, 255, 255],
192
halign: 'center',
193
valign: 'middle',
194
},
195
headStyles: {
196
fillColor: [52, 73, 94],
197
textColor: [255, 255, 255],
198
fontStyle: 'bold',
199
},
200
alternateRowStyles: {
201
fillColor: [245, 245, 245],
202
},
203
});
204
```
205
206
#### Column-Specific Styling
207
208
```typescript
209
autoTable(doc, {
210
columns: [
211
{ header: 'Name', dataKey: 'name' },
212
{ header: 'Amount', dataKey: 'amount' },
213
{ header: 'Status', dataKey: 'status' },
214
],
215
body: [
216
{ name: 'Invoice #1', amount: '$1,200', status: 'Paid' },
217
{ name: 'Invoice #2', amount: '$850', status: 'Pending' },
218
],
219
columnStyles: {
220
0: { halign: 'left' },
221
1: { halign: 'right', fontStyle: 'bold' },
222
2: { halign: 'center' },
223
},
224
});
225
```
226
227
### Type Definitions
228
229
#### Font and Alignment Types
230
231
```typescript { .api }
232
type FontStyle = "normal" | "bold" | "italic" | "bolditalic";
233
type StandardFontType = "helvetica" | "times" | "courier";
234
type CustomFontType = string;
235
type FontType = StandardFontType | CustomFontType;
236
237
type HAlignType = "left" | "center" | "right" | "justify";
238
type VAlignType = "top" | "middle" | "bottom";
239
```
240
241
#### Layout and Behavior Types
242
243
```typescript { .api }
244
type TableWidthType = "auto" | "wrap" | number;
245
type PageBreakType = "auto" | "avoid" | "always";
246
type RowPageBreakType = "auto" | "avoid";
247
type ShowHeadType = "everyPage" | "firstPage" | "never" | boolean;
248
type ShowFootType = "everyPage" | "lastPage" | "never" | boolean;
249
type HorizontalPageBreakBehaviourType = "immediately" | "afterAllRows";
250
251
type CellWidthType = "auto" | "wrap" | number;
252
type OverflowType = "linebreak" | "ellipsize" | "visible" | "hidden" |
253
((text: string | string[], width: number) => string | string[]);
254
```
255
256
#### Border and Spacing Types
257
258
```typescript { .api }
259
interface LineWidths {
260
bottom: number;
261
top: number;
262
left: number;
263
right: number;
264
}
265
266
interface MarginPadding {
267
top: number;
268
right: number;
269
bottom: number;
270
left: number;
271
}
272
273
type MarginPaddingInput = number | number[] | {
274
top?: number;
275
right?: number;
276
bottom?: number;
277
left?: number;
278
horizontal?: number;
279
vertical?: number;
280
};
281
```
282
283
### Advanced Layout Options
284
285
#### Pagination Control
286
287
```typescript
288
autoTable(doc, {
289
head: [['Column 1', 'Column 2']],
290
body: largeDataSet,
291
startY: 40,
292
pageBreak: 'auto',
293
rowPageBreak: 'avoid',
294
showHead: 'everyPage',
295
margin: { top: 20, right: 20, bottom: 20, left: 20 },
296
});
297
```
298
299
#### Wide Table Handling
300
301
```typescript
302
autoTable(doc, {
303
head: [['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']],
304
body: wideData,
305
horizontalPageBreak: true,
306
horizontalPageBreakRepeat: [0, 1], // Keep first two columns
307
horizontalPageBreakBehaviour: 'afterAllRows',
308
});
309
```
310
311
#### Responsive Width
312
313
```typescript
314
autoTable(doc, {
315
head: [['Description', 'Value']],
316
body: [
317
['Short text', 'Value 1'],
318
['This is a much longer description that will wrap', 'Value 2'],
319
],
320
tableWidth: 'wrap', // Adjust to content
321
styles: {
322
cellWidth: 'auto',
323
overflow: 'linebreak',
324
},
325
columnStyles: {
326
0: { cellWidth: 100 }, // Fixed width for first column
327
1: { cellWidth: 'auto' }, // Auto width for second column
328
},
329
});
330
```