diff --git a/src/jspdf.js b/src/jspdf.js index cf95600a4..96b452db6 100644 --- a/src/jspdf.js +++ b/src/jspdf.js @@ -1005,7 +1005,8 @@ function jsPDF(options) { subject: "", author: "", keywords: "", - creator: "" + creator: "", + producer: "" }; API.__private__.getDocumentProperty = function(key) { @@ -2856,9 +2857,14 @@ function jsPDF(options) { encryptor = encryption.encryptor(objectId, 0); } out("<<"); - out("/Producer (" + pdfEscape(encryptor("jsPDF " + jsPDF.version)) + ")"); + var producerValue = documentProperties.producer || "jsPDF " + jsPDF.version; + out("/Producer (" + pdfEscape(encryptor(producerValue)) + ")"); for (var key in documentProperties) { - if (documentProperties.hasOwnProperty(key) && documentProperties[key]) { + if ( + documentProperties.hasOwnProperty(key) && + key !== "producer" && + documentProperties[key] + ) { out( "/" + key.substr(0, 1).toUpperCase() + diff --git a/test/specs/jspdf.unit.spec.js b/test/specs/jspdf.unit.spec.js index 651cf8eff..86633db1b 100644 --- a/test/specs/jspdf.unit.spec.js +++ b/test/specs/jspdf.unit.spec.js @@ -1302,7 +1302,8 @@ describe("Core: Unit Tests", () => { subject: "", author: "", keywords: "", - creator: "" + creator: "", + producer: "" }); // expect(function() {doc.__private__.setDocumentProperty('invalid', 'Title');}).toThrow(new Error('Invalid arguments passed to jsPDF.setDocumentProperty')); @@ -2920,6 +2921,46 @@ This is a test too.`, ]); }); + it("jsPDF private function putInfo with custom producer", () => { + var doc = jsPDF({ floatPrecision: 2 }); + var writeArray = []; + doc.__private__.setCustomOutputDestination(writeArray); + var pdfDateString = "D:19871210000000+00'00'"; + doc.__private__.setCreationDate(pdfDateString); + doc.__private__.setDocumentProperty("producer", "Custom Producer v1.0"); + doc.__private__.putInfo(); + expect(writeArray).toEqual([ + "3 0 obj", + "<<", + "/Producer (Custom Producer v1.0)", + "/CreationDate (D:19871210000000+00'00')", + ">>", + "endobj" + ]); + }); + + it("jsPDF private function putInfo with producer via setDocumentProperties", () => { + var doc = jsPDF({ floatPrecision: 2 }); + var writeArray = []; + doc.__private__.setCustomOutputDestination(writeArray); + var pdfDateString = "D:19871210000000+00'00'"; + doc.__private__.setCreationDate(pdfDateString); + doc.__private__.setDocumentProperties({ + title: "Title", + producer: "My App v2.0" + }); + doc.__private__.putInfo(); + expect(writeArray).toEqual([ + "3 0 obj", + "<<", + "/Producer (My App v2.0)", + "/Title (Title)", + "/CreationDate (D:19871210000000+00'00')", + ">>", + "endobj" + ]); + }); + it("jsPDF private function putTrailer", () => { var doc = jsPDF({ floatPrecision: 2 }); diff --git a/types/index.d.ts b/types/index.d.ts index fd21f959a..292b989f5 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -685,6 +685,7 @@ declare module "jspdf" { author?: string; keywords?: string; creator?: string; + producer?: string; } export interface PatternData {