Skip to content

Commit 672105c

Browse files
committed
fromHTML fixes kindly suggested by @mcurland
1 parent 2bb6a89 commit 672105c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

jspdf.plugin.from_html.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@
621621
return $frame.document.body;
622622
})(element.replace(/<\/?script[^>]*?>/gi, ''));
623623
}
624-
var r = new Renderer(pdf, x, y, settings);
624+
var r = new Renderer(pdf, x, y, settings), out;
625625

626626
// 1. load images
627627
// 2. prepare optional footer elements
@@ -631,11 +631,11 @@
631631
DrillForContent(element, r, settings.elementHandlers);
632632
//send event dispose for final taks (e.g. footer totalpage replacement)
633633
r.pdf.internal.events.publish('htmlRenderingFinished');
634-
r = r.dispose();
635-
if (typeof callback === 'function') callback(r);
634+
out = r.dispose();
635+
if (typeof callback === 'function') callback(out);
636636
else if (found_images) console.error('jsPDF Warning: rendering issues? provide a callback to fromHTML!');
637637
});
638-
return pdf;
638+
return out || {x: r.x, y:r.y};
639639
};
640640
Renderer.prototype.init = function () {
641641
this.paragraph = {
@@ -648,7 +648,8 @@
648648
this.pdf.internal.write("Q");
649649
return {
650650
x : this.x,
651-
y : this.y
651+
y : this.y,
652+
ready:true
652653
};
653654
};
654655

@@ -775,7 +776,7 @@
775776
this.pdf.internal.write("ET", "Q");
776777
this.pdf.addPage();
777778
this.y = this.pdf.margins_doc.top;
778-
this.pdf.internal.write("q", "BT", this.pdf.internal.getCoordinateString(this.x), this.pdf.internal.getVerticalCoordinateString(this.y), "Td");
779+
this.pdf.internal.write("q", "BT 0 g", this.pdf.internal.getCoordinateString(this.x), this.pdf.internal.getVerticalCoordinateString(this.y), "Td");
779780
//move cursor by one line on new page
780781
maxLineHeight = Math.max(maxLineHeight, style["line-height"], style["font-size"]);
781782
this.pdf.internal.write(0, (-1 * defaultFontSize * maxLineHeight).toFixed(2), "Td");
@@ -835,7 +836,7 @@
835836
i = void 0;
836837
l = void 0;
837838
this.y += paragraphspacing_before;
838-
out("q", "BT", this.pdf.internal.getCoordinateString(this.x), this.pdf.internal.getVerticalCoordinateString(this.y), "Td");
839+
out("q", "BT 0 g", this.pdf.internal.getCoordinateString(this.x), this.pdf.internal.getVerticalCoordinateString(this.y), "Td");
839840

840841
//stores the current indent of cursor position
841842
var currentIndent = 0;
@@ -894,7 +895,7 @@
894895
lines = this.splitFragmentsIntoLines(PurgeWhiteSpace(localFragments), localStyles);
895896
//reposition the current cursor
896897
out("ET", "Q");
897-
out("q", "BT", this.pdf.internal.getCoordinateString(this.x), this.pdf.internal.getVerticalCoordinateString(this.y), "Td");
898+
out("q", "BT 0 g", this.pdf.internal.getCoordinateString(this.x), this.pdf.internal.getVerticalCoordinateString(this.y), "Td");
898899
}
899900

900901
}

0 commit comments

Comments
 (0)