@pdfme/cli 6.1.1-dev.5 → 6.1.1-dev.8
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.js +6 -28
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { defineCommand, runMain } from "citty";
|
|
|
3
3
|
import { PDFDocument } from "@pdfme/pdf-lib";
|
|
4
4
|
import { generate } from "@pdfme/generator";
|
|
5
5
|
import { pdf2img, pdf2size } from "@pdfme/converter";
|
|
6
|
-
import { DEFAULT_FONT_NAME, checkGenerateProps, checkTemplate, getDefaultFont, isUrlSafeToFetch } from "@pdfme/common";
|
|
6
|
+
import { DEFAULT_FONT_NAME, PAGE_SIZE_PRESETS, checkGenerateProps, checkTemplate, detectPaperSize, getDefaultFont, isUrlSafeToFetch } from "@pdfme/common";
|
|
7
7
|
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
8
8
|
import * as schemas from "@pdfme/schemas";
|
|
9
9
|
import { accessSync, constants, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
@@ -313,22 +313,6 @@ function readPdfFile(filePath) {
|
|
|
313
313
|
});
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
|
-
var PAPER_SIZES = {
|
|
317
|
-
A3: [297, 420],
|
|
318
|
-
A4: [210, 297],
|
|
319
|
-
A5: [148, 210],
|
|
320
|
-
A6: [105, 148],
|
|
321
|
-
B4: [250, 353],
|
|
322
|
-
B5: [176, 250],
|
|
323
|
-
Letter: [216, 279],
|
|
324
|
-
Legal: [216, 356],
|
|
325
|
-
Tabloid: [279, 432]
|
|
326
|
-
};
|
|
327
|
-
function detectPaperSize(width, height) {
|
|
328
|
-
const tolerance = 2;
|
|
329
|
-
for (const [name, [w, h]] of Object.entries(PAPER_SIZES)) if (Math.abs(width - w) <= tolerance && Math.abs(height - h) <= tolerance || Math.abs(width - h) <= tolerance && Math.abs(height - w) <= tolerance) return `${name} ${width < height ? "portrait" : "landscape"}`;
|
|
330
|
-
return null;
|
|
331
|
-
}
|
|
332
316
|
function parsePageRange(rangeStr, totalPages) {
|
|
333
317
|
const pages = /* @__PURE__ */ new Set();
|
|
334
318
|
for (const part of rangeStr.split(",")) {
|
|
@@ -502,8 +486,8 @@ function validateTemplate(template) {
|
|
|
502
486
|
fields: 0
|
|
503
487
|
};
|
|
504
488
|
const totalFields = schemaPages.reduce((sum, page) => sum + page.length, 0);
|
|
505
|
-
let pageWidth =
|
|
506
|
-
let pageHeight =
|
|
489
|
+
let pageWidth = PAGE_SIZE_PRESETS.A4.width;
|
|
490
|
+
let pageHeight = PAGE_SIZE_PRESETS.A4.height;
|
|
507
491
|
if (template.basePdf && typeof template.basePdf === "object" && "width" in template.basePdf) {
|
|
508
492
|
pageWidth = template.basePdf.width;
|
|
509
493
|
pageHeight = template.basePdf.height;
|
|
@@ -1937,10 +1921,7 @@ var generate_default = defineCommand({
|
|
|
1937
1921
|
for (let i = 0; i < images.length; i++) {
|
|
1938
1922
|
const templateSchemas = template.schemas ?? [];
|
|
1939
1923
|
const pageSchemas = templateSchemas[i % templateSchemas.length] ?? [];
|
|
1940
|
-
const size = renderedPageSizes[i] ?? renderedPageSizes[0] ??
|
|
1941
|
-
width: 210,
|
|
1942
|
-
height: 297
|
|
1943
|
-
};
|
|
1924
|
+
const size = renderedPageSizes[i] ?? renderedPageSizes[0] ?? PAGE_SIZE_PRESETS.A4;
|
|
1944
1925
|
const gridImage = await drawGridOnImage(images[i], pageSchemas, gridSize, size.width, size.height, imageFormat);
|
|
1945
1926
|
writeOutput(imagePaths[i], gridImage);
|
|
1946
1927
|
}
|
|
@@ -2201,10 +2182,7 @@ var pdf2img_default = defineCommand({
|
|
|
2201
2182
|
const results = [];
|
|
2202
2183
|
for (const pageIdx of pageIndices) {
|
|
2203
2184
|
let imageData = allImages[pageIdx];
|
|
2204
|
-
const size = sizes[pageIdx] ??
|
|
2205
|
-
width: 210,
|
|
2206
|
-
height: 297
|
|
2207
|
-
};
|
|
2185
|
+
const size = sizes[pageIdx] ?? PAGE_SIZE_PRESETS.A4;
|
|
2208
2186
|
if (args.grid) imageData = await drawGridOnPdfImage(imageData, gridSize, size.width, size.height, imageFormat);
|
|
2209
2187
|
const outputPath = join(outputDir, `${inputBase}-${pageIdx + 1}.${ext}`);
|
|
2210
2188
|
writeOutput(outputPath, imageData);
|
|
@@ -2292,7 +2270,7 @@ var pdf2size_default = defineCommand({
|
|
|
2292
2270
|
});
|
|
2293
2271
|
//#endregion
|
|
2294
2272
|
//#region src/version.ts
|
|
2295
|
-
var CLI_VERSION = "6.1.1-dev.
|
|
2273
|
+
var CLI_VERSION = "6.1.1-dev.8";
|
|
2296
2274
|
//#endregion
|
|
2297
2275
|
//#region src/example-templates.ts
|
|
2298
2276
|
function getExamplesBaseUrl() {
|