Skip to content

Commit

Permalink
Added support to add a signature to a pdf which has already been signed.
Browse files Browse the repository at this point in the history
  • Loading branch information
zboris12 committed Oct 20, 2022
1 parent 5c9ac47 commit 22f6628
Show file tree
Hide file tree
Showing 3 changed files with 490 additions and 79 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ And I use this name to hope the merits from this application will be dedicated t
* Sign a pdf with an invisible pkcs#7 signature.
* Sign a pdf with a visible pkcs#7 signature by drawing an image.
* Sign a pdf and set DocMDP(document modification detection and prevention).
* Add a new signature to a pdf if it has been signed already. (An incremental update)
* Sign a pdf with a timestamp from TSA(Time Stamp Authority). (Only in Google Apps Script)
* Set password protection to a pdf. Supported algorithms:
* 40bit RC4 Encryption
Expand Down Expand Up @@ -213,7 +214,7 @@ async function protect2(pdf, cert){
var eopt = {
mode: Zga.Crypto.Mode.AES_128,
pubkeys: [{
c: Zga.u8arrToRaw(new Uint8Array(cert)),
c: cert,
p: ["copy", "modify", "copy-extract", "annot-forms", "fill-forms", "extract", "assemble"],
}],
};
Expand Down
181 changes: 177 additions & 4 deletions closure/pdflib-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ var PdfLoadOptions;
/** @const */
var PDFLib = {};

/**
* @param {string} str
* @param {Array<number>} buffer
* @param {number} offset
* @return {number}
*/
PDFLib.copyStringIntoBuffer = function(str, buffer, offset){};
/**
* @param {string|ArrayBuffer|Uint8Array} input
* @return {Uint8Array}
*/
PDFLib.toUint8Array = function(input){};

/** @constructor */
PDFLib.PDFDocument = function(){};
/**
Expand Down Expand Up @@ -56,13 +69,60 @@ PDFLib.PDFDocument.prototype.catalog;
/** @type {PDFLib.PDFContext} */
PDFLib.PDFDocument.prototype.context;

/** @constructor */
PDFLib.PDFAcroField = function(){};
/**
* @returns {PDFLib.PDFString|PDFLib.PDFHexString}
*/
PDFLib.PDFAcroField.prototype.T = function(){};

/**
* @constructor
* @extends {PDFLib.PDFAcroField}
*/
PDFLib.PDFAcroTerminal = function(){};
/**
* @constructor
* @extends {PDFLib.PDFAcroTerminal}
*/
PDFLib.PDFAcroSignature = function(){};

/** @constructor */
PDFLib.PDFAcroForm = function(){};
/**
* @typedef
* {{
* 0: PDFLib.PDFAcroField,
* 1: PDFLib.PDFRef,
* }}
*/
var PdfFieldInfo;
/**
* @return {Array<PdfFieldInfo>}
*/
PDFLib.PDFAcroForm.prototype.getAllFields = function(){};
/**
* @param {PDFLib.PDFRef} field
*/
PDFLib.PDFAcroForm.prototype.addField = function(field){};
/** @type {PDFLib.PDFDict} */
PDFLib.PDFAcroForm.prototype.dict;

/** @constructor */
PDFLib.PDFCatalog = function(){};
/**
* @param {PDFLib.PDFName} name
* @param {PDFLib.PDFObject} object
*/
PDFLib.PDFCatalog.prototype.set = function(name, object){};
/**
* @return {PDFLib.PDFDict}
*/
PDFLib.PDFCatalog.prototype.AcroForm = function(){};
/**
* @return {PDFLib.PDFAcroForm}
*/
PDFLib.PDFCatalog.prototype.getOrCreateAcroForm = function(){};

/** @constructor */
PDFLib.PDFPage = function(){};
Expand All @@ -87,15 +147,25 @@ var PdfSize;
*/
PDFLib.PDFPage.prototype.getSize = function(){};

/** @constructor */
/**
* @constructor
* @extends {PDFLib.PDFDict}
*/
PDFLib.PDFPageLeaf = function(){};
/**
* @param {PDFLib.PDFName} name
* @param {PDFLib.PDFObject} object
*/
PDFLib.PDFPageLeaf.prototype.set = function(name, object){};
/**
* @return {PDFLib.PDFArray}
*/
PDFLib.PDFPageLeaf.prototype.Annots = function(){};

/** @constructor */
/**
* @constructor
* @extends {PDFLib.PDFObject}
*/
PDFLib.PDFRef = function(){};
/** @type {number} */
PDFLib.PDFRef.prototype.objectNumber;
Expand All @@ -108,7 +178,9 @@ PDFLib.PDFRef.prototype.generationNumber;
*/
PDFLib.PDFRef.of = function(objectNumber, generationNumber){};

/** @constructor */
/**
* @constructor
*/
PDFLib.PDFContext = function(){};
/**
* @typedef
Expand Down Expand Up @@ -154,19 +226,33 @@ PDFLib.PDFContext.prototype.obj = function(literal){};
* @return {PDFLib.PDFObject}
*/
PDFLib.PDFContext.prototype.lookup = function(ref){};
/**
* @param {PDFLib.PDFRef} ref
* @param {*} typ
* @return {PDFLib.PDFObject}
*/
PDFLib.PDFContext.prototype.lookupMaybe = function(ref, typ){};

/** @constructor */
PDFLib.PDFObject = function(){};
/** @type {Map<PDFLib.PDFRef, PDFLib.PDFObject>} */
PDFLib.PDFObject.prototype.dict;
/** @type {Array<PDFLib.PDFName>} */
PDFLib.PDFObject.prototype.array;
/**
* @param {Array<number>} _buffer
* @param {number} _offset
* @return {number}
*/
PDFLib.PDFObject.prototype.copyBytesInto = function(_buffer, _offset){};

/**
* @constructor
* @extends {PDFLib.PDFObject}
*/
PDFLib.PDFName = function(){};
/** @type {PDFLib.PDFName} */
PDFLib.PDFName.Annots;
/**
* @param {string} value
* @return {PDFLib.PDFName}
Expand All @@ -176,9 +262,12 @@ PDFLib.PDFName.of = function(value){};
PDFLib.PDFName.prototype.encodedName;
/** @type {number} */
PDFLib.PDFName.prototype.numberValue;
/** @return {string} */
PDFLib.PDFName.prototype.value = function(){};

/**
* @constructor
* @extends {PDFLib.PDFObject}
* @param {PDFLib.PDFContext} context
*/
PDFLib.PDFArray = function(context){};
Expand All @@ -191,6 +280,10 @@ PDFLib.PDFArray.prototype.push = function(object){};
* @return {PDFLib.PDFObject}
*/
PDFLib.PDFArray.prototype.get = function(idx){};
/**
* @return {Array<PDFLib.PDFObject>}
*/
PDFLib.PDFArray.prototype.asArray = function(){};

/**
* @constructor
Expand All @@ -207,6 +300,10 @@ PDFLib.PDFString.of = function(value){};
* @return {PDFLib.PDFString}
*/
PDFLib.PDFString.fromDate = function(value){};
/**
* @return {string}
*/
PDFLib.PDFString.prototype.asString = function(){};

/**
* @constructor
Expand All @@ -223,6 +320,10 @@ PDFLib.PDFHexString.of = function(value){};
* @return {PDFLib.PDFHexString}
*/
PDFLib.PDFHexString.fromText = function(value){};
/**
* @return {string}
*/
PDFLib.PDFHexString.prototype.decodeText = function(){};

/**
* @constructor
Expand Down Expand Up @@ -318,9 +419,81 @@ PDFLib.PDFFlateStream.prototype.contentsCache;
*/
PDFLib.PDFContentStream = function(){};
/**
* @param {PDFLib.PDFObject} dict
* @param {PDFLib.PDFDict} dict
* @param {Array<PDFLib.PDFOperator>} operators
* @param {boolean=} encode
* @return {PDFLib.PDFContentStream}
*/
PDFLib.PDFContentStream.of = function(dict, operators, encode){};

/**
* @constructor
* @extends {PDFLib.PDFObject}
*/
PDFLib.PDFCrossRefSection = function(){};
/**
* @return {PDFLib.PDFCrossRefSection}
*/
PDFLib.PDFCrossRefSection.create = function(){};
/**
* @param {PDFLib.PDFRef} ref
* @param {number} offset
*/
PDFLib.PDFCrossRefSection.prototype.addEntry = function (ref, offset){};
/**
* @constructor
* @extends {PDFLib.PDFObject}
*/
PDFLib.PDFDict = function(){};
/**
* @param {PDFLib.PDFName} key
* @param {PDFLib.PDFObject} value
*/
PDFLib.PDFDict.prototype.set = function(key, value){};
/**
* @param {PDFLib.PDFName} key
* @param {*} typ
* @return {PDFLib.PDFObject}
*/
PDFLib.PDFDict.prototype.lookupMaybe = function(key, typ){};
/**
* @param {PDFLib.PDFName} key
* @return {PDFLib.PDFObject}
*/
PDFLib.PDFDict.prototype.lookup = function(key){};

/**
* @constructor
* @extends {PDFLib.PDFObject}
*/
PDFLib.PDFWriter = function(){};
/**
* @param {PDFLib.PDFContext} context
* @param {number} objectsPerTick
* @return {PDFLib.PDFWriter}
*/
PDFLib.PDFWriter.forContext = function(context, objectsPerTick){};
/**
* @return {PDFLib.PDFDict}
*/
PDFLib.PDFWriter.prototype.createTrailerDict = function(){};
/**
* @constructor
* @extends {PDFLib.PDFObject}
*/
PDFLib.PDFTrailerDict = function(){};
/**
* @param {PDFLib.PDFDict} dict
* @return {PDFLib.PDFTrailerDict}
*/
PDFLib.PDFTrailerDict.of = function(dict){};
/**
* @constructor
* @extends {PDFLib.PDFObject}
*/
PDFLib.PDFTrailer = function(){};
/**
* @param {number} offset
* @return {PDFLib.PDFTrailer}
*/
PDFLib.PDFTrailer.forLastCrossRefSectionOffset = function(offset){};
Loading

0 comments on commit 22f6628

Please sign in to comment.