@pdfme/cli 6.1.1 → 6.1.2-dev.13
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/example-templates.d.ts +5 -0
- package/dist/index.js +16 -31
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/package.json +1 -1
|
@@ -3,12 +3,17 @@ export interface ExampleManifestEntry {
|
|
|
3
3
|
author: string;
|
|
4
4
|
path: string;
|
|
5
5
|
thumbnailPath: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
order?: number;
|
|
6
8
|
pageCount: number;
|
|
7
9
|
fieldCount: number;
|
|
8
10
|
schemaTypes: string[];
|
|
9
11
|
fontNames: string[];
|
|
10
12
|
hasCJK: boolean;
|
|
11
13
|
basePdfKind: string;
|
|
14
|
+
sourceKind?: string;
|
|
15
|
+
tags?: string[];
|
|
16
|
+
title?: string;
|
|
12
17
|
}
|
|
13
18
|
export interface ExampleManifest {
|
|
14
19
|
schemaVersion: number;
|
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.
|
|
2273
|
+
var CLI_VERSION = "6.1.2-dev.13";
|
|
2296
2274
|
//#endregion
|
|
2297
2275
|
//#region src/example-templates.ts
|
|
2298
2276
|
function getExamplesBaseUrl() {
|
|
@@ -2355,12 +2333,17 @@ function normalizeEntries(rawTemplates) {
|
|
|
2355
2333
|
author: typeof entry.author === "string" && entry.author.length > 0 ? entry.author : "pdfme",
|
|
2356
2334
|
path: typeof entry.path === "string" && entry.path.length > 0 ? entry.path : `${name}/template.json`,
|
|
2357
2335
|
thumbnailPath: typeof entry.thumbnailPath === "string" && entry.thumbnailPath.length > 0 ? entry.thumbnailPath : `${name}/thumbnail.png`,
|
|
2336
|
+
...typeof entry.description === "string" ? { description: entry.description } : {},
|
|
2337
|
+
...typeof entry.order === "number" && Number.isFinite(entry.order) ? { order: entry.order } : {},
|
|
2358
2338
|
pageCount: typeof entry.pageCount === "number" && Number.isFinite(entry.pageCount) ? entry.pageCount : 0,
|
|
2359
2339
|
fieldCount: typeof entry.fieldCount === "number" && Number.isFinite(entry.fieldCount) ? entry.fieldCount : 0,
|
|
2360
2340
|
schemaTypes: normalizeStringArray(entry.schemaTypes),
|
|
2361
2341
|
fontNames: normalizeStringArray(entry.fontNames),
|
|
2362
2342
|
hasCJK: typeof entry.hasCJK === "boolean" ? entry.hasCJK : false,
|
|
2363
|
-
basePdfKind: typeof entry.basePdfKind === "string" && entry.basePdfKind.length > 0 ? entry.basePdfKind : "unknown"
|
|
2343
|
+
basePdfKind: typeof entry.basePdfKind === "string" && entry.basePdfKind.length > 0 ? entry.basePdfKind : "unknown",
|
|
2344
|
+
...typeof entry.sourceKind === "string" ? { sourceKind: entry.sourceKind } : {},
|
|
2345
|
+
...Array.isArray(entry.tags) ? { tags: normalizeStringArray(entry.tags) } : {},
|
|
2346
|
+
...typeof entry.title === "string" ? { title: entry.title } : {}
|
|
2364
2347
|
};
|
|
2365
2348
|
}).filter((entry) => entry.name.length > 0);
|
|
2366
2349
|
}
|
|
@@ -2448,8 +2431,10 @@ function generateSampleInputs(template) {
|
|
|
2448
2431
|
if (typeof schema !== "object" || schema === null) continue;
|
|
2449
2432
|
const name = schema.name;
|
|
2450
2433
|
const content = schema.content;
|
|
2451
|
-
|
|
2452
|
-
|
|
2434
|
+
const readOnly = schema.readOnly;
|
|
2435
|
+
const type = schema.type;
|
|
2436
|
+
if (readOnly) continue;
|
|
2437
|
+
if (name) input[name] = content || (type === "image" || type === "signature" ? "" : `Sample ${name}`);
|
|
2453
2438
|
}
|
|
2454
2439
|
return [input];
|
|
2455
2440
|
}
|