renderpdf-js 0.2.0 → 0.3.0
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/API.md +204 -0
- package/README.md +275 -307
- package/dist/compose-pdf.d.ts +26 -0
- package/dist/document-colors.d.ts +8 -0
- package/dist/document-page.d.ts +115 -0
- package/dist/document-types.d.ts +135 -0
- package/dist/document.d.ts +64 -0
- package/dist/fonts.d.ts +4 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2051 -552
- package/dist/jspdf-adapter.d.ts +159 -0
- package/package.json +8 -3
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { type PDFBuilder } from './document.js';
|
|
2
|
+
import type { DocumentImageSource, DocumentPageOptions, PDFDocumentOptions } from './document-types.js';
|
|
3
|
+
import type { RenderPDFResult } from './api-types.js';
|
|
4
|
+
/** Prepared font descriptor consumed by DevExtreme's synchronous PDF exporter. */
|
|
5
|
+
export interface JsPDFAdapterFont {
|
|
6
|
+
readonly fontName: string;
|
|
7
|
+
readonly fontStyle: 'normal' | 'bold' | 'italic' | 'bolditalic';
|
|
8
|
+
readonly fontWeight: number;
|
|
9
|
+
}
|
|
10
|
+
/** Supported text placement; complex scripts and advanced jsPDF transforms are outside this adapter. */
|
|
11
|
+
export interface JsPDFAdapterTextOptions {
|
|
12
|
+
align?: 'left' | 'center' | 'right';
|
|
13
|
+
baseline?: 'alphabetic' | 'top' | 'middle' | 'bottom' | 'hanging' | 'ideographic';
|
|
14
|
+
angle?: number;
|
|
15
|
+
/** jsPDF uses counterclockwise angles by default; zero selects clockwise rotation. */
|
|
16
|
+
rotationDirection?: 0 | 1;
|
|
17
|
+
lineHeightFactor?: number;
|
|
18
|
+
maxWidth?: number;
|
|
19
|
+
isInputVisual?: boolean;
|
|
20
|
+
isOutputVisual?: boolean;
|
|
21
|
+
isInputRtl?: boolean;
|
|
22
|
+
isOutputRtl?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** Explicit font overrides used by the exporter's text measurement calls. */
|
|
25
|
+
export interface JsPDFAdapterMeasureOptions {
|
|
26
|
+
font?: JsPDFAdapterFont;
|
|
27
|
+
fontName?: string;
|
|
28
|
+
fontStyle?: string;
|
|
29
|
+
fontSize?: number;
|
|
30
|
+
maxWidth?: number;
|
|
31
|
+
}
|
|
32
|
+
type ColorChannel = number | string;
|
|
33
|
+
/** Narrow color-normalization contract used by DevExtreme 25.1. */
|
|
34
|
+
export interface JsPDFAdapterColorOptions {
|
|
35
|
+
ch1: ColorChannel;
|
|
36
|
+
ch2?: ColorChannel;
|
|
37
|
+
ch3?: ColorChannel;
|
|
38
|
+
ch4?: ColorChannel;
|
|
39
|
+
precision?: number;
|
|
40
|
+
pdfColorType?: string;
|
|
41
|
+
}
|
|
42
|
+
/** Parse a PDF color token, or an already canonical CSS color, into RGB hex. */
|
|
43
|
+
declare function decodeColor(token: string): string;
|
|
44
|
+
/** Normalize supported jsPDF grayscale, RGB and CMYK channels without vendor code. */
|
|
45
|
+
declare function encodeColor(options: JsPDFAdapterColorOptions | string): string;
|
|
46
|
+
/** A prepared, scoped facade for DevExtreme 25.1; serialization is explicitly asynchronous. */
|
|
47
|
+
export declare class JsPDFAdapter {
|
|
48
|
+
private readonly document;
|
|
49
|
+
/** jsPDF-compatible units and current page dimensions used by DevExtreme. */
|
|
50
|
+
readonly internal: {
|
|
51
|
+
readonly scaleFactor: number;
|
|
52
|
+
readonly pageSize: {
|
|
53
|
+
getWidth(): number;
|
|
54
|
+
getHeight(): number;
|
|
55
|
+
};
|
|
56
|
+
getNumberOfPages(): number;
|
|
57
|
+
};
|
|
58
|
+
/** DevExtreme's bounded private color bridge; unrelated jsPDF internals are unsupported. */
|
|
59
|
+
readonly __private__: Readonly<{
|
|
60
|
+
encodeColorString: typeof encodeColor;
|
|
61
|
+
decodeColorString: typeof decodeColor;
|
|
62
|
+
}>;
|
|
63
|
+
private currentPage;
|
|
64
|
+
private state;
|
|
65
|
+
private readonly commands;
|
|
66
|
+
private readonly savedStates;
|
|
67
|
+
private readonly activePaths;
|
|
68
|
+
private completion?;
|
|
69
|
+
/** Construct through createJsPDFAdapter so fonts exist before synchronous export begins. */
|
|
70
|
+
constructor(document: PDFBuilder);
|
|
71
|
+
/** Reject drawing after serialization starts, preserving a deterministic snapshot. */
|
|
72
|
+
private assertMutable;
|
|
73
|
+
/** Record paint in order so asynchronous image embedding cannot move it above later text. */
|
|
74
|
+
private enqueue;
|
|
75
|
+
/** Select a prepared face and validate it through the core's synchronous metrics. */
|
|
76
|
+
getFont(name?: string | null, style?: string | null): JsPDFAdapterFont;
|
|
77
|
+
/** Select a preloaded face; load custom bytes in the factory's fonts option. */
|
|
78
|
+
setFont(name: string, style?: string, weight?: number): this;
|
|
79
|
+
/** Set typographic points independently of the document's coordinate unit. */
|
|
80
|
+
setFontSize(size: number): this;
|
|
81
|
+
/** Return the current point size. */
|
|
82
|
+
getFontSize(): number;
|
|
83
|
+
/** Set the baseline-to-baseline font-size multiplier. */
|
|
84
|
+
setLineHeightFactor(value: number): this;
|
|
85
|
+
/** Return the current baseline spacing multiplier. */
|
|
86
|
+
getLineHeightFactor(): number;
|
|
87
|
+
/** Set border width in document coordinates. */
|
|
88
|
+
setLineWidth(width: number): this;
|
|
89
|
+
/** Return border width in document coordinates. */
|
|
90
|
+
getLineWidth(): number;
|
|
91
|
+
/** Normalize a color to the same representation returned by the private bridge. */
|
|
92
|
+
private color;
|
|
93
|
+
/** Set text color from gray, RGB, CMYK or a supported CSS color. */
|
|
94
|
+
setTextColor(ch1: ColorChannel, ch2?: ColorChannel, ch3?: ColorChannel, ch4?: ColorChannel): this;
|
|
95
|
+
/** Return normalized text color. */
|
|
96
|
+
getTextColor(): string;
|
|
97
|
+
/** Set stroke color. */
|
|
98
|
+
setDrawColor(ch1: ColorChannel, ch2?: ColorChannel, ch3?: ColorChannel, ch4?: ColorChannel): this;
|
|
99
|
+
/** Return normalized stroke color. */
|
|
100
|
+
getDrawColor(): string;
|
|
101
|
+
/** Set fill color. */
|
|
102
|
+
setFillColor(ch1: ColorChannel, ch2?: ColorChannel, ch3?: ColorChannel, ch4?: ColorChannel): this;
|
|
103
|
+
/** Return normalized fill color. */
|
|
104
|
+
getFillColor(): string;
|
|
105
|
+
/** Measure width and jsPDF-style line height synchronously in document units. */
|
|
106
|
+
getTextDimensions(text: string | number | readonly string[], options?: JsPDFAdapterMeasureOptions): {
|
|
107
|
+
w: number;
|
|
108
|
+
h: number;
|
|
109
|
+
};
|
|
110
|
+
/** Return the current face's text width. */
|
|
111
|
+
getTextWidth(text: string): number;
|
|
112
|
+
/** Wrap by measured words, splitting oversized words without losing characters. */
|
|
113
|
+
splitTextToSize(text: string | number | readonly string[], width: number, options?: JsPDFAdapterMeasureOptions): string[];
|
|
114
|
+
/** Position text using the supported alignment and baseline options. */
|
|
115
|
+
text(text: string | readonly string[], x: number, y: number, options?: JsPDFAdapterTextOptions): this;
|
|
116
|
+
/** Paint one stroke with the current line state. */
|
|
117
|
+
line(x1: number, y1: number, x2: number, y2: number): this;
|
|
118
|
+
/** Paint a rectangle; path-only styles are outside the exporter contract. */
|
|
119
|
+
rect(x: number, y: number, width: number, height: number, style?: string): this;
|
|
120
|
+
/** Preserve both PDF graphics and adapter style state. */
|
|
121
|
+
saveGraphicsState(): this;
|
|
122
|
+
/** Restore a state saved on this same page. */
|
|
123
|
+
restoreGraphicsState(): this;
|
|
124
|
+
/** Begin a clipping path in document coordinates. */
|
|
125
|
+
moveTo(x: number, y: number): this;
|
|
126
|
+
/** Append one path segment. */
|
|
127
|
+
lineTo(x: number, y: number): this;
|
|
128
|
+
/** Close the current path; this is not a document-disposal operation. */
|
|
129
|
+
close(): this;
|
|
130
|
+
/** Apply the current path as a clip. */
|
|
131
|
+
clip(): this;
|
|
132
|
+
/** Clear the current path after clipping. */
|
|
133
|
+
discardPath(): this;
|
|
134
|
+
/** Add a page using jsPDF's array format and optional orientation shorthand. */
|
|
135
|
+
addPage(format?: DocumentPageOptions['format'] | readonly [number, number], orientation?: 'p' | 'l' | 'portrait' | 'landscape'): this;
|
|
136
|
+
/** Select an existing one-based page for later footer and title paint. */
|
|
137
|
+
setPage(pageNumber: number): this;
|
|
138
|
+
/** Return the total number of pages already added. */
|
|
139
|
+
getNumberOfPages(): number;
|
|
140
|
+
/** Queue image placement without allowing asynchronous embedding to reorder paint. */
|
|
141
|
+
addImage(source: DocumentImageSource, format: string, x: number, y: number, width: number, height: number): this;
|
|
142
|
+
/** Flush ordered drawing once and return the immutable common PDF result. */
|
|
143
|
+
toResult(): Promise<RenderPDFResult>;
|
|
144
|
+
/** Return an asynchronously finalized PDF Blob. */
|
|
145
|
+
toBlob(): Promise<Blob>;
|
|
146
|
+
/** Return independent PDF bytes. */
|
|
147
|
+
toUint8Array(): Promise<Uint8Array>;
|
|
148
|
+
/** Save asynchronously; callers must await this method. */
|
|
149
|
+
save(filename?: string): Promise<void>;
|
|
150
|
+
/** Download alias matching the library's result API. */
|
|
151
|
+
download(filename?: string): Promise<void>;
|
|
152
|
+
/** Unlike jsPDF, every output form returns a Promise and must be awaited. */
|
|
153
|
+
output(type: 'blob'): Promise<Blob>;
|
|
154
|
+
output(type: 'arraybuffer'): Promise<ArrayBuffer>;
|
|
155
|
+
output(type: 'uint8array'): Promise<Uint8Array>;
|
|
156
|
+
}
|
|
157
|
+
/** Prepare fonts and millimeter coordinates before passing the facade as jsPDFDocument. */
|
|
158
|
+
export declare function createJsPDFAdapter(options?: PDFDocumentOptions): Promise<JsPDFAdapter>;
|
|
159
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "renderpdf-js",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Create PDFs from HTML, images or code, and merge or split existing PDFs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
"typescript",
|
|
19
19
|
"html-to-pdf",
|
|
20
20
|
"image-to-pdf",
|
|
21
|
-
"tiff-to-pdf"
|
|
21
|
+
"tiff-to-pdf",
|
|
22
|
+
"pdf-generation",
|
|
23
|
+
"pdf-merge",
|
|
24
|
+
"pdf-split"
|
|
22
25
|
],
|
|
23
26
|
"publishConfig": {
|
|
24
27
|
"access": "public",
|
|
@@ -37,6 +40,7 @@
|
|
|
37
40
|
"dist/index.js",
|
|
38
41
|
"dist/*.d.ts",
|
|
39
42
|
"README.md",
|
|
43
|
+
"API.md",
|
|
40
44
|
"LICENSE",
|
|
41
45
|
"assets/renderpdf-logo.png"
|
|
42
46
|
],
|
|
@@ -52,6 +56,7 @@
|
|
|
52
56
|
"typecheck": "vp check --no-fmt --no-lint",
|
|
53
57
|
"test": "vp test",
|
|
54
58
|
"test:browser": "playwright test",
|
|
59
|
+
"test:devextreme": "playwright test --config playwright.devextreme.config.ts",
|
|
55
60
|
"benchmark": "npm run build:library && playwright test --config playwright.benchmark.config.ts",
|
|
56
61
|
"lint": "vp lint",
|
|
57
62
|
"format": "vp fmt",
|