Skip to content

Commit 8555c60

Browse files
committed
v2.5.21
1 parent 82e83e9 commit 8555c60

File tree

7 files changed

+44
-7
lines changed

7 files changed

+44
-7
lines changed

browser.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/browser-2.5.19.js renamed to docs/browser-2.5.21.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ <h1>HTML to PDFMake convertor</h1>
116116
<div id="pdf_ie" style="display:none;padding:3em">The PDF file is sent to you for download. Use a modern browser (like Chrome or Firefox) to display the PDF in this page.</div>
117117
</div>
118118
</div>
119-
<script src="browser-2.5.19.js"></script>
119+
<script src="browser-2.5.21.js"></script>
120120
<script src="https://cdn.jsdelivr.net/npm/pdfmake@latest/build/pdfmake.min.js"></script>
121121
<script src="https://cdn.jsdelivr.net/npm/pdfmake@latest/build/vfs_fonts.js"></script>
122122
<script>

example.pdf

0 Bytes
Binary file not shown.

index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,25 @@ function htmlToPdfMake(htmlText, options) {
867867
if (value) {
868868
// convert value to a 'pt' when possible
869869
var parsedValue = _this.convertToUnit(value);
870-
// if we have 'font-size' with a parsedValue at false, then ignore it
871-
if (key === 'font-size' && parsedValue === false) break;
870+
// if we have 'font-size' with a parsedValue at false, then:
871+
// check if it's one of know keywords (like medium, small, x-small, etc), otherwise ignore it
872+
if (key === 'fontSize' && parsedValue === false) {
873+
if (["xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large", "xxx-large"].includes(value)) {
874+
// we use 12pt as the medium value
875+
switch(value) {
876+
case "xx-small": value=7.2; break; // 60%
877+
case "x-small": value=9; break; // 75%
878+
case "small": value=10.7; break; // 89%
879+
case "medium": value=12; break;
880+
case "large": value=14.4; break; // 120%
881+
case "x-large": value=18; break; // 150%
882+
case "xx-large": value=24; break; // 200%
883+
case "xxx-large": value=36; break; // 300%
884+
}
885+
} else {
886+
break;
887+
}
888+
}
872889
ret.push({key:key, value:(parsedValue === false ? value : parsedValue)});
873890
}
874891
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-to-pdfmake",
3-
"version": "2.5.19",
3+
"version": "2.5.21",
44
"description": "Convert HTML code to PDFMake",
55
"main": "index.js",
66
"scripts": {
@@ -23,7 +23,7 @@
2323
"eslint": "^5.16.0",
2424
"jsdom": "^16.6.0",
2525
"pdfmake": "^0.2.7",
26-
"simple-test-framework": "^0.1.7",
26+
"simple-test-framework": "^0.2.1",
2727
"svg-to-pdfkit": "^0.1.8"
2828
}
2929
}

test/unit.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,5 +1229,25 @@ test("unit tests", function(t) {
12291229
t.finish();
12301230
});
12311231

1232+
t.test("CSS units",function(t) {
1233+
var html = `<div style="line-height:107%;font-size:large;width:110px;height:50pt;margin-left:1in;margin-top:2em;margin-right:1rem;margin-bottom:0.5cm">hello world</div>`;
1234+
var ret = htmlToPdfMake(html, {
1235+
window:window
1236+
});
1237+
if (debug) console.log(JSON.stringify(ret));
1238+
t.check(Array.isArray(ret) && ret.length===1, "return is OK");
1239+
ret = ret[0];
1240+
t.check(ret.lineHeight == 1.07, "% OK");
1241+
t.check(ret.fontSize == 14.4, "constant OK");
1242+
t.check(ret.width == 83, "px OK");
1243+
t.check(ret.height == 50, "pt OK");
1244+
t.check(ret.marginLeft == 72, "in OK");
1245+
t.check(ret.marginRight == 12, "rem OK");
1246+
t.check(ret.marginTop == 24, "em OK");
1247+
t.check(ret.marginBottom == 14, "cm OK");
1248+
1249+
t.finish();
1250+
});
1251+
12321252
t.finish();
12331253
})

0 commit comments

Comments
 (0)