@pdfme/generator 2.1.0 → 2.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 +6 -2
- package/dist/cjs/__tests__/assets/templates/index.js +6 -0
- package/dist/cjs/__tests__/assets/templates/index.js.map +1 -1
- package/dist/cjs/__tests__/generate.test.js +6 -0
- package/dist/cjs/__tests__/generate.test.js.map +1 -1
- package/dist/cjs/src/builtInRenderer.js +9 -0
- package/dist/cjs/src/builtInRenderer.js.map +1 -0
- package/dist/cjs/src/generate.js +29 -30
- package/dist/cjs/src/generate.js.map +1 -1
- package/dist/cjs/src/pdfUtils.js +65 -0
- package/dist/cjs/src/pdfUtils.js.map +1 -0
- package/dist/cjs/src/renderUtils.js +65 -0
- package/dist/cjs/src/renderUtils.js.map +1 -0
- package/dist/cjs/src/renders/barcodes.js +37 -0
- package/dist/cjs/src/renders/barcodes.js.map +1 -0
- package/dist/cjs/src/renders/image.js +34 -0
- package/dist/cjs/src/renders/image.js.map +1 -0
- package/dist/cjs/src/renders/text.js +86 -0
- package/dist/cjs/src/renders/text.js.map +1 -0
- package/dist/cjs/src/types.js +3 -0
- package/dist/cjs/src/types.js.map +1 -0
- package/dist/esm/__tests__/assets/templates/index.js +6 -0
- package/dist/esm/__tests__/assets/templates/index.js.map +1 -1
- package/dist/esm/__tests__/generate.test.js +6 -0
- package/dist/esm/__tests__/generate.test.js.map +1 -1
- package/dist/esm/src/builtInRenderer.js +7 -0
- package/dist/esm/src/builtInRenderer.js.map +1 -0
- package/dist/esm/src/generate.js +23 -27
- package/dist/esm/src/generate.js.map +1 -1
- package/dist/esm/src/pdfUtils.js +59 -0
- package/dist/esm/src/pdfUtils.js.map +1 -0
- package/dist/esm/src/renderUtils.js +56 -0
- package/dist/esm/src/renderUtils.js.map +1 -0
- package/dist/esm/src/renders/barcodes.js +33 -0
- package/dist/esm/src/renders/barcodes.js.map +1 -0
- package/dist/esm/src/renders/image.js +30 -0
- package/dist/esm/src/renders/image.js.map +1 -0
- package/dist/esm/src/renders/text.js +82 -0
- package/dist/esm/src/renders/text.js.map +1 -0
- package/dist/esm/src/types.js +2 -0
- package/dist/esm/src/types.js.map +1 -0
- package/dist/types/__tests__/assets/templates/index.d.ts +311 -0
- package/dist/types/src/builtInRenderer.d.ts +3 -0
- package/dist/types/src/pdfUtils.d.ts +19 -0
- package/dist/types/src/renderUtils.d.ts +16 -0
- package/dist/types/src/renders/barcodes.d.ts +2 -0
- package/dist/types/src/renders/image.d.ts +2 -0
- package/dist/types/src/renders/text.d.ts +2 -0
- package/dist/types/src/types.d.ts +36 -0
- package/package.json +2 -7
- package/src/builtInRenderer.ts +14 -0
- package/src/generate.ts +28 -46
- package/src/pdfUtils.ts +76 -0
- package/src/renderUtils.ts +68 -0
- package/src/renders/barcodes.ts +32 -0
- package/src/renders/image.ts +24 -0
- package/src/renders/text.ts +114 -0
- package/src/types.ts +23 -0
- package/dist/cjs/__tests__/helper.test.js +0 -53
- package/dist/cjs/__tests__/helper.test.js.map +0 -1
- package/dist/cjs/src/helper.js +0 -252
- package/dist/cjs/src/helper.js.map +0 -1
- package/dist/esm/__tests__/helper.test.js +0 -48
- package/dist/esm/__tests__/helper.test.js.map +0 -1
- package/dist/esm/src/helper.js +0 -241
- package/dist/esm/src/helper.js.map +0 -1
- package/dist/types/__tests__/helper.test.d.ts +0 -1
- package/dist/types/src/helper.d.ts +0 -67
- package/src/helper.ts +0 -375
@@ -1,67 +0,0 @@
|
|
1
|
-
import { PDFPage, PDFFont, PDFDocument, PDFImage, PDFEmbeddedPage } from '@pdfme/pdf-lib';
|
2
|
-
import { Schema, Font, BasePdf, BarCodeType } from '@pdfme/common';
|
3
|
-
import { Buffer } from 'buffer';
|
4
|
-
export interface InputImageCache {
|
5
|
-
[key: string]: PDFImage | undefined;
|
6
|
-
}
|
7
|
-
export declare const createBarCode: (arg: {
|
8
|
-
type: BarCodeType;
|
9
|
-
input: string;
|
10
|
-
width: number;
|
11
|
-
height: number;
|
12
|
-
backgroundColor?: string;
|
13
|
-
}) => Promise<Buffer>;
|
14
|
-
declare type EmbedPdfBox = {
|
15
|
-
mediaBox: {
|
16
|
-
x: number;
|
17
|
-
y: number;
|
18
|
-
width: number;
|
19
|
-
height: number;
|
20
|
-
};
|
21
|
-
bleedBox: {
|
22
|
-
x: number;
|
23
|
-
y: number;
|
24
|
-
width: number;
|
25
|
-
height: number;
|
26
|
-
};
|
27
|
-
trimBox: {
|
28
|
-
x: number;
|
29
|
-
y: number;
|
30
|
-
width: number;
|
31
|
-
height: number;
|
32
|
-
};
|
33
|
-
};
|
34
|
-
export declare const embedAndGetFontObj: (arg: {
|
35
|
-
pdfDoc: PDFDocument;
|
36
|
-
font: Font;
|
37
|
-
}) => Promise<{
|
38
|
-
[key: string]: PDFFont;
|
39
|
-
}>;
|
40
|
-
export declare const getEmbeddedPagesAndEmbedPdfBoxes: (arg: {
|
41
|
-
pdfDoc: PDFDocument;
|
42
|
-
basePdf: BasePdf;
|
43
|
-
}) => Promise<{
|
44
|
-
embeddedPages: PDFEmbeddedPage[];
|
45
|
-
embedPdfBoxes: EmbedPdfBox[];
|
46
|
-
}>;
|
47
|
-
interface FontSetting {
|
48
|
-
font: Font;
|
49
|
-
pdfFontObj: {
|
50
|
-
[key: string]: PDFFont;
|
51
|
-
};
|
52
|
-
fallbackFontName: string;
|
53
|
-
}
|
54
|
-
export declare const drawInputByTemplateSchema: (arg: {
|
55
|
-
input: string;
|
56
|
-
templateSchema: Schema;
|
57
|
-
pdfDoc: PDFDocument;
|
58
|
-
page: PDFPage;
|
59
|
-
fontSetting: FontSetting;
|
60
|
-
inputImageCache: InputImageCache;
|
61
|
-
}) => Promise<void>;
|
62
|
-
export declare const drawEmbeddedPage: (arg: {
|
63
|
-
page: PDFPage;
|
64
|
-
embeddedPage: PDFEmbeddedPage;
|
65
|
-
embedPdfBox: EmbedPdfBox;
|
66
|
-
}) => void;
|
67
|
-
export {};
|
package/src/helper.ts
DELETED
@@ -1,375 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
PDFPage,
|
3
|
-
PDFFont,
|
4
|
-
PDFDocument,
|
5
|
-
PDFImage,
|
6
|
-
PDFEmbeddedPage,
|
7
|
-
rgb,
|
8
|
-
degrees,
|
9
|
-
setCharacterSpacing,
|
10
|
-
TransformationMatrix,
|
11
|
-
} from '@pdfme/pdf-lib';
|
12
|
-
import bwipjs, { ToBufferOptions } from 'bwip-js';
|
13
|
-
import {
|
14
|
-
getB64BasePdf,
|
15
|
-
b64toUint8Array,
|
16
|
-
validateBarcodeInput,
|
17
|
-
Schema,
|
18
|
-
TextSchema,
|
19
|
-
isTextSchema,
|
20
|
-
ImageSchema,
|
21
|
-
isImageSchema,
|
22
|
-
BarcodeSchema,
|
23
|
-
isBarcodeSchema,
|
24
|
-
Font,
|
25
|
-
BasePdf,
|
26
|
-
BarCodeType,
|
27
|
-
Alignment,
|
28
|
-
DEFAULT_FONT_SIZE,
|
29
|
-
DEFAULT_ALIGNMENT,
|
30
|
-
DEFAULT_LINE_HEIGHT,
|
31
|
-
DEFAULT_CHARACTER_SPACING,
|
32
|
-
DEFAULT_FONT_COLOR,
|
33
|
-
calculateDynamicFontSize,
|
34
|
-
heightOfFontAtSize,
|
35
|
-
getFontKitFont,
|
36
|
-
getSplittedLines,
|
37
|
-
mm2pt,
|
38
|
-
widthOfTextAtSize,
|
39
|
-
FontWidthCalcValues,
|
40
|
-
} from '@pdfme/common';
|
41
|
-
import { Buffer } from 'buffer';
|
42
|
-
|
43
|
-
export interface InputImageCache {
|
44
|
-
[key: string]: PDFImage | undefined;
|
45
|
-
}
|
46
|
-
|
47
|
-
const barCodeType2Bcid = (type: BarCodeType) => (type === 'nw7' ? 'rationalizedCodabar' : type);
|
48
|
-
export const createBarCode = async (arg: {
|
49
|
-
type: BarCodeType;
|
50
|
-
input: string;
|
51
|
-
width: number;
|
52
|
-
height: number;
|
53
|
-
backgroundColor?: string;
|
54
|
-
}): Promise<Buffer> => {
|
55
|
-
const { type, input, width, height, backgroundColor } = arg;
|
56
|
-
const bcid = barCodeType2Bcid(type);
|
57
|
-
const includetext = true;
|
58
|
-
const scale = 5;
|
59
|
-
const bwipjsArg: ToBufferOptions = { bcid, text: input, width, height, scale, includetext };
|
60
|
-
|
61
|
-
if (backgroundColor) {
|
62
|
-
bwipjsArg.backgroundcolor = backgroundColor;
|
63
|
-
}
|
64
|
-
|
65
|
-
let res: Buffer;
|
66
|
-
|
67
|
-
if (typeof window !== 'undefined') {
|
68
|
-
const canvas = document.createElement('canvas');
|
69
|
-
bwipjs.toCanvas(canvas, bwipjsArg);
|
70
|
-
const dataUrl = canvas.toDataURL('image/png');
|
71
|
-
res = b64toUint8Array(dataUrl).buffer as Buffer;
|
72
|
-
} else {
|
73
|
-
res = await bwipjs.toBuffer(bwipjsArg);
|
74
|
-
}
|
75
|
-
|
76
|
-
return res;
|
77
|
-
};
|
78
|
-
|
79
|
-
type EmbedPdfBox = {
|
80
|
-
mediaBox: { x: number; y: number; width: number; height: number };
|
81
|
-
bleedBox: { x: number; y: number; width: number; height: number };
|
82
|
-
trimBox: { x: number; y: number; width: number; height: number };
|
83
|
-
};
|
84
|
-
|
85
|
-
export const embedAndGetFontObj = async (arg: { pdfDoc: PDFDocument; font: Font }) => {
|
86
|
-
const { pdfDoc, font } = arg;
|
87
|
-
const fontValues = await Promise.all(
|
88
|
-
Object.values(font).map(async (v) => {
|
89
|
-
let fontData = v.data;
|
90
|
-
if (typeof fontData === 'string' && fontData.startsWith('http')) {
|
91
|
-
fontData = await fetch(fontData).then((res) => res.arrayBuffer());
|
92
|
-
}
|
93
|
-
return pdfDoc.embedFont(fontData, {
|
94
|
-
subset: typeof v.subset === 'undefined' ? true : v.subset,
|
95
|
-
});
|
96
|
-
})
|
97
|
-
);
|
98
|
-
|
99
|
-
return Object.keys(font).reduce(
|
100
|
-
(acc, cur, i) => Object.assign(acc, { [cur]: fontValues[i] }),
|
101
|
-
{} as { [key: string]: PDFFont }
|
102
|
-
);
|
103
|
-
};
|
104
|
-
|
105
|
-
export const getEmbeddedPagesAndEmbedPdfBoxes = async (arg: {
|
106
|
-
pdfDoc: PDFDocument;
|
107
|
-
basePdf: BasePdf;
|
108
|
-
}) => {
|
109
|
-
const { pdfDoc, basePdf } = arg;
|
110
|
-
let embeddedPages: PDFEmbeddedPage[] = [];
|
111
|
-
let embedPdfBoxes: EmbedPdfBox[] = [];
|
112
|
-
const willLoadPdf = typeof basePdf === 'string' ? await getB64BasePdf(basePdf) : basePdf;
|
113
|
-
const embedPdf = await PDFDocument.load(willLoadPdf);
|
114
|
-
const embedPdfPages = embedPdf.getPages();
|
115
|
-
|
116
|
-
embedPdfBoxes = embedPdfPages.map((p) => ({
|
117
|
-
mediaBox: p.getMediaBox(),
|
118
|
-
bleedBox: p.getBleedBox(),
|
119
|
-
trimBox: p.getTrimBox(),
|
120
|
-
}));
|
121
|
-
|
122
|
-
const boundingBoxes = embedPdfPages.map((p) => {
|
123
|
-
const { x, y, width, height } = p.getMediaBox();
|
124
|
-
|
125
|
-
return { left: x, bottom: y, right: width, top: height + y };
|
126
|
-
});
|
127
|
-
|
128
|
-
const transformationMatrices = embedPdfPages.map(
|
129
|
-
() => [1, 0, 0, 1, 0, 0] as TransformationMatrix
|
130
|
-
);
|
131
|
-
|
132
|
-
embeddedPages = await pdfDoc.embedPages(embedPdfPages, boundingBoxes, transformationMatrices);
|
133
|
-
|
134
|
-
return { embeddedPages, embedPdfBoxes };
|
135
|
-
};
|
136
|
-
|
137
|
-
const convertSchemaDimensionsToPt = (schema: Schema) => {
|
138
|
-
const width = mm2pt(schema.width);
|
139
|
-
const height = mm2pt(schema.height);
|
140
|
-
const rotate = degrees(schema.rotate ? schema.rotate : 0);
|
141
|
-
|
142
|
-
return { width, height, rotate };
|
143
|
-
};
|
144
|
-
|
145
|
-
const hex2rgb = (hex: string) => {
|
146
|
-
if (hex.slice(0, 1) === '#') hex = hex.slice(1);
|
147
|
-
if (hex.length === 3)
|
148
|
-
hex =
|
149
|
-
hex.slice(0, 1) +
|
150
|
-
hex.slice(0, 1) +
|
151
|
-
hex.slice(1, 2) +
|
152
|
-
hex.slice(1, 2) +
|
153
|
-
hex.slice(2, 3) +
|
154
|
-
hex.slice(2, 3);
|
155
|
-
|
156
|
-
return [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)].map((str) => parseInt(str, 16));
|
157
|
-
};
|
158
|
-
|
159
|
-
const hex2RgbColor = (hexString: string | undefined) => {
|
160
|
-
if (hexString) {
|
161
|
-
const [r, g, b] = hex2rgb(hexString);
|
162
|
-
|
163
|
-
return rgb(r / 255, g / 255, b / 255);
|
164
|
-
}
|
165
|
-
|
166
|
-
// eslint-disable-next-line no-undefined
|
167
|
-
return undefined;
|
168
|
-
};
|
169
|
-
|
170
|
-
const getFontProp = async ({ input, font, schema }: { input: string, font: Font, schema: TextSchema }) => {
|
171
|
-
const size = schema.dynamicFontSize ? await calculateDynamicFontSize({ textSchema: schema, font, input }) : schema.fontSize ?? DEFAULT_FONT_SIZE;
|
172
|
-
const color = hex2RgbColor(schema.fontColor ?? DEFAULT_FONT_COLOR);
|
173
|
-
const alignment = schema.alignment ?? DEFAULT_ALIGNMENT;
|
174
|
-
const lineHeight = schema.lineHeight ?? DEFAULT_LINE_HEIGHT;
|
175
|
-
const characterSpacing = schema.characterSpacing ?? DEFAULT_CHARACTER_SPACING;
|
176
|
-
|
177
|
-
return { size, color, alignment, lineHeight, characterSpacing };
|
178
|
-
};
|
179
|
-
|
180
|
-
const calcX = (x: number, alignment: Alignment, boxWidth: number, textWidth: number) => {
|
181
|
-
let addition = 0;
|
182
|
-
if (alignment === 'center') {
|
183
|
-
addition = (boxWidth - textWidth) / 2;
|
184
|
-
} else if (alignment === 'right') {
|
185
|
-
addition = boxWidth - textWidth;
|
186
|
-
}
|
187
|
-
|
188
|
-
return mm2pt(x) + addition;
|
189
|
-
};
|
190
|
-
|
191
|
-
const calcY = (y: number, height: number, itemHeight: number) => height - mm2pt(y) - itemHeight;
|
192
|
-
|
193
|
-
const drawBackgroundColor = (arg: {
|
194
|
-
templateSchema: TextSchema;
|
195
|
-
page: PDFPage;
|
196
|
-
pageHeight: number;
|
197
|
-
}) => {
|
198
|
-
const { templateSchema, page, pageHeight } = arg;
|
199
|
-
if (!templateSchema.backgroundColor) return;
|
200
|
-
const { width, height } = convertSchemaDimensionsToPt(templateSchema);
|
201
|
-
const color = hex2RgbColor(templateSchema.backgroundColor);
|
202
|
-
page.drawRectangle({
|
203
|
-
x: calcX(templateSchema.position.x, 'left', width, width),
|
204
|
-
y: calcY(templateSchema.position.y, pageHeight, height),
|
205
|
-
width,
|
206
|
-
height,
|
207
|
-
color,
|
208
|
-
});
|
209
|
-
};
|
210
|
-
|
211
|
-
interface FontSetting {
|
212
|
-
font: Font;
|
213
|
-
pdfFontObj: {
|
214
|
-
[key: string]: PDFFont;
|
215
|
-
};
|
216
|
-
fallbackFontName: string;
|
217
|
-
}
|
218
|
-
|
219
|
-
const drawInputByTextSchema = async (arg: {
|
220
|
-
input: string;
|
221
|
-
templateSchema: TextSchema;
|
222
|
-
pdfDoc: PDFDocument;
|
223
|
-
page: PDFPage;
|
224
|
-
fontSetting: FontSetting;
|
225
|
-
}) => {
|
226
|
-
const { input, templateSchema, page, fontSetting } = arg;
|
227
|
-
const { font, pdfFontObj, fallbackFontName } = fontSetting;
|
228
|
-
|
229
|
-
const pdfFontValue = pdfFontObj[templateSchema.fontName ? templateSchema.fontName : fallbackFontName];
|
230
|
-
const fontKitFont = await getFontKitFont(templateSchema, font);
|
231
|
-
|
232
|
-
const pageHeight = page.getHeight();
|
233
|
-
drawBackgroundColor({ templateSchema, page, pageHeight });
|
234
|
-
|
235
|
-
const { width, height, rotate } = convertSchemaDimensionsToPt(templateSchema);
|
236
|
-
const { size, color, alignment, lineHeight, characterSpacing } = await getFontProp({
|
237
|
-
input,
|
238
|
-
font,
|
239
|
-
schema: templateSchema,
|
240
|
-
});
|
241
|
-
|
242
|
-
page.pushOperators(setCharacterSpacing(characterSpacing));
|
243
|
-
|
244
|
-
let beforeLineOver = 0;
|
245
|
-
|
246
|
-
const fontWidthCalcValues: FontWidthCalcValues = {
|
247
|
-
font: fontKitFont,
|
248
|
-
fontSize: size,
|
249
|
-
characterSpacing,
|
250
|
-
boxWidthInPt: width,
|
251
|
-
};
|
252
|
-
|
253
|
-
input.split(/\r|\n|\r\n/g).forEach((inputLine, inputLineIndex) => {
|
254
|
-
const splitLines = getSplittedLines(inputLine, fontWidthCalcValues);
|
255
|
-
|
256
|
-
const drawLine = (line: string, lineIndex: number) => {
|
257
|
-
const textWidth = widthOfTextAtSize(line, fontKitFont, size, characterSpacing);
|
258
|
-
const textHeight = heightOfFontAtSize(fontKitFont, size);
|
259
|
-
|
260
|
-
page.drawText(line, {
|
261
|
-
x: calcX(templateSchema.position.x, alignment, width, textWidth),
|
262
|
-
y:
|
263
|
-
calcY(templateSchema.position.y, pageHeight, height) +
|
264
|
-
height -
|
265
|
-
textHeight -
|
266
|
-
lineHeight * size * (inputLineIndex + lineIndex + beforeLineOver) -
|
267
|
-
(lineHeight === 0 ? 0 : ((lineHeight - 1) * size) / 2),
|
268
|
-
rotate,
|
269
|
-
size,
|
270
|
-
color,
|
271
|
-
lineHeight: lineHeight * size,
|
272
|
-
maxWidth: width,
|
273
|
-
font: pdfFontValue,
|
274
|
-
wordBreaks: [''],
|
275
|
-
});
|
276
|
-
if (splitLines.length === lineIndex + 1) beforeLineOver += lineIndex;
|
277
|
-
};
|
278
|
-
|
279
|
-
splitLines.forEach(drawLine);
|
280
|
-
});
|
281
|
-
};
|
282
|
-
|
283
|
-
const getCacheKey = (templateSchema: Schema, input: string) => `${templateSchema.type}${input}`;
|
284
|
-
|
285
|
-
const drawInputByImageSchema = async (arg: {
|
286
|
-
input: string;
|
287
|
-
templateSchema: ImageSchema;
|
288
|
-
pdfDoc: PDFDocument;
|
289
|
-
page: PDFPage;
|
290
|
-
inputImageCache: InputImageCache;
|
291
|
-
}) => {
|
292
|
-
const { input, templateSchema, pdfDoc, page, inputImageCache } = arg;
|
293
|
-
|
294
|
-
const { width, height, rotate } = convertSchemaDimensionsToPt(templateSchema);
|
295
|
-
const opt = {
|
296
|
-
x: calcX(templateSchema.position.x, 'left', width, width),
|
297
|
-
y: calcY(templateSchema.position.y, page.getHeight(), height),
|
298
|
-
rotate,
|
299
|
-
width,
|
300
|
-
height,
|
301
|
-
};
|
302
|
-
const inputImageCacheKey = getCacheKey(templateSchema, input);
|
303
|
-
let image = inputImageCache[inputImageCacheKey];
|
304
|
-
if (!image) {
|
305
|
-
const isPng = input.startsWith('data:image/png;');
|
306
|
-
image = await (isPng ? pdfDoc.embedPng(input) : pdfDoc.embedJpg(input));
|
307
|
-
}
|
308
|
-
inputImageCache[inputImageCacheKey] = image;
|
309
|
-
page.drawImage(image, opt);
|
310
|
-
};
|
311
|
-
|
312
|
-
const drawInputByBarcodeSchema = async (arg: {
|
313
|
-
input: string;
|
314
|
-
templateSchema: BarcodeSchema;
|
315
|
-
pdfDoc: PDFDocument;
|
316
|
-
page: PDFPage;
|
317
|
-
inputImageCache: InputImageCache;
|
318
|
-
}) => {
|
319
|
-
const { input, templateSchema, pdfDoc, page, inputImageCache } = arg;
|
320
|
-
if (!validateBarcodeInput(templateSchema.type as BarCodeType, input)) return;
|
321
|
-
|
322
|
-
const { width, height, rotate } = convertSchemaDimensionsToPt(templateSchema);
|
323
|
-
const opt = {
|
324
|
-
x: calcX(templateSchema.position.x, 'left', width, width),
|
325
|
-
y: calcY(templateSchema.position.y, page.getHeight(), height),
|
326
|
-
rotate,
|
327
|
-
width,
|
328
|
-
height,
|
329
|
-
};
|
330
|
-
const inputBarcodeCacheKey = getCacheKey(templateSchema, input);
|
331
|
-
let image = inputImageCache[inputBarcodeCacheKey];
|
332
|
-
if (!image) {
|
333
|
-
const imageBuf = await createBarCode(
|
334
|
-
Object.assign(templateSchema, { type: templateSchema.type as BarCodeType, input })
|
335
|
-
);
|
336
|
-
image = await pdfDoc.embedPng(imageBuf);
|
337
|
-
}
|
338
|
-
inputImageCache[inputBarcodeCacheKey] = image;
|
339
|
-
page.drawImage(image, opt);
|
340
|
-
};
|
341
|
-
|
342
|
-
export const drawInputByTemplateSchema = async (arg: {
|
343
|
-
input: string;
|
344
|
-
templateSchema: Schema;
|
345
|
-
pdfDoc: PDFDocument;
|
346
|
-
page: PDFPage;
|
347
|
-
fontSetting: FontSetting;
|
348
|
-
inputImageCache: InputImageCache;
|
349
|
-
}) => {
|
350
|
-
if (!arg.input || !arg.templateSchema) return;
|
351
|
-
|
352
|
-
if (isTextSchema(arg.templateSchema)) {
|
353
|
-
const templateSchema = arg.templateSchema as TextSchema;
|
354
|
-
await drawInputByTextSchema({ ...arg, templateSchema });
|
355
|
-
} else if (isImageSchema(arg.templateSchema)) {
|
356
|
-
const templateSchema = arg.templateSchema as ImageSchema;
|
357
|
-
await drawInputByImageSchema({ ...arg, templateSchema });
|
358
|
-
} else if (isBarcodeSchema(arg.templateSchema)) {
|
359
|
-
const templateSchema = arg.templateSchema as BarcodeSchema;
|
360
|
-
await drawInputByBarcodeSchema({ ...arg, templateSchema });
|
361
|
-
}
|
362
|
-
};
|
363
|
-
|
364
|
-
export const drawEmbeddedPage = (arg: {
|
365
|
-
page: PDFPage;
|
366
|
-
embeddedPage: PDFEmbeddedPage;
|
367
|
-
embedPdfBox: EmbedPdfBox;
|
368
|
-
}) => {
|
369
|
-
const { page, embeddedPage, embedPdfBox } = arg;
|
370
|
-
page.drawPage(embeddedPage);
|
371
|
-
const { mediaBox: mb, bleedBox: bb, trimBox: tb } = embedPdfBox;
|
372
|
-
page.setMediaBox(mb.x, mb.y, mb.width, mb.height);
|
373
|
-
page.setBleedBox(bb.x, bb.y, bb.width, bb.height);
|
374
|
-
page.setTrimBox(tb.x, tb.y, tb.width, tb.height);
|
375
|
-
};
|