@pdfme/generator 1.0.0-beta.7 → 1.0.0
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/declaration.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +21 -1
- package/dist/index.js.map +1 -1
- package/dist/types/helper.d.ts +2 -2
- package/package.json +10 -6
- package/src/helper.ts +14 -19
- package/tsconfig.json +1 -1
- package/webpack.config.js +2 -1
package/dist/types/helper.d.ts
CHANGED
@@ -3,12 +3,12 @@ import { Schema, Font, BasePdf, BarCodeType } from '@pdfme/common';
|
|
3
3
|
export interface InputImageCache {
|
4
4
|
[key: string]: PDFImage;
|
5
5
|
}
|
6
|
-
export declare const createBarCode: (
|
6
|
+
export declare const createBarCode: (arg: {
|
7
7
|
type: BarCodeType;
|
8
8
|
input: string;
|
9
9
|
width: number;
|
10
10
|
height: number;
|
11
|
-
backgroundColor?: string
|
11
|
+
backgroundColor?: string;
|
12
12
|
}) => Promise<Buffer>;
|
13
13
|
declare type EmbedPdfBox = {
|
14
14
|
mediaBox: {
|
package/package.json
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pdfme/generator",
|
3
|
-
"version": "1.0.0
|
3
|
+
"version": "1.0.0",
|
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!",
|
7
7
|
"homepage": "https://pdfme.com",
|
8
|
-
"repository":
|
8
|
+
"repository": {
|
9
|
+
"type": "git",
|
10
|
+
"url": "git@github.com:pdfme/pdfme.git"
|
11
|
+
},
|
9
12
|
"bugs": {
|
10
13
|
"url": "https://github.com/pdfme/pdfme/issues"
|
11
14
|
},
|
@@ -16,7 +19,7 @@
|
|
16
19
|
"node": ">=14"
|
17
20
|
},
|
18
21
|
"scripts": {
|
19
|
-
"develop": "webpack
|
22
|
+
"develop": "webpack --watch --mode development",
|
20
23
|
"build": "NODE_ENV=production webpack --mode production",
|
21
24
|
"clean": "rimraf dist",
|
22
25
|
"lint": "tsc --noEmit",
|
@@ -27,14 +30,15 @@
|
|
27
30
|
},
|
28
31
|
"dependencies": {
|
29
32
|
"@pdf-lib/fontkit": "^1.1.1",
|
30
|
-
"@pdfme/common": "^1.0.0-beta.
|
31
|
-
"bwip-js": "^
|
33
|
+
"@pdfme/common": "^1.0.0-beta.11",
|
34
|
+
"bwip-js": "^2.1.3",
|
32
35
|
"pdf-lib": "^1.17.1"
|
33
36
|
},
|
34
37
|
"devDependencies": {
|
35
38
|
"@types/bwip-js": "^3.0.0",
|
36
39
|
"@types/pngjs": "^6.0.1",
|
37
40
|
"jsqr": "^1.4.0",
|
41
|
+
"node-polyfill-webpack-plugin": "^1.1.4",
|
38
42
|
"pdf2json": "^2.0.0",
|
39
43
|
"pngjs": "^6.0.0"
|
40
44
|
},
|
@@ -61,4 +65,4 @@
|
|
61
65
|
"publishConfig": {
|
62
66
|
"access": "public"
|
63
67
|
}
|
64
|
-
}
|
68
|
+
}
|
package/src/helper.ts
CHANGED
@@ -9,7 +9,9 @@ import {
|
|
9
9
|
setCharacterSpacing,
|
10
10
|
TransformationMatrix,
|
11
11
|
} from 'pdf-lib';
|
12
|
-
import
|
12
|
+
import { ToBufferOptions } from "bwip-js";
|
13
|
+
import bwipjsNode from 'bwip-js/dist/node-bwipjs';
|
14
|
+
import bwipjsBrowser from 'bwip-js/dist/bwip-js';
|
13
15
|
import {
|
14
16
|
getB64BasePdf,
|
15
17
|
b64toUint8Array,
|
@@ -36,40 +38,33 @@ export interface InputImageCache {
|
|
36
38
|
[key: string]: PDFImage;
|
37
39
|
}
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
input,
|
42
|
-
width,
|
43
|
-
height,
|
44
|
-
backgroundColor,
|
45
|
-
}: {
|
41
|
+
const barCodeType2Bcid = (type: BarCodeType) => (type === 'nw7' ? 'rationalizedCodabar' : type);
|
42
|
+
export const createBarCode = async (arg: {
|
46
43
|
type: BarCodeType;
|
47
44
|
input: string;
|
48
45
|
width: number;
|
49
46
|
height: number;
|
50
47
|
backgroundColor?: string;
|
51
48
|
}): Promise<Buffer> => {
|
52
|
-
const
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
includetext: true,
|
59
|
-
};
|
49
|
+
const { type, input, width, height, backgroundColor } = arg;
|
50
|
+
const bcid = barCodeType2Bcid(type);
|
51
|
+
const includetext = true;
|
52
|
+
const scale = 5;
|
53
|
+
const bwipjsArg: ToBufferOptions = { bcid, text: input, width, height, scale, includetext };
|
54
|
+
|
60
55
|
if (backgroundColor) {
|
61
56
|
bwipjsArg.backgroundcolor = backgroundColor;
|
62
57
|
}
|
63
58
|
|
64
59
|
let res: Buffer;
|
65
60
|
|
66
|
-
if (typeof window !== 'undefined'
|
61
|
+
if (typeof window !== 'undefined') {
|
67
62
|
const canvas = document.createElement('canvas');
|
68
|
-
|
63
|
+
bwipjsBrowser.toCanvas(canvas, bwipjsArg);
|
69
64
|
const dataUrl = canvas.toDataURL('image/png');
|
70
65
|
res = b64toUint8Array(dataUrl).buffer as Buffer;
|
71
66
|
} else {
|
72
|
-
res = await
|
67
|
+
res = await bwipjsNode.toBuffer(bwipjsArg);
|
73
68
|
}
|
74
69
|
|
75
70
|
return res;
|
package/tsconfig.json
CHANGED
package/webpack.config.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
const path = require('path');
|
2
|
+
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
|
2
3
|
const webpack = require('webpack');
|
3
4
|
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
4
5
|
const pkg = require('./package.json');
|
@@ -19,6 +20,7 @@ const config = {
|
|
19
20
|
},
|
20
21
|
plugins: [
|
21
22
|
// new BundleAnalyzerPlugin(),
|
23
|
+
new NodePolyfillPlugin(),
|
22
24
|
new webpack.BannerPlugin({
|
23
25
|
banner: BANNER,
|
24
26
|
entryOnly: true,
|
@@ -35,7 +37,6 @@ const config = {
|
|
35
37
|
filename: 'index.js',
|
36
38
|
globalObject: 'this',
|
37
39
|
library: {
|
38
|
-
name: pkg.name,
|
39
40
|
type: 'umd',
|
40
41
|
},
|
41
42
|
},
|