Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
![]() |
0d39f569ae | |
![]() |
e5372e2652 | |
![]() |
9706bfe31a | |
![]() |
4def4068f7 | |
![]() |
1f92ca61d7 |
35
README.md
35
README.md
|
@ -18,9 +18,9 @@ And I use this name to hope the merits from this application will be dedicated t
|
|||
* A visible signature can be placed on multiple pages. (In the same position)
|
||||
* Sign a pdf and set [DocMDP](https://github.com/zboris12/zgapdfsigner/wiki/API#note).
|
||||
* Add a new signature to a pdf if it has been signed already. (An incremental update)
|
||||
* Add a document timestamp from [TSA](https://github.com/zboris12/zgapdfsigner/wiki/API#note). ( :no_entry_sign:__Not__ available in web browser)
|
||||
* Sign a pdf with a timestamp from [TSA](https://github.com/zboris12/zgapdfsigner/wiki/API#note). ( :no_entry_sign:__Not__ available in web browser)
|
||||
* Enable signature's [LTV](https://github.com/zboris12/zgapdfsigner/wiki/API#note). ( :no_entry_sign:__Not__ available in web browser)
|
||||
* Add a document timestamp from [TSA](https://github.com/zboris12/zgapdfsigner/wiki/API#note). ( :no_entry_sign:__Not__ available in web browser :sunflower:)
|
||||
* Sign a pdf with a timestamp from [TSA](https://github.com/zboris12/zgapdfsigner/wiki/API#note). ( :no_entry_sign:__Not__ available in web browser :sunflower:)
|
||||
* Enable signature's [LTV](https://github.com/zboris12/zgapdfsigner/wiki/API#note). ( :no_entry_sign:__Not__ available in web browser :sunflower:)
|
||||
* Set password protection to a pdf. Supported algorithms:
|
||||
* 40bit RC4 Encryption
|
||||
* 128bit RC4 Encryption
|
||||
|
@ -33,12 +33,16 @@ And I use this name to hope the merits from this application will be dedicated t
|
|||
|
||||
Because of the [CORS](https://github.com/zboris12/zgapdfsigner/wiki/API#note) security restrictions in web browser,
|
||||
signing with a timestamp from [TSA](https://github.com/zboris12/zgapdfsigner/wiki/API#note) or enabling [LTV](https://github.com/zboris12/zgapdfsigner/wiki/API#note) can only be used in [Google Apps Script](https://developers.google.com/apps-script) or [nodejs](https://nodejs.org/).
|
||||
:sunflower: However, if you can avoid the [CORS](https://github.com/zboris12/zgapdfsigner/wiki/API#note) security restrictions
|
||||
by creating your own service or providing a reverse proxy server, these features are also available in web browser.
|
||||
|
||||
## The Dependencies
|
||||
|
||||
* [pdf-lib](https://pdf-lib.js.org/)
|
||||
* [node-forge](https://github.com/digitalbazaar/forge)
|
||||
* [follow-redirects](https://github.com/follow-redirects/follow-redirects)
|
||||
* [pako](https://github.com/nodeca/pako) - For drawing text
|
||||
* [pdf-fontkit](https://github.com/znacloud/pdf-fontkit) - For drawing text
|
||||
|
||||
## How to use this tool
|
||||
|
||||
|
@ -51,10 +55,12 @@ Just import the dependencies and this tool.
|
|||
<script src="https://unpkg.com/node-forge@1.3.1/dist/forge.min.js" type="text/javascript"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/zgapdfsigner/dist/zgapdfsigner.min.js" type="text/javascript"></script>
|
||||
```
|
||||
When drawing text by non-standard font, importing the fontkit library is necessary.
|
||||
When drawing text for signature, importing fontkit and pako library is necessary.
|
||||
```html
|
||||
<script src="https://unpkg.com/@pdf-lib/fontkit/dist/fontkit.umd.min.js" type="text/javascript"></script>
|
||||
<script src="https://unpkg.com/pdf-fontkit@1.8.9/dist/fontkit.umd.min.js" type="text/javascript"></script>
|
||||
<script src="https://unpkg.com/pako@1.0.11/dist/pako_inflate.min.js" type="text/javascript"></script>
|
||||
```
|
||||
Thanks to [znacloud](https://github.com/znacloud/pdf-fontkit) for fixing the font subsetting issue in [@pdf-lib/fontkit](https://github.com/Hopding/fontkit).
|
||||
|
||||
### [Google Apps Script](https://developers.google.com/apps-script)
|
||||
Load the dependencies and this tool.
|
||||
|
@ -64,12 +70,18 @@ function setTimeout(func, sleep){
|
|||
Utilities.sleep(sleep);
|
||||
func();
|
||||
}
|
||||
// Simulate clearTimeout function for pdf-fontkit
|
||||
function clearTimeout(timeoutID){
|
||||
// Do nothing
|
||||
}
|
||||
// Simulate window for node-forge
|
||||
var window = globalThis;
|
||||
// Load pdf-lib
|
||||
eval(UrlFetchApp.fetch("https://unpkg.com/pdf-lib@1.17.1/dist/pdf-lib.min.js").getContentText());
|
||||
// It is necessary for drawing text by non-standard font.
|
||||
eval(UrlFetchApp.fetch("https://unpkg.com/@pdf-lib/fontkit/dist/fontkit.umd.min.js").getContentText());
|
||||
// It is necessary for drawing text for signature.
|
||||
eval(UrlFetchApp.fetch("https://unpkg.com/pdf-fontkit@1.8.9/dist/fontkit.umd.min.js").getContentText());
|
||||
// Load pako, It is necessary for drawing text for signature.
|
||||
eval(UrlFetchApp.fetch("https://unpkg.com/pako@1.0.11/dist/pako_inflate.min.js").getContentText());
|
||||
// Load node-forge
|
||||
eval(UrlFetchApp.fetch("https://unpkg.com/node-forge@1.3.1/dist/forge.min.js").getContentText());
|
||||
// Load ZgaPdfSigner
|
||||
|
@ -88,9 +100,18 @@ pdfkit.loadZga(globalThis);
|
|||
```
|
||||
npm install zgapdfsigner
|
||||
```
|
||||
If using [typescript](https://www.typescriptlang.org/) for development, installation of [definitely typed for node-forge](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node-forge) is necessary.
|
||||
```
|
||||
npm install --save-dev @types/node-forge
|
||||
```
|
||||
2. Import
|
||||
```js
|
||||
// CommonJS Mode
|
||||
const Zga = require("zgapdfsigner");
|
||||
// ES Module Mode
|
||||
import { default as Zga } from "zgapdfsigner";
|
||||
// Typescript
|
||||
import * as Zga from "zgapdfsigner";
|
||||
```
|
||||
|
||||
## Let's sign
|
||||
|
|
10
build.sh
10
build.sh
|
@ -9,6 +9,8 @@ else
|
|||
mkdir ${OUTFLDR}
|
||||
fi
|
||||
|
||||
VER=$(sed -n -r "s/^.*\"version\": ?\"([0-9.]+)\".*$/\1/p" package.json)
|
||||
|
||||
GCCOPT="--charset UTF-8 --compilation_level SIMPLE_OPTIMIZATIONS --warning_level VERBOSE"
|
||||
GCCEXT="--externs closure/google-ext.js --externs closure/forge-ext.js --externs closure/pdflib-ext.js --externs closure/zb-externs.js"
|
||||
jss=""
|
||||
|
@ -20,7 +22,12 @@ do
|
|||
if [ "$c" != "#" ]
|
||||
then
|
||||
outf="${OUTFLDR}/_${js}"
|
||||
sed -e "s/\/\/Only for nodejs Start\/\//\/*/g" -e "s/\/\/Only for nodejs End\/\//*\//g" "lib/${js}" > "${outf}"
|
||||
if [ "${js}" = "zgaindex.js" ]
|
||||
then
|
||||
sed -e "s/\/\/Only for nodejs Start\/\//\/*/g" -e "s/\/\/Only for nodejs End\/\//*\//g" -e "s/ver: \"\"/ver: \"${VER}\"/" "lib/${js}" > "${outf}"
|
||||
else
|
||||
sed -e "s/\/\/Only for nodejs Start\/\//\/*/g" -e "s/\/\/Only for nodejs End\/\//*\//g" "lib/${js}" > "${outf}"
|
||||
fi
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "Created js file: ${outf}"
|
||||
|
@ -32,6 +39,7 @@ do
|
|||
fi
|
||||
fi
|
||||
done <<EOF
|
||||
zgafetch.js
|
||||
zgacertsutil.js
|
||||
zgapdfcryptor.js
|
||||
zgapdfsigner.js
|
||||
|
|
|
@ -9,7 +9,17 @@
|
|||
var PdfLoadOptions;
|
||||
|
||||
/** @const */
|
||||
var fontkit = {};
|
||||
var pako = {};
|
||||
/**
|
||||
* @param {Uint8Array} input
|
||||
* @return {Uint8Array}
|
||||
*/
|
||||
pako.inflate = function(input){};
|
||||
|
||||
/** @constructor */
|
||||
var Fontkit = function(){};
|
||||
/** @const {Fontkit} */
|
||||
var fontkit;
|
||||
|
||||
/** @const */
|
||||
var PDFLib = {};
|
||||
|
@ -41,6 +51,11 @@ PDFLib.lineSplit = function(text){};
|
|||
* @return {boolean}
|
||||
*/
|
||||
PDFLib.isNewlineChar = function(text){};
|
||||
/**
|
||||
* @param {string} fntnm
|
||||
* @return {boolean}
|
||||
*/
|
||||
PDFLib.isStandardFont = function(fntnm){};
|
||||
|
||||
/** @constructor */
|
||||
PDFLib.PDFDocument = function(){};
|
||||
|
@ -105,7 +120,7 @@ PDFLib.PDFDocument.prototype.embedFont = function(font, options){};
|
|||
*/
|
||||
PDFLib.PDFDocument.prototype.embedStandardFont = function(font, customName){};
|
||||
/**
|
||||
* @lends {fontkit} fkt
|
||||
* @param {Fontkit} fkt
|
||||
*/
|
||||
PDFLib.PDFDocument.prototype.registerFontkit = function(fkt){};
|
||||
/**
|
||||
|
@ -316,6 +331,8 @@ PDFLib.PDFName.Annots;
|
|||
* @return {PDFLib.PDFName}
|
||||
*/
|
||||
PDFLib.PDFName.of = function(value){};
|
||||
/** @return {string} */
|
||||
PDFLib.PDFName.prototype.asString = function(){};
|
||||
/** @type {string} */
|
||||
PDFLib.PDFName.prototype.encodedName;
|
||||
/** @type {number} */
|
||||
|
@ -338,10 +355,20 @@ PDFLib.PDFArray.prototype.push = function(object){};
|
|||
* @return {PDFLib.PDFObject}
|
||||
*/
|
||||
PDFLib.PDFArray.prototype.get = function(idx){};
|
||||
/**
|
||||
* @return {number}
|
||||
*/
|
||||
PDFLib.PDFArray.prototype.size = function(){};
|
||||
/**
|
||||
* @return {Array<PDFLib.PDFObject>}
|
||||
*/
|
||||
PDFLib.PDFArray.prototype.asArray = function(){};
|
||||
/**
|
||||
* @param {number} idx
|
||||
* @param {*} typ
|
||||
* @return {PDFLib.PDFObject}
|
||||
*/
|
||||
PDFLib.PDFArray.prototype.lookupMaybe = function(idx, typ){};
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
|
@ -403,8 +430,34 @@ PDFLib.PDFImage.prototype.size = function(){};
|
|||
/** @type {PDFLib.PDFRef} */
|
||||
PDFLib.PDFImage.prototype.ref;
|
||||
|
||||
/** @constructor */
|
||||
PDFLib.StandardFontEmbedder = function(){};
|
||||
/**
|
||||
* @param {string} fontName
|
||||
* @param {string=} customName
|
||||
* @return {PDFLib.StandardFontEmbedder}
|
||||
*/
|
||||
PDFLib.StandardFontEmbedder.for = function(fontName, customName){};
|
||||
|
||||
/** @constructor */
|
||||
PDFLib.CustomFontEmbedder = function(){};
|
||||
/**
|
||||
* @param {Fontkit} fontkit
|
||||
* @param {Uint8Array} fontData
|
||||
* @param {string=} customName
|
||||
* @return {PDFLib.CustomFontEmbedder}
|
||||
*/
|
||||
PDFLib.CustomFontEmbedder.for = function(fontkit, fontData, customName){};
|
||||
|
||||
/** @constructor */
|
||||
PDFLib.PDFFont = function(){};
|
||||
/**
|
||||
* @param {PDFLib.PDFRef} ref
|
||||
* @param {PDFLib.PDFDocument} doc
|
||||
* @param {PDFLib.StandardFontEmbedder|PDFLib.CustomFontEmbedder} embedder
|
||||
* @return {PDFLib.PDFFont}
|
||||
*/
|
||||
PDFLib.PDFFont.of = function(ref, doc, embedder){};
|
||||
/** @type {PDFLib.PDFRef} */
|
||||
PDFLib.PDFFont.prototype.ref;
|
||||
/** @type {string} */
|
||||
|
@ -540,6 +593,12 @@ PDFLib.PDFContentStream.of = function(dict, operators, encode){};
|
|||
* @extends {PDFLib.PDFStream}
|
||||
*/
|
||||
PDFLib.PDFRawStream = function(){};
|
||||
/** @type {PDFLib.PDFDict} */
|
||||
PDFLib.PDFRawStream.prototype.dict;
|
||||
/**
|
||||
* @return {Uint8Array}
|
||||
*/
|
||||
PDFLib.PDFRawStream.prototype.getContents = function(){};
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
|
|
|
@ -36,6 +36,7 @@ var SignAreaInfo;
|
|||
* {{
|
||||
* text: string,
|
||||
* fontData: (Array<number>|Uint8Array|ArrayBuffer|string|undefined),
|
||||
* subset: (boolean|undefined),
|
||||
* color: (string|undefined),
|
||||
* opacity: (number|undefined),
|
||||
* blendMode: (string|undefined),
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
/**
|
||||
* @param {Object<string, *>} z
|
||||
*/
|
||||
function supplyZgaUrlFetch(z){
|
||||
|
||||
//Only for nodejs Start//
|
||||
const m_urlparser = require("url");
|
||||
const m_h = {
|
||||
"http:": require('follow-redirects').http,
|
||||
"https:": require('follow-redirects').https,
|
||||
};
|
||||
// @type {boolean}
|
||||
z.isNode = function(){return this === globalThis.global;}();
|
||||
//Only for nodejs End//
|
||||
|
||||
/** @type {boolean} */
|
||||
z.isBrowser = function(){return this === globalThis.self;}();
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @param {UrlFetchParams} params
|
||||
* @return {Promise<Uint8Array>}
|
||||
*/
|
||||
z.urlFetch = function(url, params){
|
||||
|
||||
//Only for nodejs Start//
|
||||
if(z.isNode){
|
||||
return new Promise(function(resolve, reject){
|
||||
// @type {URL}
|
||||
var opts = m_urlparser.parse(url);
|
||||
var http = m_h[opts.protocol];
|
||||
// @type {string|Buffer}
|
||||
var dat = null;
|
||||
var encoding = undefined;
|
||||
opts.method = "GET";
|
||||
if(params){
|
||||
if(params.payload instanceof Buffer){
|
||||
dat = params.payload;
|
||||
}else if(params.payload instanceof Uint8Array){
|
||||
dat = Buffer.from(params.payload.buffer);
|
||||
}else if(params.payload instanceof ArrayBuffer){
|
||||
dat = Buffer.from(params.payload);
|
||||
}else{
|
||||
dat = params.payload;
|
||||
encoding = "binary";
|
||||
}
|
||||
if(params.headers){
|
||||
opts.headers = params.headers;
|
||||
}
|
||||
if(params.method){
|
||||
opts.method = params.method;
|
||||
}
|
||||
if(params.validateHttpsCertificates === false){
|
||||
opts.rejectUnauthorized = false;
|
||||
}
|
||||
}
|
||||
|
||||
// @type {http.ClientRequest}
|
||||
var hreq = http.request(opts, function(a_res){ // @type {http.IncomingMessage} a_res
|
||||
if(a_res.statusCode !== 200){
|
||||
var a_err = new Error("Failed to request url. " + url + "\n Status Code: " + a_res.statusCode);
|
||||
a_res.resume();
|
||||
throw a_err;
|
||||
}
|
||||
// @type {Array<Buffer>}
|
||||
var a_bufs = [];
|
||||
var a_bufs_len = 0;
|
||||
a_res.on("data", function(b_chunk){ // @type {Buffer} b_chunk
|
||||
a_bufs.push(b_chunk);
|
||||
a_bufs_len += b_chunk.length;
|
||||
});
|
||||
a_res.on("end", function(){
|
||||
// @type {Buffer}
|
||||
var b_bdat = Buffer.concat(a_bufs, a_bufs_len);
|
||||
resolve(b_bdat);
|
||||
});
|
||||
});
|
||||
hreq.on("error", function(a_err){
|
||||
throw a_err;
|
||||
});
|
||||
hreq.end(dat, encoding);
|
||||
});
|
||||
}
|
||||
//Only for nodejs End//
|
||||
|
||||
// Google Apps Script
|
||||
if(globalThis.UrlFetchApp){
|
||||
return new Promise(function(resolve){
|
||||
/** @type {GBlob} */
|
||||
var tblob = UrlFetchApp.fetch(url, params).getBlob();
|
||||
resolve(new Uint8Array(tblob.getBytes()));
|
||||
});
|
||||
}
|
||||
|
||||
// browser
|
||||
if(z.isBrowser && globalThis.self.fetch){
|
||||
/**
|
||||
* @return {Promise<Uint8Array>}
|
||||
*/
|
||||
var func = async function(){
|
||||
/** @type {!RequestInit} */
|
||||
var reqinf = {
|
||||
method: "GET",
|
||||
redirect: "follow",
|
||||
};
|
||||
if(params){
|
||||
if(params.payload){
|
||||
reqinf.body = params.payload;
|
||||
}
|
||||
if(params.headers){
|
||||
reqinf.headers = params.headers;
|
||||
}
|
||||
if(params.method){
|
||||
reqinf.method = params.method;
|
||||
}
|
||||
}
|
||||
/** @type {Response} */
|
||||
var resp = await fetch(url, reqinf);
|
||||
if(resp.ok){
|
||||
/** @type {ArrayBuffer} */
|
||||
var abdat = await resp.arrayBuffer();
|
||||
return new Uint8Array(abdat);
|
||||
}else{
|
||||
/** @type {string} */
|
||||
var msg = await resp.text();
|
||||
throw new Error("Fetch failed." + resp.status + ": " + msg);
|
||||
}
|
||||
};
|
||||
return func();
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
//Only for nodejs Start//
|
||||
if(typeof exports === "object" && typeof module !== "undefined"){
|
||||
module.exports = supplyZgaUrlFetch;
|
||||
}
|
||||
//Only for nodejs End//
|
|
@ -5,14 +5,16 @@
|
|||
*/
|
||||
function genZga(){
|
||||
/** @const {Object<string, *>} */
|
||||
const z = {};
|
||||
const z = {
|
||||
ver: "",
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} msg
|
||||
* @param {...string} msg
|
||||
*/
|
||||
z.log = function(msg){
|
||||
z.log = function(...msg){
|
||||
if(z.debug){
|
||||
console.log(msg);
|
||||
console.log(...msg);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -42,22 +44,6 @@ function genZga(){
|
|||
return arr;
|
||||
};
|
||||
|
||||
// Google Apps Script
|
||||
if(globalThis.UrlFetchApp){
|
||||
/**
|
||||
* @param {string} url
|
||||
* @param {UrlFetchParams} params
|
||||
* @return {Promise<Uint8Array>}
|
||||
*/
|
||||
z.urlFetch = function(url, params){
|
||||
return new Promise(function(resolve){
|
||||
/** @type {GBlob} */
|
||||
var tblob = UrlFetchApp.fetch(url, params).getBlob();
|
||||
resolve(new Uint8Array(tblob.getBytes()));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
return z;
|
||||
}
|
||||
|
||||
|
@ -68,6 +54,7 @@ if(typeof exports === "object" && typeof module !== "undefined"){
|
|||
//Only for nodejs End//
|
||||
if(!globalThis.Zga){
|
||||
globalThis.Zga = genZga();
|
||||
supplyZgaUrlFetch(globalThis.Zga);
|
||||
supplyZgaCertsChain(globalThis.Zga);
|
||||
supplyZgaCryptor(globalThis.Zga);
|
||||
supplyZgaSigner(globalThis.Zga);
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
import * as forge from "node-forge";
|
||||
import * as PDFLib from "pdf-lib";
|
||||
export * as forge from "node-forge";
|
||||
export * as PDFLib from "pdf-lib";
|
||||
|
||||
export declare function u8arrToRaw(uarr: Uint8Array): string;
|
||||
export declare function rawToU8arr(raw: string): Uint8Array;
|
||||
export declare namespace Crypto {
|
||||
enum Mode {
|
||||
RC4_40,
|
||||
RC4_128,
|
||||
AES_128,
|
||||
AES_256,
|
||||
}
|
||||
}
|
||||
export type DSSInfo = {
|
||||
certs?: Array<forge.pki.Certificate>;
|
||||
ocsps?: Array<Uint8Array>;
|
||||
crls?: Array<Uint8Array>;
|
||||
};
|
||||
export type EncryptOption = {
|
||||
mode: Crypto.Mode;
|
||||
permissions?: Array<string>;
|
||||
userpwd?: string;
|
||||
ownerpwd?: string;
|
||||
pubkeys?: Array<PubKeyInfo>;
|
||||
};
|
||||
export type PubKeyInfo = {
|
||||
c?: Array<number> | Uint8Array | ArrayBuffer | string | forge.pki.Certificate;
|
||||
p?: Array<string>;
|
||||
};
|
||||
export type SignAreaInfo = {
|
||||
x: number;
|
||||
y: number;
|
||||
w?: number;
|
||||
h?: number;
|
||||
};
|
||||
export type SignTextInfo = {
|
||||
text: string,
|
||||
fontData?: Array<number> | Uint8Array | ArrayBuffer | PDFLib.StandardFonts;
|
||||
subset?: boolean;
|
||||
color?: string;
|
||||
opacity?: number;
|
||||
blendMode?: string;
|
||||
lineHeight?: number;
|
||||
size: number,
|
||||
xOffset?: number;
|
||||
yOffset?: number;
|
||||
wMax?: number;
|
||||
align?: number;
|
||||
noBreaks?: string;
|
||||
};
|
||||
export type SignImageInfo = {
|
||||
imgData: Array<number> | Uint8Array | ArrayBuffer | string;
|
||||
imgType: string;
|
||||
opacity?: number;
|
||||
blendMode?: string;
|
||||
};
|
||||
export type SignDrawInfo = {
|
||||
area: SignAreaInfo;
|
||||
pageidx?: number | string;
|
||||
/** @deprecated use imgInfo instead */
|
||||
imgData?: Array<number> | Uint8Array | ArrayBuffer | string;
|
||||
/** @deprecated use imgInfo instead */
|
||||
imgType?: string;
|
||||
imgInfo?: SignImageInfo;
|
||||
textInfo?: SignTextInfo;
|
||||
};
|
||||
export type SignOption = {
|
||||
p12cert?: Array<number> | Uint8Array | ArrayBuffer | string;
|
||||
pwd?: string;
|
||||
permission?: number;
|
||||
reason?: string;
|
||||
location?: string;
|
||||
contact?: string;
|
||||
signdate?: Date | TsaServiceInfo | string;
|
||||
signame?: string;
|
||||
drawinf?: SignDrawInfo;
|
||||
ltv?: number;
|
||||
debug?: boolean;
|
||||
};
|
||||
export type TsaServiceInfo = {
|
||||
url: string;
|
||||
len?: number;
|
||||
headers?: Record<string, any>;
|
||||
};
|
||||
|
||||
export declare class CertsChain {
|
||||
constructor(certs?: Array<forge.pki.Certificate | forge.asn1.Asn1 | string>);
|
||||
buildChain(cert: forge.pki.Certificate): Promise<boolean>;
|
||||
getAllCerts(): Array<forge.pki.Certificate>;
|
||||
getSignCert(): forge.pki.Certificate;
|
||||
isSelfSignedCert(): boolean;
|
||||
prepareDSSInf(crlOnly?: boolean): Promise<DSSInfo>;
|
||||
}
|
||||
export declare class PdfCryptor {
|
||||
constructor(encopt: EncryptOption);
|
||||
encryptPdf(pdf: PDFLib.PDFDocument | Array<number> | Uint8Array | ArrayBuffer | string, ref?: PDFLib.PDFRef): Promise<PDFLib.PDFDocument>;
|
||||
encryptObject(num: number, val: PDFLib.PDFObject): void;
|
||||
}
|
||||
export declare class PdfSigner {
|
||||
constructor(signopt: SignOption);
|
||||
sign(pdf: PDFLib.PDFDocument | Array<number> | Uint8Array | ArrayBuffer | string, cypopt?: EncryptOption): Promise<Uint8Array>;
|
||||
}
|
||||
export declare class TsaFetcher {
|
||||
constructor(inf: TsaServiceInfo);
|
||||
url: string;
|
||||
len: number;
|
||||
getCertsChain(): CertsChain;
|
||||
getToken(forP7?: boolean): forge.asn1.Asn1;
|
||||
queryTsa(data?: string): Promise<string>;
|
||||
}
|
||||
export declare class PdfFonts {
|
||||
private constructor();
|
||||
static from(pdfdoc: PDFLib.PDFDocument): Promise<PdfFonts>;
|
||||
getEmbeddedFont(fontData?: Array<number> | Uint8Array | ArrayBuffer | PDFLib.StandardFonts, subset?: boolean): Promise<PDFLib.PDFFont>;
|
||||
}
|
|
@ -6,70 +6,11 @@ const m_h = {
|
|||
const z = require("./zgaindex.js");
|
||||
z.forge = require("node-forge");
|
||||
z.PDFLib = require("pdf-lib");
|
||||
z.fontkit = require("@pdf-lib/fontkit");
|
||||
/**
|
||||
* @param {string} url
|
||||
* @param {UrlFetchParams} params
|
||||
* @return {Promise<Uint8Array>}
|
||||
*/
|
||||
z.urlFetch = function(url, params){
|
||||
return new Promise(function(resolve, reject){
|
||||
/** @type {URL} */
|
||||
var opts = m_urlparser.parse(url);
|
||||
var http = m_h[opts.protocol];
|
||||
/** @type {string|Buffer} */
|
||||
var dat = null;
|
||||
var encoding = undefined;
|
||||
opts.method = "GET";
|
||||
if(params){
|
||||
if(params.payload instanceof Buffer){
|
||||
dat = params.payload;
|
||||
}else if(params.payload instanceof Uint8Array){
|
||||
dat = Buffer.from(params.payload.buffer);
|
||||
}else if(params.payload instanceof ArrayBuffer){
|
||||
dat = Buffer.from(params.payload);
|
||||
}else{
|
||||
dat = params.payload;
|
||||
encoding = "binary";
|
||||
}
|
||||
if(params.headers){
|
||||
opts.headers = params.headers;
|
||||
}
|
||||
if(params.method){
|
||||
opts.method = params.method;
|
||||
}
|
||||
if(params.validateHttpsCertificates === false){
|
||||
opts.rejectUnauthorized = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {http.ClientRequest} */
|
||||
var hreq = http.request(opts, function(/** @type {http.IncomingMessage} */a_res){
|
||||
if(a_res.statusCode !== 200){
|
||||
var a_err = new Error("Failed to request url. " + url + "\n Status Code: " + a_res.statusCode);
|
||||
a_res.resume();
|
||||
throw a_err;
|
||||
}
|
||||
/** @type {Array<Buffer>} */
|
||||
var a_bufs = [];
|
||||
var a_bufs_len = 0;
|
||||
a_res.on("data", function(/** @type {Buffer} */b_chunk){
|
||||
a_bufs.push(b_chunk);
|
||||
a_bufs_len += b_chunk.length;
|
||||
});
|
||||
a_res.on("end", function(){
|
||||
/** @type {Buffer} */
|
||||
var b_bdat = Buffer.concat(a_bufs, a_bufs_len);
|
||||
resolve(b_bdat);
|
||||
});
|
||||
});
|
||||
hreq.on("error", function(a_err){
|
||||
throw a_err;
|
||||
});
|
||||
hreq.end(dat, encoding);
|
||||
});
|
||||
};
|
||||
// z.fontkit = require("@pdf-lib/fontkit");
|
||||
z.fontkit = require("pdf-fontkit");
|
||||
z.pako = require("pako");
|
||||
|
||||
require("./zgafetch.js")(z);
|
||||
require("./zgacertsutil.js")(z);
|
||||
require("./zgapdfcryptor.js")(z);
|
||||
require("./zgapdfsigner.js")(z);
|
||||
|
|
|
@ -15,6 +15,9 @@ if(z.PDFLib){
|
|||
if(z.fontkit){
|
||||
var fontkit = z.fontkit;
|
||||
}
|
||||
if(z.pako){
|
||||
var pako = z.pako;
|
||||
}
|
||||
//Only for nodejs End//
|
||||
|
||||
/** @type {Object<string, TsaServiceInfo>} */
|
||||
|
@ -243,6 +246,8 @@ z.PdfSigner = class{
|
|||
this.oriU8pdf = null;
|
||||
/** @private @type {Array<PdfObjEntry>} */
|
||||
this.apobjs = null;
|
||||
/** @private @type {z.PdfFonts} */
|
||||
this.fonts = null;
|
||||
|
||||
if(typeof this.opt.debug == "boolean"){
|
||||
z.debug = this.opt.debug;
|
||||
|
@ -255,6 +260,9 @@ z.PdfSigner = class{
|
|||
if(!(globalThis.forge || forge)){
|
||||
throw new Error("node-forge is not imported.");
|
||||
}
|
||||
if(z.ver){
|
||||
z.log("ZgaPdfSigner Version:", z.ver);
|
||||
}
|
||||
/** @type {?TsaServiceInfo} */
|
||||
var tsainf = null;
|
||||
if(signopt.signdate){
|
||||
|
@ -268,11 +276,13 @@ z.PdfSigner = class{
|
|||
}
|
||||
if(tsainf){
|
||||
if(!z.urlFetch){
|
||||
throw new Error("Because of the CORS security restrictions, signing with TSA is not supported in web browser.");
|
||||
// throw new Error("Because of the CORS security restrictions, signing with TSA is not supported in web browser.");
|
||||
throw new Error("No fetch method found in this environment.");
|
||||
}
|
||||
if(z.TSAURLS[tsainf.url]){
|
||||
Object.assign(tsainf, z.TSAURLS[tsainf.url]);
|
||||
}else if(!(new RegExp("^https?://")).test(tsainf.url)){
|
||||
}else if(!tsainf.url || (!z.isBrowser && !(new RegExp("^https?://")).test(tsainf.url))){
|
||||
// It may be a relative path in browser environment, so only check in non-browser environment
|
||||
throw new Error("Unknown tsa data. " + JSON.stringify(tsainf));
|
||||
}
|
||||
if(!tsainf.len){
|
||||
|
@ -341,21 +351,8 @@ z.PdfSigner = class{
|
|||
}
|
||||
|
||||
if(_this.opt.drawinf && _this.opt.drawinf.textInfo && !_this.opt.drawinf.font){
|
||||
/** @type {Uint8Array|ArrayBuffer|string} */
|
||||
var fontData2 = null;
|
||||
if(Array.isArray(_this.opt.drawinf.textInfo.fontData)){
|
||||
fontData2 = new Uint8Array(_this.opt.drawinf.textInfo.fontData);
|
||||
}else if(_this.opt.drawinf.textInfo.fontData){
|
||||
fontData2 = _this.opt.drawinf.textInfo.fontData;
|
||||
}else{
|
||||
fontData2 = "Helvetica";
|
||||
}
|
||||
if(typeof fontData2 == "string"){
|
||||
_this.opt.drawinf.font = pdfdoc.embedStandardFont(fontData2);
|
||||
}else{
|
||||
pdfdoc.registerFontkit(fontkit);
|
||||
_this.opt.drawinf.font = await pdfdoc.embedFont(fontData2);
|
||||
}
|
||||
_this.fonts = await z.PdfFonts.from(pdfdoc);
|
||||
_this.opt.drawinf.font = await _this.fonts.getEmbeddedFont(_this.opt.drawinf.textInfo.fontData, _this.opt.drawinf.textInfo.subset);
|
||||
}
|
||||
|
||||
/** @type {forge_cert} */
|
||||
|
@ -1839,6 +1836,192 @@ z.SignatureCreator = class{
|
|||
}
|
||||
};
|
||||
|
||||
z.PdfFonts = class{
|
||||
/**
|
||||
* @private
|
||||
* @param {PDFLib.PDFDocument} pdfdoc
|
||||
* @param {Array<FontInfo>} fonts
|
||||
*/
|
||||
constructor(pdfdoc, fonts){
|
||||
/** @private @type {PDFLib.PDFDocument} */
|
||||
this.doc = pdfdoc;
|
||||
/** @private @type {Array<FontInfo>} */
|
||||
this.fonts = fonts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param {PDFLib.PDFDocument} pdfdoc
|
||||
* @return {Promise<z.PdfFonts>}
|
||||
*/
|
||||
static async from(pdfdoc){
|
||||
/**
|
||||
* @param {PDFLib.PDFDict} dict
|
||||
* @param {string} nm
|
||||
* @return {string|undefined}
|
||||
*/
|
||||
var lookupName = function(dict, nm){
|
||||
var pnm = /** @type {PDFLib.PDFName} */(dict.lookupMaybe(PDFLib.PDFName.of(nm), PDFLib.PDFName));
|
||||
if(pnm){
|
||||
return pnm.asString();
|
||||
}else{
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
/** @type Array<FontInfo> */
|
||||
var fonts = [];
|
||||
/** @type {Array<PdfObjEntry>} */
|
||||
var objs = pdfdoc.context.enumerateIndirectObjects();
|
||||
/** @type {number} */
|
||||
var i = 0;
|
||||
while(i < objs.length){
|
||||
/** @type {PdfObjEntry} */
|
||||
var poe = objs[i];
|
||||
i++;
|
||||
|
||||
if(poe[1] instanceof PDFLib.PDFDict){
|
||||
/** @type {string|undefined} */
|
||||
var typ = lookupName(poe[1], "Type");
|
||||
if(typ !== "/Font"){
|
||||
continue;
|
||||
}
|
||||
/** @type {string|undefined} */
|
||||
var fntnm = lookupName(poe[1], "BaseFont");
|
||||
if(fntnm){
|
||||
fntnm = fntnm.substring(1);
|
||||
if(PDFLib.isStandardFont(fntnm)){
|
||||
fonts.push({
|
||||
font: PDFLib.PDFFont.of(poe[0], pdfdoc, PDFLib.StandardFontEmbedder.for(fntnm)),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
|
||||
var dfnts = /** @type {PDFLib.PDFArray} */(poe[1].lookupMaybe(PDFLib.PDFName.of("DescendantFonts"), PDFLib.PDFArray));
|
||||
if(dfnts && dfnts.size()){
|
||||
var fntdict = /** @type {PDFLib.PDFDict} */(dfnts.lookupMaybe(0, PDFLib.PDFDict));
|
||||
if(fntdict){
|
||||
var fntdesc = /** @type {PDFLib.PDFDict} */(fntdict.lookupMaybe(PDFLib.PDFName.of("FontDescriptor"), PDFLib.PDFDict));
|
||||
if(fntdesc){
|
||||
var rstm = /** @type {PDFLib.PDFRawStream} */(fntdesc.lookupMaybe(PDFLib.PDFName.of("FontFile2"), PDFLib.PDFRawStream));
|
||||
if(rstm){
|
||||
/** @type {Uint8Array} */
|
||||
var fdat = rstm.getContents();
|
||||
/** @type {string|undefined} */
|
||||
var fltr = lookupName(rstm.dict, "Filter");
|
||||
if(fltr == "/FlateDecode"){
|
||||
fdat = pako.inflate(fdat);
|
||||
}
|
||||
try{
|
||||
/** @type {PDFLib.CustomFontEmbedder} */
|
||||
var emdr = await PDFLib.CustomFontEmbedder.for(fontkit, fdat);
|
||||
fonts.push({
|
||||
font: PDFLib.PDFFont.of(poe[0], pdfdoc, emdr),
|
||||
data: fdat,
|
||||
});
|
||||
}catch(ex){
|
||||
z.log(fntnm, ex.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new z.PdfFonts(pdfdoc, fonts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param {Array<number>|Uint8Array|ArrayBuffer|string|undefined} fontData
|
||||
* @param {boolean=} subset
|
||||
* @return {Promise<PDFLib.PDFFont>}
|
||||
*/
|
||||
async getEmbeddedFont(fontData, subset){
|
||||
if(!fontData){
|
||||
if(this.fonts.length){
|
||||
z.log("Use existing default font.", this.fonts[0].font.name);
|
||||
return this.fonts[0].font;
|
||||
}else{
|
||||
fontData = "Helvetica";
|
||||
z.log("Use default font.", fontData);
|
||||
}
|
||||
}
|
||||
if(typeof fontData == "string"){
|
||||
return this.getStandardFont(fontData);
|
||||
}else{
|
||||
/** @type {Uint8Array} */
|
||||
var u8dat = (fontData instanceof Uint8Array) ? fontData : new Uint8Array(fontData);
|
||||
return await this.getCustomFont(u8dat, subset || false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {string} fontData
|
||||
* @return {PDFLib.PDFFont}
|
||||
*/
|
||||
getStandardFont(fontData){
|
||||
/** @type {number} */
|
||||
var i = 0;
|
||||
while(i < this.fonts.length){
|
||||
/** @type {FontInfo} */
|
||||
var fi = this.fonts[i];
|
||||
i++;
|
||||
if(!fi.data && fi.font.name == fontData){
|
||||
z.log("Existing font found.", fi.font.name);
|
||||
return fi.font;
|
||||
}
|
||||
}
|
||||
return this.doc.embedStandardFont(fontData);
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* @param {Uint8Array} fontData
|
||||
* @param {boolean} subset
|
||||
* @return {Promise<PDFLib.PDFFont>}
|
||||
*/
|
||||
async getCustomFont(fontData, subset){
|
||||
/** @type {number} */
|
||||
var i = 0;
|
||||
while(i < this.fonts.length){
|
||||
/** @type {FontInfo} */
|
||||
var fi = this.fonts[i];
|
||||
i++;
|
||||
if(fi.data && this.isSameData(fi.data, fontData)){
|
||||
z.log("Existing font found.", fi.font.name);
|
||||
return fi.font;
|
||||
}
|
||||
}
|
||||
this.doc.registerFontkit(fontkit);
|
||||
return await this.doc.embedFont(fontData, {subset});
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* @param {Uint8Array} dat1
|
||||
* @param {Uint8Array} dat2
|
||||
* @return {boolean}
|
||||
*/
|
||||
isSameData(dat1, dat2){
|
||||
if(dat1.length != dat2.length){
|
||||
return false;
|
||||
}
|
||||
/** @type {number} */
|
||||
var i = 0;
|
||||
while(i < dat1.length){
|
||||
if(dat1[i] != dat2[i]){
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef
|
||||
* {{
|
||||
|
@ -1848,6 +2031,14 @@ z.SignatureCreator = class{
|
|||
* }}
|
||||
*/
|
||||
var SplitLongWordResult;
|
||||
/**
|
||||
* @typedef
|
||||
* {{
|
||||
* font: PDFLib.PDFFont,
|
||||
* data: (Uint8Array|undefined),
|
||||
* }}
|
||||
*/
|
||||
var FontInfo;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,31 +1,23 @@
|
|||
{
|
||||
"name": "zgapdfsigner",
|
||||
"version": "2.5.2",
|
||||
"lockfileVersion": 2,
|
||||
"version": "2.7.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "zgapdfsigner",
|
||||
"version": "2.5.2",
|
||||
"version": "2.7.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@pdf-lib/fontkit": "^1.1.1",
|
||||
"follow-redirects": "1.15.6",
|
||||
"node-forge": "1.3.1",
|
||||
"pdf-fontkit": "1.8.9",
|
||||
"pdf-lib": "1.17.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"google-closure-compiler": "^20231112.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@pdf-lib/fontkit": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@pdf-lib/fontkit/-/fontkit-1.1.1.tgz",
|
||||
"integrity": "sha512-KjMd7grNapIWS/Dm0gvfHEilSyAmeLvrEGVcqLGi0VYebuqqzTbgF29efCx7tvx+IEbG3zQciRSWl3GkUSvjZg==",
|
||||
"dependencies": {
|
||||
"pako": "^1.0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/@pdf-lib/standard-fonts": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@pdf-lib/standard-fonts/-/standard-fonts-1.0.0.tgz",
|
||||
|
@ -181,35 +173,6 @@
|
|||
"integrity": "sha512-E45cJD6/xLJlL8pL6HEoxu8nEKp87CnrojUK0UuHiT7ZjCsrJfR4WhZwNNCq2+/6gYD9unGgMsunV4DDtBbvaA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/google-closure-compiler-linux": {
|
||||
"version": "20231112.0.0",
|
||||
"resolved": "https://registry.npmjs.org/google-closure-compiler-linux/-/google-closure-compiler-linux-20231112.0.0.tgz",
|
||||
"integrity": "sha512-qi2DbqQ+OuZ4Mcp1EttmL4j3oqvXLPl8XREekkfdV651PXBNenoBG6EnzQIius7ESYVgmpbQE4Pw2wNhPudBBQ==",
|
||||
"cpu": [
|
||||
"x32",
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
]
|
||||
},
|
||||
"node_modules/google-closure-compiler-osx": {
|
||||
"version": "20231112.0.0",
|
||||
"resolved": "https://registry.npmjs.org/google-closure-compiler-osx/-/google-closure-compiler-osx-20231112.0.0.tgz",
|
||||
"integrity": "sha512-gNnlnVH4rVO5TyDhvqELzRc9Oydaxincj0QLsAQQkM0btBTUEEyFL1ACT00RgJKxrCTb5Lfa83DfU8ICJi5Ptw==",
|
||||
"cpu": [
|
||||
"x32",
|
||||
"x64",
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
]
|
||||
},
|
||||
"node_modules/google-closure-compiler-windows": {
|
||||
"version": "20231112.0.0",
|
||||
"resolved": "https://registry.npmjs.org/google-closure-compiler-windows/-/google-closure-compiler-windows-20231112.0.0.tgz",
|
||||
|
@ -267,6 +230,14 @@
|
|||
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
|
||||
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
|
||||
},
|
||||
"node_modules/pdf-fontkit": {
|
||||
"version": "1.8.9",
|
||||
"resolved": "https://registry.npmjs.org/pdf-fontkit/-/pdf-fontkit-1.8.9.tgz",
|
||||
"integrity": "sha512-TTq+umfhlFjUuQYOq6dCKT/wLslCrX4zVr5gqrIvrGHfo+vJ3ETapZTb4YLOCErohX7pF+HxlXSZuiToSRhNmA==",
|
||||
"dependencies": {
|
||||
"pako": "^1.0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/pdf-lib": {
|
||||
"version": "1.17.1",
|
||||
"resolved": "https://registry.npmjs.org/pdf-lib/-/pdf-lib-1.17.1.tgz",
|
||||
|
@ -387,290 +358,5 @@
|
|||
"source-map": "^0.5.1"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@pdf-lib/fontkit": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@pdf-lib/fontkit/-/fontkit-1.1.1.tgz",
|
||||
"integrity": "sha512-KjMd7grNapIWS/Dm0gvfHEilSyAmeLvrEGVcqLGi0VYebuqqzTbgF29efCx7tvx+IEbG3zQciRSWl3GkUSvjZg==",
|
||||
"requires": {
|
||||
"pako": "^1.0.6"
|
||||
}
|
||||
},
|
||||
"@pdf-lib/standard-fonts": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@pdf-lib/standard-fonts/-/standard-fonts-1.0.0.tgz",
|
||||
"integrity": "sha512-hU30BK9IUN/su0Mn9VdlVKsWBS6GyhVfqjwl1FjZN4TxP6cCw0jP2w7V3Hf5uX7M0AZJ16vey9yE0ny7Sa59ZA==",
|
||||
"requires": {
|
||||
"pako": "^1.0.6"
|
||||
}
|
||||
},
|
||||
"@pdf-lib/upng": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@pdf-lib/upng/-/upng-1.0.1.tgz",
|
||||
"integrity": "sha512-dQK2FUMQtowVP00mtIksrlZhdFXQZPC+taih1q4CvPZ5vqdxR/LKBaFg0oAfzd1GlHZXXSPdQfzQnt+ViGvEIQ==",
|
||||
"requires": {
|
||||
"pako": "^1.0.10"
|
||||
}
|
||||
},
|
||||
"ansi-styles": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"color-convert": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"chalk": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
|
||||
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ansi-styles": "^4.1.0",
|
||||
"supports-color": "^7.1.0"
|
||||
}
|
||||
},
|
||||
"clone": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz",
|
||||
"integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==",
|
||||
"dev": true
|
||||
},
|
||||
"clone-buffer": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/clone-buffer/-/clone-buffer-1.0.0.tgz",
|
||||
"integrity": "sha512-KLLTJWrvwIP+OPfMn0x2PheDEP20RPUcGXj/ERegTgdmPEZylALQldygiqrPPu8P45uNuPs7ckmReLY6v/iA5g==",
|
||||
"dev": true
|
||||
},
|
||||
"clone-stats": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/clone-stats/-/clone-stats-1.0.0.tgz",
|
||||
"integrity": "sha512-au6ydSpg6nsrigcZ4m8Bc9hxjeW+GJ8xh5G3BJCMt4WXe1H10UNaVOamqQTmrx1kjVuxAHIQSNU6hY4Nsn9/ag==",
|
||||
"dev": true
|
||||
},
|
||||
"cloneable-readable": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/cloneable-readable/-/cloneable-readable-1.1.3.tgz",
|
||||
"integrity": "sha512-2EF8zTQOxYq70Y4XKtorQupqF0m49MBz2/yf5Bj+MHjvpG3Hy7sImifnqD6UA+TKYxeSV+u6qqQPawN5UvnpKQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"inherits": "^2.0.1",
|
||||
"process-nextick-args": "^2.0.0",
|
||||
"readable-stream": "^2.3.5"
|
||||
}
|
||||
},
|
||||
"color-convert": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"color-name": "~1.1.4"
|
||||
}
|
||||
},
|
||||
"color-name": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||
"dev": true
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
||||
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==",
|
||||
"dev": true
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.15.6",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
|
||||
"integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA=="
|
||||
},
|
||||
"google-closure-compiler": {
|
||||
"version": "20231112.0.0",
|
||||
"resolved": "https://registry.npmjs.org/google-closure-compiler/-/google-closure-compiler-20231112.0.0.tgz",
|
||||
"integrity": "sha512-C/MPRThIxRAFomGhpEwXyVcWRIVnmqGraJ5BTJ+EQcfAiPNBvl+Q5nKU2J/lICPcx+YQ+3c+FJ/gBJsTXPjcwg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"chalk": "4.x",
|
||||
"google-closure-compiler-java": "^20231112.0.0",
|
||||
"google-closure-compiler-linux": "^20231112.0.0",
|
||||
"google-closure-compiler-osx": "^20231112.0.0",
|
||||
"google-closure-compiler-windows": "^20231112.0.0",
|
||||
"minimist": "1.x",
|
||||
"vinyl": "2.x",
|
||||
"vinyl-sourcemaps-apply": "^0.2.0"
|
||||
}
|
||||
},
|
||||
"google-closure-compiler-java": {
|
||||
"version": "20231112.0.0",
|
||||
"resolved": "https://registry.npmjs.org/google-closure-compiler-java/-/google-closure-compiler-java-20231112.0.0.tgz",
|
||||
"integrity": "sha512-E45cJD6/xLJlL8pL6HEoxu8nEKp87CnrojUK0UuHiT7ZjCsrJfR4WhZwNNCq2+/6gYD9unGgMsunV4DDtBbvaA==",
|
||||
"dev": true
|
||||
},
|
||||
"google-closure-compiler-linux": {
|
||||
"version": "20231112.0.0",
|
||||
"resolved": "https://registry.npmjs.org/google-closure-compiler-linux/-/google-closure-compiler-linux-20231112.0.0.tgz",
|
||||
"integrity": "sha512-qi2DbqQ+OuZ4Mcp1EttmL4j3oqvXLPl8XREekkfdV651PXBNenoBG6EnzQIius7ESYVgmpbQE4Pw2wNhPudBBQ==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"google-closure-compiler-osx": {
|
||||
"version": "20231112.0.0",
|
||||
"resolved": "https://registry.npmjs.org/google-closure-compiler-osx/-/google-closure-compiler-osx-20231112.0.0.tgz",
|
||||
"integrity": "sha512-gNnlnVH4rVO5TyDhvqELzRc9Oydaxincj0QLsAQQkM0btBTUEEyFL1ACT00RgJKxrCTb5Lfa83DfU8ICJi5Ptw==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"google-closure-compiler-windows": {
|
||||
"version": "20231112.0.0",
|
||||
"resolved": "https://registry.npmjs.org/google-closure-compiler-windows/-/google-closure-compiler-windows-20231112.0.0.tgz",
|
||||
"integrity": "sha512-wbN5EOCGz53HVENVtOEO1brn/G3ZmCV1ULiJljNuASQc62vQ36QHA6XnAZOAGTEpAoMnYRv3dtXtBKd07wBdsA==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"has-flag": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
||||
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
|
||||
"dev": true
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
||||
"dev": true
|
||||
},
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==",
|
||||
"dev": true
|
||||
},
|
||||
"minimist": {
|
||||
"version": "1.2.8",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
|
||||
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
|
||||
"dev": true
|
||||
},
|
||||
"node-forge": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz",
|
||||
"integrity": "sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA=="
|
||||
},
|
||||
"pako": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
|
||||
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
|
||||
},
|
||||
"pdf-lib": {
|
||||
"version": "1.17.1",
|
||||
"resolved": "https://registry.npmjs.org/pdf-lib/-/pdf-lib-1.17.1.tgz",
|
||||
"integrity": "sha512-V/mpyJAoTsN4cnP31vc0wfNA1+p20evqqnap0KLoRUN0Yk/p3wN52DOEsL4oBFcLdb76hlpKPtzJIgo67j/XLw==",
|
||||
"requires": {
|
||||
"@pdf-lib/standard-fonts": "^1.0.0",
|
||||
"@pdf-lib/upng": "^1.0.1",
|
||||
"pako": "^1.0.11",
|
||||
"tslib": "^1.11.1"
|
||||
}
|
||||
},
|
||||
"process-nextick-args": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
||||
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==",
|
||||
"dev": true
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.3.8",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz",
|
||||
"integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.3",
|
||||
"isarray": "~1.0.0",
|
||||
"process-nextick-args": "~2.0.0",
|
||||
"safe-buffer": "~5.1.1",
|
||||
"string_decoder": "~1.1.1",
|
||||
"util-deprecate": "~1.0.1"
|
||||
}
|
||||
},
|
||||
"remove-trailing-separator": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz",
|
||||
"integrity": "sha512-/hS+Y0u3aOfIETiaiirUFwDBDzmXPvO+jAfKTitUngIPzdKc6Z0LoFjM/CK5PL4C+eKwHohlHAb6H0VFfmmUsw==",
|
||||
"dev": true
|
||||
},
|
||||
"replace-ext": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/replace-ext/-/replace-ext-1.0.1.tgz",
|
||||
"integrity": "sha512-yD5BHCe7quCgBph4rMQ+0KkIRKwWCrHDOX1p1Gp6HwjPM5kVoCdKGNhN7ydqqsX6lJEnQDKZ/tFMiEdQ1dvPEw==",
|
||||
"dev": true
|
||||
},
|
||||
"safe-buffer": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
|
||||
"dev": true
|
||||
},
|
||||
"source-map": {
|
||||
"version": "0.5.7",
|
||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz",
|
||||
"integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==",
|
||||
"dev": true
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
|
||||
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"safe-buffer": "~5.1.0"
|
||||
}
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
||||
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"has-flag": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"tslib": {
|
||||
"version": "1.14.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
|
||||
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
|
||||
},
|
||||
"util-deprecate": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
|
||||
"dev": true
|
||||
},
|
||||
"vinyl": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/vinyl/-/vinyl-2.2.1.tgz",
|
||||
"integrity": "sha512-LII3bXRFBZLlezoG5FfZVcXflZgWP/4dCwKtxd5ky9+LOtM4CS3bIRQsmR1KMnMW07jpE8fqR2lcxPZ+8sJIcw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"clone": "^2.1.1",
|
||||
"clone-buffer": "^1.0.0",
|
||||
"clone-stats": "^1.0.0",
|
||||
"cloneable-readable": "^1.0.0",
|
||||
"remove-trailing-separator": "^1.0.1",
|
||||
"replace-ext": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"vinyl-sourcemaps-apply": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/vinyl-sourcemaps-apply/-/vinyl-sourcemaps-apply-0.2.1.tgz",
|
||||
"integrity": "sha512-+oDh3KYZBoZC8hfocrbrxbLUeaYtQK7J5WU5Br9VqWqmCll3tFJqKp97GC9GmMsVIL0qnx2DgEDVxdo5EZ5sSw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"source-map": "^0.5.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "zgapdfsigner",
|
||||
"version": "2.6.0",
|
||||
"version": "2.7.3",
|
||||
"author": "zboris12",
|
||||
"description": "A javascript tool to sign a pdf or set protection to a pdf in web browser, Google Apps Script and nodejs.",
|
||||
"homepage": "https://github.com/zboris12/zgapdfsigner",
|
||||
|
@ -14,8 +14,10 @@
|
|||
},
|
||||
"license": "MIT",
|
||||
"main": "lib/zganode.js",
|
||||
"unpkg": "dist/zgapdfsigner.min.js",
|
||||
"files": [
|
||||
"dist/*.min.js",
|
||||
"lib/*.d.ts",
|
||||
"lib/*.js"
|
||||
],
|
||||
"keywords": [
|
||||
|
@ -30,12 +32,12 @@
|
|||
],
|
||||
"scripts": {
|
||||
"build": "./build.sh",
|
||||
"test": "node test4node.js"
|
||||
"test": "node test4node.js ${pfxpwd}"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pdf-lib/fontkit": "^1.1.1",
|
||||
"follow-redirects": "1.15.6",
|
||||
"node-forge": "1.3.1",
|
||||
"pdf-fontkit": "1.8.9",
|
||||
"pdf-lib": "1.17.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"editor.tabSize": 2,
|
||||
"editor.formatOnSave": true,
|
||||
"files.eol": "\n"
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "zgapdfsigner-test-ts",
|
||||
"version": "1.0.0",
|
||||
"author": "zboris12",
|
||||
"description": "A typescript program to test zgapdfsigner.",
|
||||
"private": false,
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "node test/index.js ${pfxpwd}"
|
||||
},
|
||||
"dependencies": {
|
||||
"zgapdfsigner": "^2.7.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node-forge": "^1.3.11",
|
||||
"typescript": "~4.9"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
import * as m_fs from "node:fs";
|
||||
import * as m_path from "node:path";
|
||||
import * as Zga from "zgapdfsigner";
|
||||
|
||||
const workpath = "./";
|
||||
|
||||
async function sign_protect(pdfPath: string, pfxPath: string, ps: string, perm: number, imgPath?: string, txt?: string, fontPath?: string): Promise<string> {
|
||||
let pdf: Buffer = m_fs.readFileSync(pdfPath);
|
||||
let pfx: Buffer = m_fs.readFileSync(pfxPath);
|
||||
let img: Buffer | undefined = undefined;
|
||||
let imgType: string = "";
|
||||
let font: Buffer | Zga.PDFLib.StandardFonts | undefined = undefined;
|
||||
|
||||
if (perm == 1) {
|
||||
console.log("\nTest signing pdf with full protection. (permission 1 and password encryption)");
|
||||
} else {
|
||||
console.log("\nTest signing pdf with permission " + perm);
|
||||
}
|
||||
|
||||
if (imgPath) {
|
||||
img = m_fs.readFileSync(imgPath);
|
||||
imgType = m_path.extname(imgPath).slice(1);
|
||||
}
|
||||
if (fontPath) {
|
||||
if (Zga.PDFLib.isStandardFont(fontPath)) {
|
||||
font = fontPath as string as Zga.PDFLib.StandardFonts;
|
||||
} else {
|
||||
font = m_fs.readFileSync(fontPath);
|
||||
}
|
||||
}
|
||||
let sopt: Zga.SignOption = {
|
||||
p12cert: pfx,
|
||||
pwd: ps,
|
||||
permission: perm,
|
||||
signdate: "1",
|
||||
reason: "I have a test reason " + perm + ".",
|
||||
location: "I am on the earth " + perm + ".",
|
||||
contact: "zga" + perm + "@zga.com",
|
||||
ltv: 1,
|
||||
debug: true,
|
||||
};
|
||||
if (img || txt) {
|
||||
sopt.drawinf = {
|
||||
area: {
|
||||
x: perm ? 25 : 200, // left
|
||||
y: 50, // top
|
||||
w: txt ? undefined : 60,
|
||||
h: txt ? undefined : 100,
|
||||
},
|
||||
pageidx: "-",
|
||||
imgInfo: img ? {
|
||||
imgData: img,
|
||||
imgType: imgType,
|
||||
} : undefined,
|
||||
textInfo: txt ? {
|
||||
text: txt,
|
||||
fontData: font,
|
||||
color: "00f0f1",
|
||||
lineHeight: 20,
|
||||
size: 16,
|
||||
align: 1,
|
||||
wMax: 80,
|
||||
yOffset: 10,
|
||||
xOffset: 20,
|
||||
noBreaks: "[あいうえおA-Za-z0-9]",
|
||||
} : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
let eopt: Zga.EncryptOption | undefined = undefined;
|
||||
if (perm == 1) {
|
||||
eopt = {
|
||||
mode: Zga.Crypto.Mode.AES_256,
|
||||
permissions: ["copy", "copy-extract", "print-high"],
|
||||
userpwd: "123",
|
||||
};
|
||||
}
|
||||
|
||||
let ser: Zga.PdfSigner = new Zga.PdfSigner(sopt);
|
||||
let u8dat: Uint8Array = await ser.sign(pdf, eopt);
|
||||
let outPath: string = "";
|
||||
if (u8dat) {
|
||||
outPath = m_path.join(__dirname, workpath + "test_perm" + perm + m_path.basename(pdfPath));
|
||||
m_fs.writeFileSync(outPath, u8dat);
|
||||
console.log("Output file: " + outPath);
|
||||
}
|
||||
return outPath;
|
||||
}
|
||||
|
||||
async function addtsa(pdfPath: string): Promise<string> {
|
||||
console.log("\nTest signing pdf by a timestamp.");
|
||||
|
||||
let pdf: Buffer = m_fs.readFileSync(pdfPath);
|
||||
let sopt: Zga.SignOption = {
|
||||
signdate: "2",
|
||||
reason: "I have a test reason tsa.",
|
||||
location: "I am on the earth tsa.",
|
||||
contact: "zgatsa@zga.com",
|
||||
ltv: 1,
|
||||
debug: true,
|
||||
};
|
||||
let ser: Zga.PdfSigner = new Zga.PdfSigner(sopt);
|
||||
let u8dat: Uint8Array = await ser.sign(pdf);
|
||||
let outPath: string = m_path.join(__dirname, workpath + "tsa_" + m_path.basename(pdfPath));
|
||||
m_fs.writeFileSync(outPath, u8dat);
|
||||
console.log("Output file: " + outPath);
|
||||
return outPath;
|
||||
}
|
||||
|
||||
async function main1(angle: number): Promise<void> {
|
||||
let pdfPath: string = m_path.join(__dirname, workpath + "_test" + (angle ? "_" + angle : "") + ".pdf");
|
||||
let pfxPath: string = m_path.join(__dirname, workpath + "_test.pfx");
|
||||
let ps: string = "";
|
||||
let imgPath: string = m_path.join(__dirname, workpath + "_test.png");
|
||||
let fontPath: string = angle ? Zga.PDFLib.StandardFonts.TimesRomanBold : m_path.join(__dirname, workpath + "_test.ttf");
|
||||
|
||||
if (process.argv.length > 3) {
|
||||
pfxPath = process.argv[2];
|
||||
ps = process.argv[3];
|
||||
} else if (process.argv[2]) {
|
||||
ps = process.argv[2];
|
||||
}
|
||||
|
||||
if (!ps) {
|
||||
// throw new Error("The passphrase is not specified.");
|
||||
pfxPath = "";
|
||||
}
|
||||
|
||||
if (pfxPath) {
|
||||
await sign_protect(pdfPath, pfxPath, ps, 1, imgPath, "あいうえおあいうえおか\r\n\nThis is a test of text!\n");
|
||||
pdfPath = await sign_protect(pdfPath, pfxPath, ps, 2, imgPath, (angle ? "" : "ありがとうご\r\n\n") + "This is an another test of text!\n", fontPath);
|
||||
pdfPath = await sign_protect(pdfPath, pfxPath, ps, 0, undefined, (angle ? "" : "たちつて得\n\n") + "This is a test for same font!\n", fontPath);
|
||||
await addtsa(pdfPath);
|
||||
} else {
|
||||
await addtsa(pdfPath);
|
||||
}
|
||||
|
||||
console.log("Done");
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
let arr: Array<number> = [0, 90, 180, 270];
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
await main1(arr[i]);
|
||||
// break;
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2015",
|
||||
"module": "commonjs",
|
||||
"newLine": "LF",
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitThis": true,
|
||||
"rootDir": "./src",
|
||||
"outDir": "./test",
|
||||
"typeRoots": [
|
||||
"node_modules/@types"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
|
@ -5,7 +5,8 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title> Test for ZgaPdfSigner </title>
|
||||
<script src="https://unpkg.com/pdf-lib@1.17.1/dist/pdf-lib.min.js" type="text/javascript"></script>
|
||||
<script src="https://unpkg.com/@pdf-lib/fontkit/dist/fontkit.umd.min.js" type="text/javascript"></script>
|
||||
<script src="https://unpkg.com/pdf-fontkit@1.8.9/dist/fontkit.umd.min.js" type="text/javascript"></script>
|
||||
<script src="https://unpkg.com/pako@1.0.11/dist/pako_inflate.min.js" type="text/javascript"></script>
|
||||
<script src="https://unpkg.com/node-forge@1.3.1/dist/forge.min.js" type="text/javascript"></script>
|
||||
<script src="dist/zgapdfsigner.min.js" type="text/javascript"></script>
|
||||
<script type="text/javascript">
|
||||
|
@ -89,7 +90,7 @@ async function testMe(){
|
|||
if(img || txt){
|
||||
sopt.drawinf = {
|
||||
area: {
|
||||
x: 25, // left
|
||||
x: parseInt(document.getElementById("drawx").value), // left
|
||||
y: 150, // top
|
||||
w: txt ? undefined : 60,
|
||||
h: txt ? undefined : 100,
|
||||
|
@ -102,6 +103,7 @@ async function testMe(){
|
|||
textInfo: txt ? {
|
||||
text: txt,
|
||||
fontData: font,
|
||||
subset: true,
|
||||
color: "f00",
|
||||
size: 16,
|
||||
align: 2,
|
||||
|
@ -207,6 +209,7 @@ span.header {
|
|||
<label>signature image </label><input type="file" id="img" /><br />
|
||||
<label>signature text </label><input type="text" id="txt" /><br />
|
||||
<label>text font </label><input type="file" id="font" /><br />
|
||||
<label>left </label><input type="text" id="drawx" value="25" /><br />
|
||||
<label>permission </label>
|
||||
<select id="sperm" onchange="changeSperm()">
|
||||
<option value="0">No DocMDP</option>
|
||||
|
|
28
test4node.js
28
test4node.js
|
@ -1,3 +1,10 @@
|
|||
// ES Module Mode
|
||||
// import * as m_fs from "node:fs";
|
||||
// import * as m_path from "node:path";
|
||||
// import { fileURLToPath } from "node:url";
|
||||
// import { default as Zga } from "./lib/zganode.js";
|
||||
// const __dirname = m_path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const m_fs = require("fs");
|
||||
const m_path = require("path");
|
||||
const Zga = require("./lib/zganode.js");
|
||||
|
@ -23,7 +30,7 @@ async function sign_protect(pdfPath, pfxPath, ps, perm, imgPath, txt, fontPath){
|
|||
var img = null;
|
||||
/** @type {string} */
|
||||
var imgType = "";
|
||||
/** @type {Buffer} */
|
||||
/** @type {Buffer|string} */
|
||||
var font = null;
|
||||
|
||||
if(perm == 1){
|
||||
|
@ -37,7 +44,11 @@ async function sign_protect(pdfPath, pfxPath, ps, perm, imgPath, txt, fontPath){
|
|||
imgType = m_path.extname(imgPath).slice(1);
|
||||
}
|
||||
if(fontPath){
|
||||
font = m_fs.readFileSync(fontPath);
|
||||
if(Zga.PDFLib.isStandardFont(fontPath)){
|
||||
font = fontPath;
|
||||
}else{
|
||||
font = m_fs.readFileSync(fontPath);
|
||||
}
|
||||
}
|
||||
/** @type {SignOption} */
|
||||
var sopt = {
|
||||
|
@ -54,7 +65,7 @@ async function sign_protect(pdfPath, pfxPath, ps, perm, imgPath, txt, fontPath){
|
|||
if(img || txt){
|
||||
sopt.drawinf = {
|
||||
area: {
|
||||
x: 25, // left
|
||||
x: perm ? 25 : 200, // left
|
||||
y: 50, // top
|
||||
w: txt ? undefined : 60,
|
||||
h: txt ? undefined : 100,
|
||||
|
@ -145,6 +156,7 @@ async function main1(angle){
|
|||
var imgPath = m_path.join(__dirname, workpath+"_test.png");
|
||||
/** @type {string} */
|
||||
var fontPath = m_path.join(__dirname, workpath+"_test.ttf");
|
||||
// var fontPath = Zga.PDFLib.StandardFonts.CourierBold;
|
||||
|
||||
if(process.argv.length > 3){
|
||||
pfxPath = process.argv[2];
|
||||
|
@ -159,8 +171,14 @@ async function main1(angle){
|
|||
}
|
||||
|
||||
if(pfxPath){
|
||||
await sign_protect(pdfPath, pfxPath, ps, 1, imgPath, "あいうえおあいうえおか\r\n\nThis is a test of text!\n", fontPath);
|
||||
pdfPath = await sign_protect(pdfPath, pfxPath, ps, 2, undefined, "ありがとうご\r\n\nThis is an another test of text!\n", fontPath);
|
||||
await sign_protect(pdfPath, pfxPath, ps, 1, imgPath, "あいうえおあいうえおか\r\n\nThis is a test of text!\n");
|
||||
if(Zga.PDFLib.isStandardFont(fontPath)){
|
||||
pdfPath = await sign_protect(pdfPath, pfxPath, ps, 2, imgPath, "This is an another test of text!\n", fontPath);
|
||||
pdfPath = await sign_protect(pdfPath, pfxPath, ps, 0, undefined, "This is a test for same font!\n", fontPath);
|
||||
}else{
|
||||
pdfPath = await sign_protect(pdfPath, pfxPath, ps, 2, imgPath, "ありがとうご\r\nThis is an another test of text!\n", fontPath);
|
||||
pdfPath = await sign_protect(pdfPath, pfxPath, ps, 0, undefined, "たちつてと\n\nThis is a test for same font!\n", fontPath);
|
||||
}
|
||||
await addtsa(pdfPath);
|
||||
}else{
|
||||
await addtsa(pdfPath);
|
||||
|
|
Loading…
Reference in New Issue