pols-pdf 1.1.2 → 1.1.4
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 +31 -9
- package/dist/index.d.ts +2 -1
- package/dist/index.js +28 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -110,7 +110,7 @@ pdf.rectangle({
|
|
|
110
110
|
pdf.cell({
|
|
111
111
|
text: 'Texto de la celda',
|
|
112
112
|
width: 200,
|
|
113
|
-
height: 40, //
|
|
113
|
+
height: 40, // opcional: si se omite, el alto se calcula según el contenido
|
|
114
114
|
padding: 6,
|
|
115
115
|
hAlign: 'center',
|
|
116
116
|
vAlign: 'center',
|
|
@@ -122,11 +122,12 @@ pdf.cell({
|
|
|
122
122
|
|
|
123
123
|
- `text` acepta `string`, `number`, `null`/`undefined`, un objeto `{ chars, font? }`, o un arreglo
|
|
124
124
|
de estos últimos para mezclar fuentes/estilos dentro de una misma celda.
|
|
125
|
-
- Una celda
|
|
126
|
-
calcula según el contenido y, si no entra en la página actual, el
|
|
127
|
-
automáticamente en una página nueva
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
- Una celda admite `height` (alto fijo) **o** `autojump` (opcional, `boolean`, por defecto `true`):
|
|
126
|
+
con `autojump` el alto se calcula según el contenido y, si no entra en la página actual, el
|
|
127
|
+
texto restante continúa automáticamente en una página nueva. Pasar `autojump: false` desactiva
|
|
128
|
+
ese salto automático (el contenido que no entre se recorta al borde de la página).
|
|
129
|
+
- Si el contenido no entra en la página (con `autojump` activo, que es el default), `cell()`
|
|
130
|
+
agrega una página nueva y continúa dibujando el resto automáticamente.
|
|
130
131
|
|
|
131
132
|
---
|
|
132
133
|
|
|
@@ -193,6 +194,25 @@ Cambia la fuente activa del documento; los métodos de texto (`cell`, `row`, `ta
|
|
|
193
194
|
aceptan `font` por llamada (y por fragmento de texto individual dentro de `text`), sin necesidad
|
|
194
195
|
de llamar a `setFont` explícitamente.
|
|
195
196
|
|
|
197
|
+
`font` se hereda en cascada — tabla → fila → celda → fragmento de texto — y cada nivel solo
|
|
198
|
+
sobrescribe las propiedades que declara explícitamente, heredando el resto del nivel anterior. Por
|
|
199
|
+
ejemplo, en:
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
pdf.table({
|
|
203
|
+
font: { size: '80%' },
|
|
204
|
+
rows: [{
|
|
205
|
+
cells: [
|
|
206
|
+
{ text: 'Solped:', font: { bold: true }, weight: 1 },
|
|
207
|
+
{ text: '12345', weight: 3 },
|
|
208
|
+
]
|
|
209
|
+
}]
|
|
210
|
+
})
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
la celda `'Solped:'` se dibuja en **negrita y al 80% del tamaño de fuente activo**: `bold: true`
|
|
214
|
+
la define la celda, pero `size: '80%'` lo hereda de la tabla porque la celda no lo redefine.
|
|
215
|
+
|
|
196
216
|
---
|
|
197
217
|
|
|
198
218
|
## Tipos con forma abreviada (`*Params`)
|
|
@@ -211,6 +231,8 @@ completo:
|
|
|
211
231
|
|
|
212
232
|
## Convención de nombres
|
|
213
233
|
|
|
214
|
-
Todas las clases y tipos exportados llevan el prefijo `P` (`PPdf`, `
|
|
215
|
-
siguiendo la convención usada en los paquetes hermanos de este ecosistema: `pols-date`
|
|
216
|
-
y `pols-utils` (`PRecord`, `PUtilsNumber`).
|
|
234
|
+
Todas las clases y tipos exportados llevan el prefijo `P` (`PPdf`, `PCellParams`, `PRowParams`,
|
|
235
|
+
etc.), siguiendo la convención usada en los paquetes hermanos de este ecosistema: `pols-date`
|
|
236
|
+
(`PDate`) y `pols-utils` (`PRecord`, `PUtilsNumber`). Los tipos ya resueltos que usa el motor de
|
|
237
|
+
layout internamente (`PCellCompiled`, `PRowCompiled`, `PTableCompiled`, etc.) llevan el sufijo
|
|
238
|
+
`Compiled` y no se exportan — no forman parte de la API pública.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import pdfkit from 'pdfkit';
|
|
1
2
|
export type PBoundParams = number | {
|
|
2
3
|
top?: number;
|
|
3
4
|
bottom?: number;
|
|
@@ -154,7 +155,7 @@ export declare class PPdf {
|
|
|
154
155
|
private static readonly lineHeightCache;
|
|
155
156
|
private cursor;
|
|
156
157
|
private configPage;
|
|
157
|
-
|
|
158
|
+
engine: typeof pdfkit;
|
|
158
159
|
template?: () => void;
|
|
159
160
|
private currentFont;
|
|
160
161
|
get title(): string;
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.PPdf = void 0;
|
|
7
7
|
const pdfkit_1 = __importDefault(require("pdfkit"));
|
|
8
8
|
const pols_utils_1 = require("pols-utils");
|
|
9
|
+
const calculateWidth = ({ width, left, pdf }) => {
|
|
10
|
+
if (width == null || width == 'auto') {
|
|
11
|
+
return pdf.engine.page.width - pdf.engine.page.margins.right - (left ?? pdf.getCursorLeftPosition());
|
|
12
|
+
}
|
|
13
|
+
else if (width == 'full') {
|
|
14
|
+
return pdf.engine.page.width - pdf.engine.page.margins.right - pdf.engine.page.margins.left;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return width;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
9
20
|
class PPdf {
|
|
10
21
|
/* Cachés de métricas de fuente, compartidas por todas las instancias: widthOfString/heightOfString
|
|
11
22
|
de pdfkit son funciones puras de (fuente, carácter) — el mismo par siempre da el mismo resultado —,
|
|
@@ -168,17 +179,11 @@ class PPdf {
|
|
|
168
179
|
return this.engine;
|
|
169
180
|
}
|
|
170
181
|
table(params) {
|
|
171
|
-
const width = (
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return this.engine.page.width - this.engine.page.margins.right - this.engine.page.margins.left;
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
return params.width;
|
|
180
|
-
}
|
|
181
|
-
})();
|
|
182
|
+
const width = calculateWidth({
|
|
183
|
+
width: params.width,
|
|
184
|
+
left: params.left,
|
|
185
|
+
pdf: this,
|
|
186
|
+
});
|
|
182
187
|
const left = params.left ?? this.cursor.left;
|
|
183
188
|
const top = params.top ?? this.cursor.top;
|
|
184
189
|
const padding = this.prepareBoundValues(params.padding);
|
|
@@ -673,7 +678,17 @@ class PPdf {
|
|
|
673
678
|
this.setCursorTopPosition(params.top + params.height);
|
|
674
679
|
}
|
|
675
680
|
cell(params) {
|
|
676
|
-
|
|
681
|
+
const width = calculateWidth({
|
|
682
|
+
width: params.width,
|
|
683
|
+
left: params.left,
|
|
684
|
+
pdf: this
|
|
685
|
+
});
|
|
686
|
+
const left = params.left ?? this.cursor.left;
|
|
687
|
+
let paramsToDraw = {
|
|
688
|
+
...params,
|
|
689
|
+
width,
|
|
690
|
+
left
|
|
691
|
+
};
|
|
677
692
|
while (paramsToDraw) {
|
|
678
693
|
const prepared = this.prepareCell(paramsToDraw);
|
|
679
694
|
this.drawCell(prepared.currentPage);
|
|
@@ -688,6 +703,7 @@ class PPdf {
|
|
|
688
703
|
paramsToDraw = null;
|
|
689
704
|
}
|
|
690
705
|
}
|
|
706
|
+
this.setCursorLeftPosition(left);
|
|
691
707
|
}
|
|
692
708
|
image(params) {
|
|
693
709
|
const options = {};
|