Skip to content

Commit 87fd3f2

Browse files
authored
Deprecate addhtml and fromHTML and provide html plugin (#1934)
* Delete standard.spec.js * Delete html-output.pdf * Rename plugins/addhtml.js to deprecated/addhtml.js * Rename plugins/from_html.js to deprecated/from_html.js * Delete test_from_html.html * Update main_plugins.js * Add files via upload * Add files via upload * Update main_plugins.js * Add files via upload * Update main_libs.js * Add files via upload * Update html.js
1 parent 1449e14 commit 87fd3f2

20 files changed

+849
-211
lines changed
File renamed without changes.
File renamed without changes.

examples/html2pdf/acid.html

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,12 @@ <h1>sing to me, erbarme dich</h1>
157157
<script>
158158

159159
var pdf = new jsPDF('p', 'pt', 'letter');
160-
var canvas = pdf.canvas;
161-
162-
canvas.width = 8.5 * 72;
163-
164-
html2canvas(document.body, {canvas:canvas})
165-
.then(function(canvas) {
160+
pdf.html(document.body, {callback: function(pdf) {
166161
var iframe = document.createElement('iframe');
167162
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
168163
document.body.appendChild(iframe);
169164
iframe.src = pdf.output('datauristring');
170-
171-
//var div = document.createElement('pre');
172-
//div.innerText=pdf.output();
173-
//document.body.appendChild(div);
165+
}
174166
});
175167
</script>
176168
</body>

examples/html2pdf/acid2.html

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,16 @@
102102
function onLoad() {
103103
window.setTimeout (function () {
104104
var pdf = new jsPDF('p', 'pt', 'letter');
105-
var canvas = pdf.canvas;
106-
canvas.height = 96 * 11;
107-
canvas.width= 96 * 8.5;;
108-
// var width = 400;
109-
110105
document.body.style.width = 400 + 'px';
111106

112-
html2pdf(document.body, pdf,
113-
function(pdf) {
107+
var pdf = new jsPDF('p', 'pt', 'letter');
108+
pdf.html(document.body, {callback: function(pdf) {
114109
var iframe = document.createElement('iframe');
115110
iframe.setAttribute('style','position:fixed;right:0; top:0; bottom:0; height:100%; width:500px');
116111
document.body.appendChild(iframe);
117112
iframe.src = pdf.output('datauristring');
118-
}
119-
);
113+
}
114+
});
120115
}, 2000);
121116
}
122117
</script>

examples/html2pdf/auto_break.html

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</style>
88
</head>
99
<body>
10-
<div style='position: absolute; left: 0; top: 0; bottom: 0; width: 400px; overflow: auto'>
10+
<div id="html" style='position: absolute; left: 0; top: 0; bottom: 0; width: 400px; overflow: auto'>
1111
<h1>Autobreak</h1>
1212
<p>The context2d plugin was tweaked to auto-break a document into multiple pages.</p>
1313
<p>The auto-page-break feature allows vertical positioning by addressing the Y coordinate beyond the PDF page.</p>
@@ -147,24 +147,13 @@ <h1>Autobreak</h1>
147147
<script src='../../dist/jspdf.debug.js'></script>
148148
<script>
149149
var pdf = new jsPDF('p', 'pt', 'letter');
150-
var canvas = pdf.canvas;
151-
canvas.height = 96 * 11;
152-
canvas.width= 96 * 8.5;;
153-
// var width = 400;
154-
155-
document.body.style.width = 400 + 'px';
156-
157-
html2pdf(document.body, pdf, function(pdf) {
150+
pdf.html(document.getElementById('html'), {callback: function(pdf) {
158151
var iframe = document.createElement('iframe');
159152
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
160153
document.body.appendChild(iframe);
161154
iframe.src = pdf.output('datauristring');
162-
163-
//var div = document.createElement('pre');
164-
//div.innerText=pdf.output();
165-
//document.body.appendChild(div);
166155
}
167-
);
156+
});
168157
</script>
169158
</body>
170159
</html>

examples/html2pdf/lists.html

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</style>
88
</head>
99
<body>
10-
<div style='position: absolute'>
10+
<div id="html" style='position: absolute'>
1111
<h1>Ordered And Unordered Lists</h1>
1212
<h2>Implemented</h2>
1313
<ol>
@@ -48,17 +48,14 @@ <h2>Not Implemented</h2>
4848
<script>
4949
var pdf = new jsPDF('p', 'pt', 'letter');
5050
var canvas = pdf.canvas;
51-
canvas.height = 72 * 11;
52-
canvas.width=72 * 8.5;;
53-
// var width = 400;
5451

55-
html2pdf(document.body, pdf, function(canvas) {
56-
var iframe = document.createElement('iframe');
57-
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
58-
document.body.appendChild(iframe);
59-
iframe.src = pdf.output('datauristring');
52+
pdf.html(document.getElementById('html'), {callback: function(pdf) {
53+
var iframe = document.createElement('iframe');
54+
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
55+
document.body.appendChild(iframe);
56+
iframe.src = pdf.output('datauristring');
6057
}
61-
);
58+
});
6259
</script>
6360
</body>
6461
</html>

examples/html2pdf/page_break.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</style>
1616
</head>
1717
<body>
18-
<div style='position: absolute; left: 0; top: 0; bottom: 0; overflow: auto; width: 400px'>
18+
<div id="html" style='position: absolute; left: 0; top: 0; bottom: 0; overflow: auto; width: 400px'>
1919
This example show how the <em>page-break-before</em> style is rendered.
2020

2121
<h1 style='page-break-before: always'>Numbers</h1>
@@ -38,16 +38,13 @@ <h1 style='page-break-before: always'>Text</h1>
3838
<script src='../../dist/jspdf.debug.js'></script>
3939
<script>
4040
var pdf = new jsPDF('p', 'pt', 'letter');
41-
pdf.canvas.height = 72 * 11;
42-
pdf.canvas.width = 72 * 8.5;
4341

44-
//html2pdf(document.documentElement.innerHTML, pdf, function(pdf){
45-
html2pdf(document.body, pdf, function(pdf){
42+
pdf.html(document.getElementById('html'), {callback: function(pdf) {
4643
var iframe = document.createElement('iframe');
4744
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
4845
document.body.appendChild(iframe);
4946
iframe.src = pdf.output('datauristring');
50-
});
47+
}});
5148
</script>
5249
</body>
5350
</html>

examples/html2pdf/pdf2.html

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</style>
3535
</head>
3636
<body>
37-
<div style="background: red;">
37+
<div id="html" style="background: red;">
3838
<div style="background: green;">
3939
<div style="background: blue; border-color: white;">
4040
<div style="background: yellow;">
@@ -63,21 +63,15 @@ <h2>More content</h2>
6363

6464
<script>
6565
var pdf = new jsPDF('p', 'pt', 'letter');
66-
var canvas = pdf.canvas;
6766
var width = 600;
68-
//canvas.width=8.5*72;
6967
document.body.style.width=width + "px";
7068

71-
html2canvas(document.body, {canvas:canvas})
72-
.then(function(canvas) {
69+
pdf.html(document.body, {callback: function(pdf) {
7370
var iframe = document.createElement('iframe');
7471
iframe.setAttribute('style', 'position:absolute;top:0;right:0;height:100%; width:600px');
7572
document.body.appendChild(iframe);
7673
iframe.src = pdf.output('datauristring');
77-
78-
//var div = document.createElement('pre');
79-
//div.innerText=pdf.output();
80-
//document.body.appendChild(div);
74+
}
8175
});
8276
</script>
8377
</body>

examples/html2pdf/showcase.html

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</style>
88
</head>
99
<body>
10-
<div style='position: absolute; left: 0; top: 0; bottom: 0; overflow: auto; width: 400px'>
10+
<div id="html" style='position: absolute; left: 0; top: 0; bottom: 0; overflow: auto; width: 400px'>
1111

1212

1313
<h1>Html2Pdf</h1>
@@ -70,21 +70,13 @@ <h2>Font Size</h2>
7070

7171
<script>
7272
var pdf = new jsPDF('p', 'pt', 'letter');
73-
var canvas = pdf.canvas;
74-
canvas.height = 72 * 11;
75-
canvas.width=72 * 8.5;;
76-
// var width = 400;
77-
78-
html2pdf(document.body, pdf, function(pdf) {
73+
pdf.html(document.getElementById('html'), {callback: function(pdf) {
7974
var iframe = document.createElement('iframe');
8075
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
8176
document.body.appendChild(iframe);
8277
iframe.src = pdf.output('datauristring');
83-
84-
//var div = document.createElement('pre');
85-
//div.innerText=pdf.output();
86-
//document.body.appendChild(div);
8778
}
79+
}
8880
);
8981

9082
</script>

examples/html2pdf/showcase_supported_html.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</style>
2424
</head>
2525
<body>
26-
<div style='position: absolute; left: 0; top: 0; bottom: 0; overflow: auto; width: 400px'>
26+
<div id="html" style='position: absolute; left: 0; top: 0; bottom: 0; overflow: auto; width: 400px'>
2727
<h1>HTML Test File</h1>
2828
This page showcases all HTML supported features.
2929
<hr>
@@ -204,14 +204,12 @@ <h2>External</h2>
204204

205205
<script>
206206
var pdf = new jsPDF('p', 'pt', 'letter');
207-
pdf.canvas.height = 72 * 11;
208-
pdf.canvas.width = 72 * 8.5;
209-
html2pdf(document.body, pdf, function(pdf){
207+
pdf.html(document.getElementById('html'), {callback: function(pdf) {
210208
var iframe = document.createElement('iframe');
211209
iframe.setAttribute('style','position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
212210
document.body.appendChild(iframe);
213211
iframe.src = pdf.output('datauristring');
214-
});
212+
}});
215213
</script>
216214
</body>
217215
</html>

0 commit comments

Comments
 (0)