Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/jspdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,8 @@ function jsPDF(options) {
subject: "",
author: "",
keywords: "",
creator: ""
creator: "",
producer: ""
};

API.__private__.getDocumentProperty = function(key) {
Expand Down Expand Up @@ -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() +
Expand Down
43 changes: 42 additions & 1 deletion test/specs/jspdf.unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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 });

Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ declare module "jspdf" {
author?: string;
keywords?: string;
creator?: string;
producer?: string;
}

export interface PatternData {
Expand Down