Skip to content

Commit b503a02

Browse files
authored
Merge pull request #859 from MrRio/bugfix-html2pdf
[WIP] Fix up html2canvas
2 parents dfc01c5 + 21aceb6 commit b503a02

File tree

12 files changed

+182
-203
lines changed

12 files changed

+182
-203
lines changed

dist/jspdf.debug.js

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
/** @preserve
1414
* jsPDF - PDF Document creation from JavaScript
15-
* Version 1.3.0 Built on 2016-09-28T10:52:40.410Z
16-
* CommitID a434267220
15+
* Version 1.3.0 Built on 2016-09-28T17:23:20.924Z
16+
* CommitID c01f6b51de
1717
*
1818
* Copyright (c) 2010-2014 James Hall <[email protected]>, https://github.com/MrRio/jsPDF
1919
* 2010 Aaron Spike, https://github.com/acspike
@@ -2026,7 +2026,7 @@
20262026
* pdfdoc.mymethod() // <- !!!!!!
20272027
*/
20282028
jsPDF.API = { events: [] };
2029-
jsPDF.version = "1.3.0 2016-09-28T10:52:40.410Z:jameshall";
2029+
jsPDF.version = "1.3.0 2016-09-28T17:23:20.924Z:jameshall";
20302030

20312031
if (typeof define === 'function' && define.amd) {
20322032
define('jsPDF', function () {
@@ -2588,25 +2588,51 @@ Q\n";
25882588
var DotRadius = AcroForm.Appearance.internal.getWidth(formObject) <= AcroForm.Appearance.internal.getHeight(formObject) ? AcroForm.Appearance.internal.getWidth(formObject) / 4 : AcroForm.Appearance.internal.getHeight(formObject) / 4;
25892589
// The Borderpadding...
25902590
DotRadius *= 0.9;
2591-
var c = AcroForm.Appearance.internal.Bezier_C;
2591+
// Save results for later use; no need to waste processor ticks on doing math
2592+
var k = DotRadius * 2;
2593+
// var c = AcroForm.Appearance.internal.Bezier_C;
2594+
var kc = k * AcroForm.Appearance.internal.Bezier_C;
2595+
var dc = DotRadius * AcroForm.Appearance.internal.Bezier_C;
2596+
// stream += "0.749023 g\n\
2597+
// q\n\
2598+
// 1 0 0 1 " + AcroForm.Appearance.internal.getWidth(formObject) / 2 + " " + AcroForm.Appearance.internal.getHeight(formObject) / 2 + " cm\n\
2599+
// " + DotRadius * 2 + " 0 m\n\
2600+
// " + DotRadius * 2 + " " + DotRadius * 2 * c + " " + DotRadius * 2 * c + " " + DotRadius * 2 + " 0 " + DotRadius * 2 + " c\n\
2601+
// -" + DotRadius * 2 * c + " " + DotRadius * 2 + " -" + DotRadius * 2 + " " + DotRadius * 2 * c + " -" + DotRadius * 2 + " 0 c\n\
2602+
// -" + DotRadius * 2 + " -" + DotRadius * 2 * c + " -" + DotRadius * 2 * c + " -" + DotRadius * 2 + " 0 -" + DotRadius * 2 + " c\n\
2603+
// " + DotRadius * 2 * c + " -" + DotRadius * 2 + " " + DotRadius * 2 + " -" + DotRadius * 2 * c + " " + DotRadius * 2 + " 0 c\n\
2604+
// f\n\
2605+
// Q\n\
2606+
// 0 g\n\
2607+
// q\n\
2608+
// 1 0 0 1 " + AcroForm.Appearance.internal.getWidth(formObject) / 2 + " " + AcroForm.Appearance.internal.getHeight(formObject) / 2 + " cm\n\
2609+
// " + DotRadius + " 0 m\n\
2610+
// " + DotRadius + " " + DotRadius * c + " " + DotRadius * c + " " + DotRadius + " 0 " + DotRadius + " c\n\
2611+
// -" + DotRadius * c + " " + DotRadius + " -" + DotRadius + " " + DotRadius * c + " -" + DotRadius + " 0 c\n\
2612+
// -" + DotRadius + " -" + DotRadius * c + " -" + DotRadius * c + " -" + DotRadius + " 0 -" + DotRadius + " c\n\
2613+
// " + DotRadius * c + " -" + DotRadius + " " + DotRadius + " -" + DotRadius * c + " " + DotRadius + " 0 c\n\
2614+
// f\n\
2615+
// Q\n";
2616+
2617+
// FASTER VERSION with less processor ticks spent on math operations
25922618
stream += "0.749023 g\n\
25932619
q\n\
25942620
1 0 0 1 " + AcroForm.Appearance.internal.getWidth(formObject) / 2 + " " + AcroForm.Appearance.internal.getHeight(formObject) / 2 + " cm\n\
2595-
" + DotRadius * 2 + " 0 m\n\
2596-
" + DotRadius * 2 + " " + DotRadius * 2 * c + " " + DotRadius * 2 * c + " " + DotRadius * 2 + " 0 " + DotRadius * 2 + " c\n\
2597-
-" + DotRadius * 2 * c + " " + DotRadius * 2 + " -" + DotRadius * 2 + " " + DotRadius * 2 * c + " -" + DotRadius * 2 + " 0 c\n\
2598-
-" + DotRadius * 2 + " -" + DotRadius * 2 * c + " -" + DotRadius * 2 * c + " -" + DotRadius * 2 + " 0 -" + DotRadius * 2 + " c\n\
2599-
" + DotRadius * 2 * c + " -" + DotRadius * 2 + " " + DotRadius * 2 + " -" + DotRadius * 2 * c + " " + DotRadius * 2 + " 0 c\n\
2621+
" + k + " 0 m\n\
2622+
" + k + " " + kc + " " + kc + " " + k + " 0 " + k + " c\n\
2623+
-" + kc + " " + k + " -" + k + " " + kc + " -" + k + " 0 c\n\
2624+
-" + k + " -" + kc + " -" + kc + " -" + k + " 0 -" + k + " c\n\
2625+
" + kc + " -" + k + " " + k + " -" + kc + " " + k + " 0 c\n\
26002626
f\n\
26012627
Q\n\
26022628
0 g\n\
26032629
q\n\
26042630
1 0 0 1 " + AcroForm.Appearance.internal.getWidth(formObject) / 2 + " " + AcroForm.Appearance.internal.getHeight(formObject) / 2 + " cm\n\
26052631
" + DotRadius + " 0 m\n\
2606-
" + DotRadius + " " + DotRadius * c + " " + DotRadius * c + " " + DotRadius + " 0 " + DotRadius + " c\n\
2607-
-" + DotRadius * c + " " + DotRadius + " -" + DotRadius + " " + DotRadius * c + " -" + DotRadius + " 0 c\n\
2608-
-" + DotRadius + " -" + DotRadius * c + " -" + DotRadius * c + " -" + DotRadius + " 0 -" + DotRadius + " c\n\
2609-
" + DotRadius * c + " -" + DotRadius + " " + DotRadius + " -" + DotRadius * c + " " + DotRadius + " 0 c\n\
2632+
" + DotRadius + " " + dc + " " + dc + " " + DotRadius + " 0 " + DotRadius + " c\n\
2633+
-" + dc + " " + DotRadius + " -" + DotRadius + " " + dc + " -" + DotRadius + " 0 c\n\
2634+
-" + DotRadius + " -" + dc + " -" + dc + " -" + DotRadius + " 0 -" + DotRadius + " c\n\
2635+
" + dc + " -" + DotRadius + " " + DotRadius + " -" + dc + " " + DotRadius + " 0 c\n\
26102636
f\n\
26112637
Q\n";
26122638
xobj.stream = stream;
@@ -2618,15 +2644,30 @@ Q\n";
26182644
var DotRadius = AcroForm.Appearance.internal.getWidth(formObject) <= AcroForm.Appearance.internal.getHeight(formObject) ? AcroForm.Appearance.internal.getWidth(formObject) / 4 : AcroForm.Appearance.internal.getHeight(formObject) / 4;
26192645
// The Borderpadding...
26202646
DotRadius *= 0.9;
2621-
var c = AcroForm.Appearance.internal.Bezier_C;
2647+
// Save results for later use; no need to waste processor ticks on doing math
2648+
var k = DotRadius * 2;
2649+
// var c = AcroForm.Appearance.internal.Bezier_C;
2650+
var kc = k * AcroForm.Appearance.internal.Bezier_C;
2651+
// stream += "0.749023 g\n\
2652+
// q\n\
2653+
// 1 0 0 1 " + AcroForm.Appearance.internal.getWidth(formObject) / 2 + " " + AcroForm.Appearance.internal.getHeight(formObject) / 2 + " cm\n\
2654+
// " + DotRadius * 2 + " 0 m\n\
2655+
// " + DotRadius * 2 + " " + DotRadius * 2 * c + " " + DotRadius * 2 * c + " " + DotRadius * 2 + " 0 " + DotRadius * 2 + " c\n\
2656+
// -" + DotRadius * 2 * c + " " + DotRadius * 2 + " -" + DotRadius * 2 + " " + DotRadius * 2 * c + " -" + DotRadius * 2 + " 0 c\n\
2657+
// -" + DotRadius * 2 + " -" + DotRadius * 2 * c + " -" + DotRadius * 2 * c + " -" + DotRadius * 2 + " 0 -" + DotRadius * 2 + " c\n\
2658+
// " + DotRadius * 2 * c + " -" + DotRadius * 2 + " " + DotRadius * 2 + " -" + DotRadius * 2 * c + " " + DotRadius * 2 + " 0 c\n\
2659+
// f\n\
2660+
// Q\n";
2661+
2662+
// FASTER VERSION with less processor ticks spent on math operations
26222663
stream += "0.749023 g\n\
26232664
q\n\
26242665
1 0 0 1 " + AcroForm.Appearance.internal.getWidth(formObject) / 2 + " " + AcroForm.Appearance.internal.getHeight(formObject) / 2 + " cm\n\
2625-
" + DotRadius * 2 + " 0 m\n\
2626-
" + DotRadius * 2 + " " + DotRadius * 2 * c + " " + DotRadius * 2 * c + " " + DotRadius * 2 + " 0 " + DotRadius * 2 + " c\n\
2627-
-" + DotRadius * 2 * c + " " + DotRadius * 2 + " -" + DotRadius * 2 + " " + DotRadius * 2 * c + " -" + DotRadius * 2 + " 0 c\n\
2628-
-" + DotRadius * 2 + " -" + DotRadius * 2 * c + " -" + DotRadius * 2 * c + " -" + DotRadius * 2 + " 0 -" + DotRadius * 2 + " c\n\
2629-
" + DotRadius * 2 * c + " -" + DotRadius * 2 + " " + DotRadius * 2 + " -" + DotRadius * 2 * c + " " + DotRadius * 2 + " 0 c\n\
2666+
" + k + " 0 m\n\
2667+
" + k + " " + kc + " " + kc + " " + k + " 0 " + k + " c\n\
2668+
-" + kc + " " + k + " -" + k + " " + kc + " -" + k + " 0 c\n\
2669+
-" + k + " -" + kc + " -" + kc + " -" + k + " 0 -" + k + " c\n\
2670+
" + kc + " -" + k + " " + k + " -" + kc + " " + k + " 0 c\n\
26302671
f\n\
26312672
Q\n";
26322673
xobj.stream = stream;

dist/jspdf.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/html2pdf/auto_break.html

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,34 +144,28 @@ <h1>Autobreak</h1>
144144
</ol>
145145
</div>
146146

147-
<script src='../../libs/require/require.js'></script>
148-
147+
<script src='../../../dist/jspdf.debug.js'></script>
148+
<script src='../../libs/html2pdf.js'></script>
149149
<script>
150-
require_baseUrl_override = '../..';
151-
require(['../../libs/require/config'], function(){
152-
require(['html2pdf'], function(){
153150
var pdf = new jsPDF('p', 'pt', 'letter');
154151
var canvas = pdf.canvas;
155152
canvas.height = 72 * 11;
156153
canvas.width=72 * 8.5;;
157154
// var width = 400;
158-
155+
159156
document.body.style.width = 400 + 'px';
160-
161-
html2pdf(document.body, pdf, function(pdf) {
157+
158+
html2pdf(document.body, pdf, function(pdf) {
162159
var iframe = document.createElement('iframe');
163160
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
164161
document.body.appendChild(iframe);
165162
iframe.src = pdf.output('datauristring');
166-
163+
167164
//var div = document.createElement('pre');
168165
//div.innerText=pdf.output();
169166
//document.body.appendChild(div);
170167
}
171168
);
172-
173-
}); // require
174-
}); // require
175169
</script>
176170
</body>
177171
</html>

examples/html2pdf/lists.html

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h2>Not Implemented</h2>
3434
armenian
3535
cjk-ideographic
3636
decimal-leading-zero
37-
georgian
37+
georgian
3838
hebrew
3939
hiragana
4040
hiragana-iroha
@@ -43,33 +43,23 @@ <h2>Not Implemented</h2>
4343
</pre>
4444
</div>
4545

46-
<script src='../../libs/require/require.js'></script>
46+
<script src='../../../dist/jspdf.debug.js'></script>
47+
<script src='../../libs/html2pdf.js'></script>
4748

4849
<script>
49-
require_baseUrl_override = '../..';
50-
require(['../../libs/require/config'], function(){
51-
require(['html2pdf'], function(){
52-
53-
var pdf = new jsPDF('p', 'pt', 'letter');
54-
var canvas = pdf.canvas;
55-
canvas.height = 72 * 11;
56-
canvas.width=72 * 8.5;;
57-
// var width = 400;
58-
59-
html2pdf(document.body, pdf, function(canvas) {
60-
var iframe = document.createElement('iframe');
61-
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
62-
document.body.appendChild(iframe);
63-
iframe.src = pdf.output('datauristring');
64-
65-
//var div = document.createElement('pre');
66-
//div.innerText=pdf.output();
67-
//document.body.appendChild(div);
68-
}
69-
);
70-
71-
}); // require
72-
}); // require
73-
</script>
50+
var pdf = new jsPDF('p', 'pt', 'letter');
51+
var canvas = pdf.canvas;
52+
canvas.height = 72 * 11;
53+
canvas.width=72 * 8.5;;
54+
// var width = 400;
55+
56+
html2pdf(document.body, pdf, function(canvas) {
57+
var iframe = document.createElement('iframe');
58+
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
59+
document.body.appendChild(iframe);
60+
iframe.src = pdf.output('datauristring');
61+
}
62+
);
63+
</script>
7464
</body>
7565
</html>

examples/html2pdf/page_break.html

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,20 @@ <h1 style='page-break-before: always'>Text</h1>
3535

3636
</div>
3737

38-
<script src='../../libs/require/require.js'></script>
39-
38+
<script src='../../../dist/jspdf.debug.js'></script>
39+
<script src='../../libs/html2pdf.js'></script>
4040
<script>
41-
require_baseUrl_override = '../..';
42-
require(['../../libs/require/config'], function(){
43-
require(['html2pdf'], function(){
44-
45-
var pdf = new jsPDF('p', 'pt', 'letter');
46-
pdf.canvas.height = 72 * 11;
47-
pdf.canvas.width = 72 * 8.5;
48-
49-
//html2pdf(document.documentElement.innerHTML, pdf, function(pdf){
50-
html2pdf(document.body, pdf, function(pdf){
51-
var iframe = document.createElement('iframe');
52-
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
53-
document.body.appendChild(iframe);
54-
iframe.src = pdf.output('datauristring');
55-
});
56-
57-
}); // require
58-
}); // require
59-
</script>
41+
var pdf = new jsPDF('p', 'pt', 'letter');
42+
pdf.canvas.height = 72 * 11;
43+
pdf.canvas.width = 72 * 8.5;
44+
45+
//html2pdf(document.documentElement.innerHTML, pdf, function(pdf){
46+
html2pdf(document.body, pdf, function(pdf){
47+
var iframe = document.createElement('iframe');
48+
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
49+
document.body.appendChild(iframe);
50+
iframe.src = pdf.output('datauristring');
51+
});
52+
</script>
6053
</body>
6154
</html>

examples/html2pdf/pdf.html

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -153,34 +153,28 @@ <h1>sing to me, erbarme dich</h1>
153153
This is a nonsensical document, but syntactically valid HTML 4.0. All 100% conformant CSS1 agents should be able to render the document elements above this paragraph <b>indistinguishably</b> (to the pixel) from this reference rendering, (except font rasterization and form widgets). All discrepancies should be traceable to CSS1 implementation shortcomings. Once you have finished evaluating this test, you can return to the <A HREF="sec5526c.htm" style="text-decoration: none">parent page</A>.
154154
</p>
155155

156-
<script src='../../libs/require/require.js'></script>
157-
158-
<script>
159-
require_baseUrl_override = '../..';
160-
require(['../../libs/require/config'], function(){
161-
require(['html2pdf'], function(){
162-
163-
var pdf = new jsPDF('p', 'pt', 'letter');
164-
var canvas = pdf.canvas;
165-
166-
canvas.width=8.5*72;
167-
168-
html2canvas(document.body, {
169-
canvas:canvas,
170-
onrendered: function(canvas) {
171-
var iframe = document.createElement('iframe');
172-
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
173-
document.body.appendChild(iframe);
174-
iframe.src = pdf.output('datauristring');
175-
176-
//var div = document.createElement('pre');
177-
//div.innerText=pdf.output();
178-
//document.body.appendChild(div);
179-
}
180-
});
181-
182-
}); // require
183-
}); // require
156+
<script src='../../../dist/jspdf.debug.js'></script>
157+
<script src='../../libs/html2pdf.js'></script>
158+
<script>
159+
160+
var pdf = new jsPDF('p', 'pt', 'letter');
161+
var canvas = pdf.canvas;
162+
163+
canvas.width = 8.5 * 72;
164+
165+
html2canvas(document.body, {
166+
canvas:canvas,
167+
onrendered: function(canvas) {
168+
var iframe = document.createElement('iframe');
169+
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
170+
document.body.appendChild(iframe);
171+
iframe.src = pdf.output('datauristring');
172+
173+
//var div = document.createElement('pre');
174+
//div.innerText=pdf.output();
175+
//document.body.appendChild(div);
176+
}
177+
});
184178
</script>
185179
</body>
186180
</html>

examples/html2pdf/pdf2.html

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,30 @@ <h2>More content</h2>
5858
</div>
5959
</div>
6060

61-
<script src='../../libs/require/require.js'></script>
61+
62+
<script src='../../../dist/jspdf.debug.js'></script>
63+
<script src='../../libs/html2pdf.js'></script>
6264

6365
<script>
64-
require_baseUrl_override = '../..';
65-
require(['../../libs/require/config'], function(){
66-
require(['html2pdf'], function(){
67-
68-
var pdf = new jsPDF('p', 'pt', 'letter');
69-
var canvas = pdf.canvas;
70-
71-
var width = 600;
72-
//canvas.width=8.5*72;
73-
document.body.style.width=width + "px";
74-
75-
html2canvas(document.body, {
76-
canvas:canvas,
77-
onrendered: function(canvas) {
78-
var iframe = document.createElement('iframe');
79-
iframe.setAttribute('style', 'position:absolute;top:0;right:0;height:100%; width:600px');
80-
document.body.appendChild(iframe);
81-
iframe.src = pdf.output('datauristring');
82-
83-
//var div = document.createElement('pre');
84-
//div.innerText=pdf.output();
85-
//document.body.appendChild(div);
86-
}
87-
});
88-
89-
});
90-
});
66+
var pdf = new jsPDF('p', 'pt', 'letter');
67+
var canvas = pdf.canvas;
68+
var width = 600;
69+
//canvas.width=8.5*72;
70+
document.body.style.width=width + "px";
71+
72+
html2canvas(document.body, {
73+
canvas:canvas,
74+
onrendered: function(canvas) {
75+
var iframe = document.createElement('iframe');
76+
iframe.setAttribute('style', 'position:absolute;top:0;right:0;height:100%; width:600px');
77+
document.body.appendChild(iframe);
78+
iframe.src = pdf.output('datauristring');
79+
80+
//var div = document.createElement('pre');
81+
//div.innerText=pdf.output();
82+
//document.body.appendChild(div);
83+
}
84+
});
9185
</script>
9286
</body>
9387
</html>

0 commit comments

Comments
 (0)