pols-pdf 1.1.4 → 1.2.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/dist/index.d.ts +10 -1
- package/dist/index.js +28 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -31,10 +31,17 @@ export type PBorderColorParams = string | {
|
|
|
31
31
|
left?: string;
|
|
32
32
|
leftTop?: string;
|
|
33
33
|
};
|
|
34
|
+
export type PPageMarginsParams = number | {
|
|
35
|
+
top?: number;
|
|
36
|
+
bottom?: number;
|
|
37
|
+
left?: number;
|
|
38
|
+
right?: number;
|
|
39
|
+
show?: boolean;
|
|
40
|
+
};
|
|
34
41
|
export type PPage = {
|
|
35
42
|
size: 'A4' | 'LETTER';
|
|
36
43
|
layout: 'portrait' | 'landscape';
|
|
37
|
-
margins:
|
|
44
|
+
margins: PPageMarginsParams;
|
|
38
45
|
};
|
|
39
46
|
export type PFont = {
|
|
40
47
|
name: string;
|
|
@@ -176,6 +183,7 @@ export declare class PPdf {
|
|
|
176
183
|
addFirstPage?: boolean;
|
|
177
184
|
});
|
|
178
185
|
addPage(config?: Partial<PPage>): void;
|
|
186
|
+
private drawMarginLines;
|
|
179
187
|
rectangleTo(params: Omit<PRectangle, 'width' | 'height'>): void;
|
|
180
188
|
rectangle(params: PRectangle): void;
|
|
181
189
|
build(): PDFKit.PDFDocument;
|
|
@@ -198,6 +206,7 @@ export declare class PPdf {
|
|
|
198
206
|
cell(params: PCellParams): void;
|
|
199
207
|
image(params: PImage): void;
|
|
200
208
|
private prepareBoundValues;
|
|
209
|
+
private prepareMarginsValues;
|
|
201
210
|
private prepareRadiusValues;
|
|
202
211
|
private prepareBorderValues;
|
|
203
212
|
private prepareBorderColorValues;
|
package/dist/index.js
CHANGED
|
@@ -95,11 +95,12 @@ class PPdf {
|
|
|
95
95
|
size: 'A4',
|
|
96
96
|
layout: 'portrait',
|
|
97
97
|
...(params?.page ?? {}),
|
|
98
|
-
margins: this.
|
|
98
|
+
margins: this.prepareMarginsValues(params?.page?.margins, {
|
|
99
99
|
left: 20,
|
|
100
100
|
top: 20,
|
|
101
101
|
right: 20,
|
|
102
|
-
bottom: 20
|
|
102
|
+
bottom: 20,
|
|
103
|
+
show: false
|
|
103
104
|
})
|
|
104
105
|
};
|
|
105
106
|
if (params?.addFirstPage == null || params.addFirstPage)
|
|
@@ -109,18 +110,25 @@ class PPdf {
|
|
|
109
110
|
const finalConfig = {
|
|
110
111
|
...this.configPage,
|
|
111
112
|
...(config ?? {}),
|
|
112
|
-
margins: this.
|
|
113
|
-
left: 20,
|
|
114
|
-
top: 20,
|
|
115
|
-
right: 20,
|
|
116
|
-
bottom: 20
|
|
117
|
-
})
|
|
113
|
+
margins: this.prepareMarginsValues(config?.margins ?? this.configPage.margins, this.configPage.margins)
|
|
118
114
|
};
|
|
119
115
|
this.engine.addPage(finalConfig);
|
|
120
116
|
this.configPage = finalConfig;
|
|
121
117
|
this.cursor.top = finalConfig.margins.top;
|
|
118
|
+
this.drawMarginLines();
|
|
122
119
|
this.template?.();
|
|
123
120
|
}
|
|
121
|
+
/* Dibuja líneas grises en los márgenes de la hoja actual, sin alterar el cursor */
|
|
122
|
+
drawMarginLines() {
|
|
123
|
+
if (!this.configPage.margins.show)
|
|
124
|
+
return;
|
|
125
|
+
const left = this.configPage.margins.left;
|
|
126
|
+
const top = this.configPage.margins.top;
|
|
127
|
+
const right = this.engine.page.width - this.configPage.margins.right;
|
|
128
|
+
const bottom = this.engine.page.height - this.configPage.margins.bottom;
|
|
129
|
+
this.engine.lineWidth(0.5);
|
|
130
|
+
this.engine.path(`M${left},${top} L${right},${top} L${right},${bottom} L${left},${bottom} Z`).stroke('#999999');
|
|
131
|
+
}
|
|
124
132
|
rectangleTo(params) {
|
|
125
133
|
this.rectangle({
|
|
126
134
|
...params,
|
|
@@ -374,6 +382,9 @@ class PPdf {
|
|
|
374
382
|
if (value == 'left') {
|
|
375
383
|
n = this.engine.page.margins.left;
|
|
376
384
|
}
|
|
385
|
+
else if (value < 0) {
|
|
386
|
+
n = this.engine.page.width + value;
|
|
387
|
+
}
|
|
377
388
|
else {
|
|
378
389
|
n = value;
|
|
379
390
|
}
|
|
@@ -389,6 +400,9 @@ class PPdf {
|
|
|
389
400
|
if (value == 'top') {
|
|
390
401
|
n = this.engine.page.margins.top;
|
|
391
402
|
}
|
|
403
|
+
else if (value < 0) {
|
|
404
|
+
n = this.engine.page.height + value;
|
|
405
|
+
}
|
|
392
406
|
else {
|
|
393
407
|
n = value;
|
|
394
408
|
}
|
|
@@ -757,6 +771,12 @@ class PPdf {
|
|
|
757
771
|
return defa;
|
|
758
772
|
}
|
|
759
773
|
}
|
|
774
|
+
prepareMarginsValues(value, defa) {
|
|
775
|
+
return {
|
|
776
|
+
...this.prepareBoundValues(value, defa),
|
|
777
|
+
show: (typeof value == 'object' ? value.show : undefined) ?? defa.show,
|
|
778
|
+
};
|
|
779
|
+
}
|
|
760
780
|
prepareRadiusValues(value, defa = {
|
|
761
781
|
leftTop: 0,
|
|
762
782
|
leftBottom: 0,
|