Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/jspdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5689,7 +5689,10 @@ function jsPDF(options) {

var endFormObject = function(key) {
// only add it if it is not already present (the keys provided by the user must be unique!)
if (renderTargetMap[key]) return;
if (renderTargetMap[key]) {
renderTargetStack.pop().restore();
return;
}

// save the created xObject
var newXObject = new RenderTarget();
Expand Down
23 changes: 21 additions & 2 deletions test/specs/jspdf.unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3056,8 +3056,7 @@ This is a test too.`,
writeArray = [];
doc.__private__.setCustomOutputDestination(writeArray);
doc.__private__.putStream({
data:
"x\u009C+.)JMÌuI,I\u0004\u0000\u0016Ò\u0004\u0007",
data: "x\u009C+.)JMÌuI,I\u0004\u0000\u0016Ò\u0004\u0007",
alreadyAppliedFilters: ["/FlateDecode"]
});
expect(bufferFromString(writeArray.join("\n"))).toEqual(expected);
Expand Down Expand Up @@ -3100,6 +3099,7 @@ This is a test too.`,
objId: 3,
contentsObjId: 4
});

expect(writeArray).toEqual([
"3 0 obj",
"<</Type /Page",
Expand Down Expand Up @@ -3607,6 +3607,25 @@ This is a test too.`,
"%%EOF"
]);
});

it("jsPdf public function beginFormObject, endFormObject", () => {
var doc = jsPDF();
var startContext = doc.internal.getCurrentPageInfo().pageContext;
doc.beginFormObject(0, 0, 100, 100, new doc.internal.Matrix(1, 0, 0, 1, 0, 0));
expect(doc.internal.getCurrentPageInfo().pageContext).not.toEqual(
startContext
);
doc.endFormObject("testFormObject");
expect(doc.internal.getCurrentPageInfo().pageContext).toEqual(startContext);

// Adding a form object with the same id twice should keep stack intact
doc.beginFormObject(0, 0, 100, 100, new doc.internal.Matrix(1, 0, 0, 1, 0, 0));
expect(doc.internal.getCurrentPageInfo().pageContext).not.toEqual(
startContext
);
doc.endFormObject("testFormObject");
expect(doc.internal.getCurrentPageInfo().pageContext).toEqual(startContext);
});
});

function bufferFromString(string) {
Expand Down