@pdfme/generator 1.0.0 → 1.0.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.
@@ -1,7 +1,7 @@
1
1
  import { PDFPage, PDFFont, PDFDocument, PDFImage, PDFEmbeddedPage } from 'pdf-lib';
2
2
  import { Schema, Font, BasePdf, BarCodeType } from '@pdfme/common';
3
3
  export interface InputImageCache {
4
- [key: string]: PDFImage;
4
+ [key: string]: PDFImage | undefined;
5
5
  }
6
6
  export declare const createBarCode: (arg: {
7
7
  type: BarCodeType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfme/generator",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "author": "hand-dot",
5
5
  "license": "MIT",
6
6
  "description": "TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@pdf-lib/fontkit": "^1.1.1",
33
- "@pdfme/common": "^1.0.0-beta.11",
33
+ "@pdfme/common": "^1.0.0",
34
34
  "bwip-js": "^2.1.3",
35
35
  "pdf-lib": "^1.17.1"
36
36
  },
package/src/helper.ts CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  setCharacterSpacing,
10
10
  TransformationMatrix,
11
11
  } from 'pdf-lib';
12
- import { ToBufferOptions } from "bwip-js";
12
+ import { ToBufferOptions } from 'bwip-js';
13
13
  import bwipjsNode from 'bwip-js/dist/node-bwipjs';
14
14
  import bwipjsBrowser from 'bwip-js/dist/bwip-js';
15
15
  import {
@@ -35,7 +35,7 @@ import {
35
35
  } from '@pdfme/common';
36
36
 
37
37
  export interface InputImageCache {
38
- [key: string]: PDFImage;
38
+ [key: string]: PDFImage | undefined;
39
39
  }
40
40
 
41
41
  const barCodeType2Bcid = (type: BarCodeType) => (type === 'nw7' ? 'rationalizedCodabar' : type);
@@ -366,6 +366,7 @@ const drawInputByBarcodeSchema = async (arg: {
366
366
  inputImageCache: InputImageCache;
367
367
  }) => {
368
368
  const { input, templateSchema, pageHeight, pdfDoc, page, inputImageCache } = arg;
369
+ if (!validateBarcodeInput(templateSchema.type as BarCodeType, input)) return;
369
370
 
370
371
  const { width, height, rotate } = getSchemaSizeAndRotate(templateSchema);
371
372
  const opt = {
@@ -377,14 +378,13 @@ const drawInputByBarcodeSchema = async (arg: {
377
378
  };
378
379
  const inputBarcodeCacheKey = getCacheKey(templateSchema, input);
379
380
  let image = inputImageCache[inputBarcodeCacheKey];
380
- if (!image && validateBarcodeInput(templateSchema.type as BarCodeType, input)) {
381
- const imageBuf = await createBarCode({
382
- ...{ ...templateSchema, type: templateSchema.type as BarCodeType },
383
- input,
384
- });
385
- if (imageBuf) {
386
- image = await pdfDoc.embedPng(imageBuf);
387
- }
381
+ if (!image) {
382
+ const imageBuf = await createBarCode(
383
+ Object.assign(templateSchema, { type: templateSchema.type as BarCodeType, input })
384
+ );
385
+ image = await pdfDoc.embedPng(imageBuf);
386
+ console.log('image: ', image);
387
+ console.log('imageBuf: ', imageBuf);
388
388
  }
389
389
  inputImageCache[inputBarcodeCacheKey] = image;
390
390
  page.drawImage(image, opt);