jspdf-utils 0.1.29 → 0.2.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 CHANGED
@@ -17,7 +17,7 @@ npm install jspdf-utils jspdf html2canvas-pro
17
17
  - `previewImages(source, container, opts)`
18
18
  - `PAGE_SIZES`
19
19
  - `PAGE_MARGINS`
20
- - Types: `PageOptions`, `PageOptionsInput`, `ImagePDFOptions`
20
+ - Types: `PageOptions`, `PageOptionsInput`, `ImagePDFOptions`, `MarginContentInput`, `Border`, `TextBorder`
21
21
 
22
22
  Type import example:
23
23
 
@@ -106,6 +106,8 @@ Important:
106
106
  - `imageQuality?: number`
107
107
  - `scale?: number`
108
108
  - `marginContent?: MarginContentInput`
109
+ - `border?: Border`
110
+ - `textBorder?: TextBorder`
109
111
  - `forcedPageCount?: number`
110
112
 
111
113
  `forcedPageCount` behavior:
@@ -118,18 +120,42 @@ Important:
118
120
 
119
121
  ## Margin Content and Borders
120
122
 
121
- `marginContent` supports:
123
+ `marginContent`, `border`, and `textBorder` are independent, top-level page
124
+ options. Each has its own `margin` property that controls its distance from the
125
+ page edge, fully decoupled from the main `margin` (which only controls where
126
+ the HTML content is placed).
122
127
 
123
- - `top`, `right`, `bottom`, `left` as:
124
- - `HTMLElement`, or
125
- - `(page: number, totalPages: number) => HTMLElement`
126
- - `contentBorder` (vector rectangle)
127
- - `textBorder` (repeated text around page edges)
128
+ ### `MarginContentInput`
128
129
 
129
- Rendering order:
130
+ - `top`, `right`, `bottom`, `left` — each accepts:
131
+ - `HTMLElement` or `string` (static, rendered once and reused), or
132
+ - `(page: number, totalPages: number) => HTMLElement | string` (per-page)
133
+ - `margin?` — distance in mm from the page edge to the content area (default: format default margin)
130
134
 
131
- - Margin content and borders are rendered beneath page content.
132
- - Main document content stays visually above borders/text borders.
135
+ ### `Border`
136
+
137
+ Draws a vector rectangle around the page.
138
+
139
+ - `color?: string` (default: `"#000000"`)
140
+ - `width?: number` — line width in mm (default: `0.3`)
141
+ - `margin?` — distance in mm from the page edge to the border (default: page margin)
142
+
143
+ ### `TextBorder`
144
+
145
+ Draws repeated text along all four page edges.
146
+
147
+ - `text: string` — the text to repeat
148
+ - `color?: string` (default: `"#000000"`)
149
+ - `fontSize?: number` — in mm (default: `2.5`)
150
+ - `fontFamily?: string` (default: `"Arial, sans-serif"`)
151
+ - `fontWeight?: string` (default: `"normal"`)
152
+ - `gap?: number` — gap between repetitions in mm (default: `fontSize * 0.5`)
153
+ - `margin?` — distance in mm from the page edge to the text border (default: page margin)
154
+
155
+ ### Rendering order
156
+
157
+ - Margin content, borders, and text borders are rendered beneath page content.
158
+ - Main document content stays visually above them.
133
159
 
134
160
  ## Development
135
161
 
@@ -48,9 +48,10 @@ export interface PrepareResult {
48
48
  /**
49
49
  * Render an HTML element to PDF using doc.html().
50
50
  */
51
- declare function generatePDF(doc: jsPDF, source: HTMLElement, opts?: PageOptionsInput & Pick<ImagePDFOptions, "marginContent" | "forcedPageCount">): Promise<jsPDF>;
52
- type MarginFactory = (page: number, totalPages: number) => HTMLElement;
53
- export interface ContentBorder {
51
+ declare function generatePDF(doc: jsPDF, source: HTMLElement, opts?: PageOptionsInput & Pick<ImagePDFOptions, "marginContent" | "forcedPageCount" | "textBorder" | "border">): Promise<jsPDF>;
52
+ type MarginResult = HTMLElement | string | null | undefined | void;
53
+ type MarginFactory = (page: number, totalPages: number) => MarginResult;
54
+ export interface Border {
54
55
  /** Stroke color (default: "#000000") */
55
56
  color?: string;
56
57
  /** Line width in mm (default: 0.3) */
@@ -85,20 +86,27 @@ export interface TextBorder {
85
86
  };
86
87
  }
87
88
  export interface MarginContentInput {
88
- top?: HTMLElement | MarginFactory;
89
- right?: HTMLElement | MarginFactory;
90
- bottom?: HTMLElement | MarginFactory;
91
- left?: HTMLElement | MarginFactory;
92
- /** Draw a rectangle border around the content area. */
93
- contentBorder?: ContentBorder;
94
- /** Draw a repeated-text border around the content area. */
95
- textBorder?: TextBorder;
89
+ top?: HTMLElement | string | MarginFactory;
90
+ right?: HTMLElement | string | MarginFactory;
91
+ bottom?: HTMLElement | string | MarginFactory;
92
+ left?: HTMLElement | string | MarginFactory;
93
+ /** Distance in mm from the page edge to the margin content area (default: uses page margins). */
94
+ margin?: number | {
95
+ top?: number;
96
+ right?: number;
97
+ bottom?: number;
98
+ left?: number;
99
+ };
96
100
  }
97
101
  export interface ImagePDFOptions {
98
102
  imageFormat?: "JPEG" | "PNG";
99
103
  imageQuality?: number;
100
104
  scale?: number;
101
105
  marginContent?: MarginContentInput;
106
+ /** Draw a rectangle border around the content area. */
107
+ border?: Border;
108
+ /** Draw a repeated-text border around the content area. */
109
+ textBorder?: TextBorder;
102
110
  /**
103
111
  * Force output to the first N pages only.
104
112
  * Example: 1 means only page 1 is generated/exported.