Skip to content

Commit bbd00a3

Browse files
committed
[from_html plugin] support for page-break-before
1 parent f085fb1 commit bbd00a3

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

jspdf.plugin.from_html.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@
212212
css["padding-left"] = tmp && ResolveUnitedNumber(computedCSSElement("padding-left")) || 0;
213213
css["padding-right"] = tmp && ResolveUnitedNumber(computedCSSElement("padding-right")) || 0;
214214

215+
css["page-break-before"] = computedCSSElement("page-break-before") || "auto";
216+
215217
//float and clearing of floats
216218
css["float"] = FloatMap[computedCSSElement("cssFloat")] || "none";
217219
css["clear"] = ClearMap[computedCSSElement("clear")] || "none";
@@ -838,6 +840,12 @@
838840
paragraphspacing_after = ((blockstyle["margin-bottom"] || 0) + (blockstyle["padding-bottom"] || 0)) * fontToUnitRatio;
839841
this.priorMarginBottom = blockstyle["margin-bottom"] || 0;
840842

843+
if (blockstyle['page-break-before'] === 'always'){
844+
this.pdf.addPage();
845+
this.y = 0;
846+
paragraphspacing_before = ((blockstyle["margin-top"] || 0) + (blockstyle["padding-top"] || 0)) * fontToUnitRatio;
847+
}
848+
841849
out = this.pdf.internal.write;
842850
i = void 0;
843851
l = void 0;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!doctype html>
2+
<!--
3+
/**
4+
* jsPDF Test HTML PlugIn
5+
* Copyright (c) 2014 Steven Spungin (TwelveTone LLC) [email protected]
6+
*
7+
* Licensed under the MIT License.
8+
* http://opensource.org/licenses/mit-license
9+
*/
10+
-->
11+
12+
<html>
13+
<head>
14+
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
15+
16+
<title>Test HTML</title>
17+
18+
<!-- Required Files -->
19+
<script type="text/javascript" src="../jspdf.js"></script>
20+
<!-- Plugin Dependencies -->
21+
<script type="text/javascript" src="../jspdf.plugin.standard_fonts_metrics.js"></script>
22+
<script type="text/javascript" src="../jspdf.plugin.split_text_to_size.js"></script>
23+
<script type="text/javascript" src="../jspdf.plugin.from_html.js"></script>
24+
<!-- Plugin To Test -->
25+
<script type="text/javascript" src="test_harness.js"></script>
26+
<!-- Test Dependencies -->
27+
28+
<script>
29+
pdf_test_harness.onload = function(harness) {
30+
var pdf = new jsPDF('p', 'pt', 'letter');
31+
var ta = document.getElementById('textarea');
32+
33+
pdf.fromHTML(ta.value, 0, 0);
34+
35+
ta.onkeyup = function(){
36+
var pdf = new jsPDF('p', 'pt', 'letter');
37+
pdf.fromHTML(ta.value, 0, 0);
38+
harness.setPdf(pdf);
39+
}
40+
41+
harness.header.style.left='300px';
42+
harness.body.style.left='300px';
43+
44+
return pdf;
45+
}
46+
47+
48+
</script>
49+
50+
</head>
51+
52+
<body style='background-color: silver; margin: 0;'>
53+
<textarea id='textarea' style='position:fixed;left:0;width:290px;height:100%'>
54+
55+
<html>
56+
<head>
57+
<style>
58+
.break{
59+
page-break-before:always;
60+
}
61+
body{
62+
font-size:2em;
63+
}
64+
</style>
65+
</head>
66+
<body>
67+
<div>page 1 <em>ok?</em></div>
68+
<div class='break'>page 2</div>
69+
<div class='break' style='margin-top:1in'>page 3</div>
70+
</body>
71+
</html>
72+
73+
</textarea>
74+
</body>
75+
</html>

0 commit comments

Comments
 (0)