Skip to content

Commit e7be9ae

Browse files
committed
require support for from_html plugin
1 parent 3cc5884 commit e7be9ae

3 files changed

Lines changed: 56 additions & 43 deletions

File tree

libs/require/config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ require.config({
5959
]
6060
},
6161

62+
'jspdf.plugin.from_html':{
63+
deps:[
64+
'jspdf'
65+
]
66+
},
67+
6268
'jspdf.plugin.context2d':{
6369
deps:[
6470
'jspdf',

test/test_from_html.html

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,57 +15,54 @@
1515

1616
<title>Test HTML</title>
1717

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 -->
18+
<script src='../libs/require/require.js'></script>
2719

2820
<script>
29-
pdf_test_harness.onload = function(harness) {
30-
var pdf = new jsPDF('p', 'pt', 'letter');
21+
require_baseUrl_override = '../';
22+
23+
require(['../libs/require/config'], function(){
24+
require(['test/test_harness', 'jspdf.plugin.from_html'], function(){
25+
26+
var pdf = new jsPDF('p', 'pt', 'letter');
3127
var ta = document.getElementById('textarea');
32-
33-
pdf.fromHTML(ta.value, 0, 0);
34-
35-
ta.onkeyup = function(){
28+
29+
pdf.fromHTML(ta.value, 0, 0);
30+
31+
ta.onkeyup = function(){
3632
var pdf = new jsPDF('p', 'pt', 'letter');
37-
pdf.fromHTML(ta.value, 0, 0);
38-
harness.setPdf(pdf);
39-
}
40-
33+
pdf.fromHTML(ta.value, 0, 0);
34+
harness.setPdf(pdf);
35+
}
36+
37+
var harness = pdf_test_harness_init(pdf);
4138
harness.header.style.left='50%';
4239
harness.body.style.left='50%';
43-
44-
return pdf;
45-
}
40+
41+
}); //require
42+
}); //require
4643
</script>
4744

4845
</head>
4946

5047
<body style='background-color: silver; margin: 0;'>
51-
<textarea id='textarea' style='position:fixed;width: 50%;height:100%'>
48+
<textarea id='textarea' style='position: fixed; width: 50%; height: 100%'>
5249

5350
<html>
5451
<head>
5552
<style>
56-
.important
57-
{
58-
color:darkred ; font-size:10em;
59-
}
53+
.important {
54+
color: darkred;
55+
font-size: 10em;
56+
}
6057
</style>
6158
</head>
6259
<body>
6360
<div>black</div>
6461
<div>black (should not have color parameter in PDF source)</div>
6562

66-
<div style='color: red;font-size:30px'>hello</div>
67-
<div style='color: rgb(0,255,0);font-size:30px'>hello</div>
68-
<div style='color: #0000FF;font-size:30px'>hello</div>
63+
<div style='color: red; font-size: 30px'>hello</div>
64+
<div style='color: rgb(0, 255, 0); font-size: 30px'>hello</div>
65+
<div style='color: #0000FF; font-size: 30px'>hello</div>
6966

7067
<div class='important'>hello</div>
7168

test/test_from_html_css_page_breaks.html

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,43 @@
1515

1616
<title>Test HTML</title>
1717

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 -->
18+
<script src='../libs/require/require.js'></script>
2719

2820
<script>
29-
pdf_test_harness.onload = function(harness) {
30-
var pdf = new jsPDF('p', 'pt', 'letter');
31-
var ta = document.getElementById('textarea');
21+
require_baseUrl_override = '../';
22+
23+
require(['../libs/require/config'], function(){
24+
require(['test/test_harness', 'jspdf.plugin.from_html'], function(){
25+
26+
var pdf = new jsPDF('p', 'pt', 'letter');
27+
var ta = document.getElementById('textarea');
3228

3329
pdf.fromHTML(ta.value, 0, 0);
3430

31+
ta.onkeyup = function(){
32+
var pdf = new jsPDF('p', 'pt', 'letter');
33+
pdf.fromHTML(ta.value, 0, 0);
34+
harness.setPdf(pdf);
35+
}
36+
3537
ta.onkeyup = function(){
3638
var pdf = new jsPDF('p', 'pt', 'letter');
3739
pdf.fromHTML(ta.value, 0, 0);
3840
harness.setPdf(pdf);
3941
}
4042

43+
var harness = pdf_test_harness_init(pdf);
4144
harness.header.style.left='300px';
4245
harness.body.style.left='300px';
46+
4347

44-
return pdf;
48+
}); //require
49+
}); //require
50+
</script>
51+
52+
<script>
53+
pdf_test_harness.onload = function(harness) {
54+
4555
}
4656

4757

0 commit comments

Comments
 (0)