react-vector-pdf 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -1
- package/dist/index.d.ts +37 -7
- package/dist/react-vector-pdf.css +1 -0
- package/dist/react-vector-pdf.js +1095 -719
- package/package.json +69 -69
package/README.md
CHANGED
|
@@ -95,6 +95,76 @@ import { PdfPreview, PdfText } from "react-vector-pdf";
|
|
|
95
95
|
|
|
96
96
|
**Note:** Changing props (like options, colors, fonts) will automatically regenerate and update the preview.
|
|
97
97
|
|
|
98
|
+
## Styling with CSS Classes
|
|
99
|
+
|
|
100
|
+
You can use standard CSS classes (including generic CSS or utility frameworks like **Tailwind CSS**) to style PDF components using the `className` prop. The library uses a special `useClassStyles` hook that renders a hidden DOM element to compute CSS styles and converts them into PDF-compatible properties.
|
|
101
|
+
|
|
102
|
+
### Supported CSS Properties
|
|
103
|
+
|
|
104
|
+
| CSS Property | PDF Mapping | Notes |
|
|
105
|
+
| ------------------ | ------------- | -------------------------------- |
|
|
106
|
+
| `color` | `color` | Supports hex and RGBA |
|
|
107
|
+
| `background-color` | `fillColor` | Supports hex and RGBA |
|
|
108
|
+
| `font-size` | `fontSize` | Converted from px to points (pt) |
|
|
109
|
+
| `font-weight` | `fontStyle` | ≥700 maps to 'bold' |
|
|
110
|
+
| `font-style` | `fontStyle` | Supports italic/bold/bolditalic |
|
|
111
|
+
| `text-align` | `align` | left/center/right/justify |
|
|
112
|
+
| `line-height` | `lineHeight` | Converted to multiplier |
|
|
113
|
+
| `padding-*` | `padding` | Converted from px to mm |
|
|
114
|
+
| `margin-*` | `margin` | Converted from px to mm |
|
|
115
|
+
| `border-width` | `borderWidth` | Uniform borders only, px to mm |
|
|
116
|
+
| `border-color` | `borderColor` | Supports hex and RGBA |
|
|
117
|
+
| `border-radius` | `radius` | Converted from px to mm |
|
|
118
|
+
| `gap` | `gap` | PdfView only, px to mm |
|
|
119
|
+
| `width` | `width` | Explicit widths, px to mm |
|
|
120
|
+
| `height` | `height` | Explicit heights, px to mm |
|
|
121
|
+
|
|
122
|
+
### Unsupported Properties
|
|
123
|
+
|
|
124
|
+
The following CSS properties are **not supported** and will trigger console warnings if used:
|
|
125
|
+
|
|
126
|
+
- `box-shadow`, `text-shadow`
|
|
127
|
+
- `z-index`
|
|
128
|
+
- `float`
|
|
129
|
+
- `overflow`
|
|
130
|
+
- `transform`
|
|
131
|
+
- Layout properties: `display: flex/grid`, `position: absolute/fixed`
|
|
132
|
+
|
|
133
|
+
> **Note**: PDF layout uses standard flow or absolute positioning. Complex CSS layout features like flexbox and grid are not available.
|
|
134
|
+
|
|
135
|
+
### Usage Examples
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
// Using Tailwind CSS classes
|
|
139
|
+
<PdfText className="text-red-600 font-bold text-xl mb-4">
|
|
140
|
+
Styled with Tailwind!
|
|
141
|
+
</PdfText>
|
|
142
|
+
|
|
143
|
+
<PdfView className="border border-gray-300 p-4 bg-gray-50 rounded gap-4">
|
|
144
|
+
<PdfText className="text-gray-800">
|
|
145
|
+
This box uses utility classes for padding, border, and background.
|
|
146
|
+
</PdfText>
|
|
147
|
+
<PdfText>
|
|
148
|
+
Items inside this view are separated by a 1rem (approx 4mm) gap.
|
|
149
|
+
</PdfText>
|
|
150
|
+
</PdfView>
|
|
151
|
+
|
|
152
|
+
// Mixing className with direct props (direct props take precedence)
|
|
153
|
+
<PdfText className="text-blue-500" color="#FF0000">
|
|
154
|
+
This text will be red, not blue
|
|
155
|
+
</PdfText>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### How It Works
|
|
159
|
+
|
|
160
|
+
The library:
|
|
161
|
+
|
|
162
|
+
1. Creates a hidden `<div>` element with the provided `className`
|
|
163
|
+
2. Uses `getComputedStyle()` to read the final computed CSS values
|
|
164
|
+
3. Converts pixel values to PDF units (mm for dimensions, pt for fonts)
|
|
165
|
+
4. Maps CSS properties to PDF renderer properties
|
|
166
|
+
5. Validates and warns about unsupported properties
|
|
167
|
+
|
|
98
168
|
## Components
|
|
99
169
|
|
|
100
170
|
### 1. `PdfDocument`
|
|
@@ -125,6 +195,8 @@ Renders a paragraph of text. Automatically wraps to the content width.
|
|
|
125
195
|
- `align` ('left' | 'center' | 'right' | 'justify'): Text alignment.
|
|
126
196
|
- `lineHeight` (number): Line height multiplier.
|
|
127
197
|
- `spacingBelow` (number): Vertical space (mm) to add after the paragraph.
|
|
198
|
+
- `className` (string): CSS class names for styling (supports Tailwind and other frameworks).
|
|
199
|
+
- `style` (React.CSSProperties): Inline styles object.
|
|
128
200
|
- `showInAllPages` (boolean): Make this text appear on multiple pages.
|
|
129
201
|
- `scope` ('all' | 'first-only' | 'except-first' | number[]): Which pages to show on.
|
|
130
202
|
|
|
@@ -171,6 +243,8 @@ A robust table component designed for dynamic data.
|
|
|
171
243
|
- `cellPadding`: Default padding for cells (number or object).
|
|
172
244
|
- `striped` (boolean): Enable alternating row colors.
|
|
173
245
|
- `repeatHeader` (boolean): Repeat header on each page (default: true).
|
|
246
|
+
- `className` (string): CSS class names for styling.
|
|
247
|
+
- `style` (React.CSSProperties): Inline styles object.
|
|
174
248
|
|
|
175
249
|
**Complex Cell Example:**
|
|
176
250
|
|
|
@@ -223,6 +297,8 @@ Embed images (JPEG/PNG).
|
|
|
223
297
|
- `align` ('left' | 'center' | 'right'): Horizontal alignment (flow mode only).
|
|
224
298
|
- `layout` ('fixed' | 'flow'): Layout mode (default: 'fixed').
|
|
225
299
|
- `sizing` ('fit' | 'fill' | 'auto'): How to size the image (default: 'fit').
|
|
300
|
+
- `className` (string): CSS class names for styling.
|
|
301
|
+
- `style` (React.CSSProperties): Inline styles object.
|
|
226
302
|
- `showInAllPages` (boolean): Make this image appear on multiple pages.
|
|
227
303
|
- `scope` ('all' | 'first-only' | 'except-first' | number[]): Which pages to show on.
|
|
228
304
|
|
|
@@ -252,7 +328,8 @@ A container component for grouping content, adding borders, backgrounds, or marg
|
|
|
252
328
|
|
|
253
329
|
**Props:**
|
|
254
330
|
|
|
255
|
-
- `style`: Object with `margin`, `padding` (granular: `marginTop`, `paddingLeft` etc.), `borderWidth`, `borderColor`, `fillColor`, `radius`.
|
|
331
|
+
- `style`: Object with `margin`, `padding` (granular: `marginTop`, `paddingLeft` etc.), `borderWidth`, `borderColor`, `fillColor`, `radius`, `gap`.
|
|
332
|
+
- `className` (string): CSS class names for styling (supports gap, padding, margin, borders, backgrounds).
|
|
256
333
|
- `x`, `y`, `w`, `h`: Optional props for **absolute positioning**. If provided, the view will be placed at exactly these coordinates.
|
|
257
334
|
- `children`: Nested components to render inside the view.
|
|
258
335
|
- `showInAllPages` (boolean): Make this view appear on multiple pages.
|
|
@@ -284,6 +361,7 @@ Renders bulleted or numbered lists.
|
|
|
284
361
|
- `indent`: Number (mm) for indentation. Default 5.
|
|
285
362
|
- `markerWidth`: Number (mm) for the marker area. Default 5.
|
|
286
363
|
- `spacing`: Number (mm) for space between items. Default 2.
|
|
364
|
+
- `className` (string): CSS class names for styling list items.
|
|
287
365
|
- `style`: TextStyle object for the list items.
|
|
288
366
|
|
|
289
367
|
```tsx
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare interface BoxStyle {
|
|
|
18
18
|
paddingRight?: number;
|
|
19
19
|
paddingBottom?: number;
|
|
20
20
|
paddingLeft?: number;
|
|
21
|
+
gap?: number;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export declare interface CenterLabelOptions {
|
|
@@ -84,6 +85,8 @@ declare interface PdfImageProps {
|
|
|
84
85
|
align?: "left" | "center" | "right";
|
|
85
86
|
showInAllPages?: boolean;
|
|
86
87
|
scope?: "all" | "first-only" | "except-first" | number[];
|
|
88
|
+
className?: string;
|
|
89
|
+
style?: default_2.CSSProperties;
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
export declare const PdfList: default_2.FC<PdfListProps>;
|
|
@@ -95,6 +98,7 @@ declare interface PdfListProps {
|
|
|
95
98
|
indent?: number;
|
|
96
99
|
markerWidth?: number;
|
|
97
100
|
spacing?: number;
|
|
101
|
+
className?: string;
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
export declare interface PDFOptions {
|
|
@@ -149,7 +153,7 @@ export declare class PdfRenderer {
|
|
|
149
153
|
private footerDrawer?;
|
|
150
154
|
private pendingTasks;
|
|
151
155
|
private opQueue;
|
|
152
|
-
|
|
156
|
+
generation: number;
|
|
153
157
|
private recordingStack;
|
|
154
158
|
private recurringItems;
|
|
155
159
|
constructor(opts?: PDFOptions);
|
|
@@ -164,6 +168,15 @@ export declare class PdfRenderer {
|
|
|
164
168
|
get contentRight(): number;
|
|
165
169
|
get contentTop(): number;
|
|
166
170
|
get contentBottom(): number;
|
|
171
|
+
private indentStack;
|
|
172
|
+
private currentIndent;
|
|
173
|
+
pushIndent(left: number, right: number): void;
|
|
174
|
+
popIndent(): void;
|
|
175
|
+
/**
|
|
176
|
+
* Returns the top Y position for content on a given page, accounting for recurring items.
|
|
177
|
+
* This is useful for drawing background boxes that shouldn't overlap headers.
|
|
178
|
+
*/
|
|
179
|
+
getSafeContentTop(pageNum: number): number;
|
|
167
180
|
get contentHeight(): number;
|
|
168
181
|
get contentAreaWidth(): number;
|
|
169
182
|
get baseFont(): {
|
|
@@ -172,11 +185,14 @@ export declare class PdfRenderer {
|
|
|
172
185
|
size: number;
|
|
173
186
|
};
|
|
174
187
|
get baseLineHeight(): number;
|
|
188
|
+
private verticalPaddingStack;
|
|
189
|
+
pushVerticalPadding(top: number, bottom: number): void;
|
|
190
|
+
popVerticalPadding(): void;
|
|
191
|
+
get currentVerticalPadding(): {
|
|
192
|
+
top: number;
|
|
193
|
+
bottom: number;
|
|
194
|
+
};
|
|
175
195
|
setReservedHeight(h: number): void;
|
|
176
|
-
private indentStack;
|
|
177
|
-
private currentIndent;
|
|
178
|
-
pushIndent(left: number, right: number): void;
|
|
179
|
-
popIndent(): void;
|
|
180
196
|
resetFlowCursor(): void;
|
|
181
197
|
reset(): void;
|
|
182
198
|
setHeaderFooter(header?: (pdf: jsPDF, pageNum: number, pageCount: number, renderer: PdfRenderer) => void, footer?: (pdf: jsPDF, pageNum: number, pageCount: number, renderer: PdfRenderer) => void): void;
|
|
@@ -194,6 +210,7 @@ export declare class PdfRenderer {
|
|
|
194
210
|
h?: number;
|
|
195
211
|
mime?: "PNG" | "JPEG";
|
|
196
212
|
align?: "left" | "center" | "right";
|
|
213
|
+
radius?: number;
|
|
197
214
|
}): Promise<{
|
|
198
215
|
width: number;
|
|
199
216
|
height: number;
|
|
@@ -240,7 +257,12 @@ export declare class PdfRenderer {
|
|
|
240
257
|
y: number;
|
|
241
258
|
w: number;
|
|
242
259
|
h: number;
|
|
243
|
-
}, color: string
|
|
260
|
+
}, color: string, radius?: number | {
|
|
261
|
+
tl?: number;
|
|
262
|
+
tr?: number;
|
|
263
|
+
br?: number;
|
|
264
|
+
bl?: number;
|
|
265
|
+
}): void;
|
|
244
266
|
}
|
|
245
267
|
|
|
246
268
|
export declare const PdfTable: default_2.FC<PdfTableProps>;
|
|
@@ -263,6 +285,9 @@ declare interface PdfTableProps {
|
|
|
263
285
|
headerHeight?: number;
|
|
264
286
|
repeatHeader?: boolean;
|
|
265
287
|
striped?: boolean;
|
|
288
|
+
className?: string;
|
|
289
|
+
style?: default_2.CSSProperties;
|
|
290
|
+
stripeColor?: string;
|
|
266
291
|
}
|
|
267
292
|
|
|
268
293
|
export declare const PdfText: default_2.FC<PdfTextProps>;
|
|
@@ -273,18 +298,23 @@ declare interface PdfTextProps extends TextStyle {
|
|
|
273
298
|
y?: number;
|
|
274
299
|
maxWidth?: number;
|
|
275
300
|
spacingBelow?: number;
|
|
301
|
+
className?: string;
|
|
302
|
+
style?: default_2.CSSProperties;
|
|
276
303
|
}
|
|
277
304
|
|
|
278
305
|
export declare const PdfView: default_2.FC<PdfViewProps>;
|
|
279
306
|
|
|
280
307
|
declare interface PdfViewProps {
|
|
281
|
-
style?: ViewStyle;
|
|
308
|
+
style?: ViewStyle | default_2.CSSProperties;
|
|
309
|
+
className?: string;
|
|
282
310
|
children?: default_2.ReactNode;
|
|
283
311
|
debug?: boolean;
|
|
284
312
|
x?: number;
|
|
285
313
|
y?: number;
|
|
286
314
|
w?: number;
|
|
287
315
|
h?: number;
|
|
316
|
+
showInAllPages?: boolean;
|
|
317
|
+
scope?: "all" | "first-only" | "except-first" | number[];
|
|
288
318
|
}
|
|
289
319
|
|
|
290
320
|
declare interface TableColumn {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.pdf-preview-hidden{display:none!important}.pdf-preview-iframe{border:none}.pdf-preview-placeholder{width:100%;height:100%;display:flex;align-items:center;justify-content:center;background-color:#f3f4f6;color:#6b7280}
|