Skip to content

Commit

Permalink
v2.4.20
Browse files Browse the repository at this point in the history
Fixed a bug introduced in v2.4.19 (see issue #181)
  • Loading branch information
Aymkdn committed Apr 25, 2023
1 parent 2bfd39d commit 950b6c8
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/browser-2.4.19.js → docs/browser-2.4.20.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ <h1>HTML to PDFMake convertor</h1>
<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>
</div>
</div>
<script src="browser-2.4.19.js"></script>
<script src="browser-2.4.20.js"></script>
<script src="https://cdn.jsdelivr.net/npm/pdfmake@latest/build/pdfmake.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/pdfmake@latest/build/vfs_fonts.js"></script>
<script>
Expand Down
Binary file modified example.pdf
Binary file not shown.
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,15 +733,7 @@ function htmlToPdfMake(htmlText, options) {
case "font-style": {
if (value==="italic") ret.push({key:"italics", value:true});
break;
}
case "height": {
ret.push({key:"height", value: _this.convertToUnit(value)});
break;
}
case "width": {
ret.push({key:"width", value: _this.convertToUnit(value)});
break;
}
}
case "font-family": {
ret.push({
key: "font", value: value.split(',')[0].replace(/"|^'|^\s*|\s*$|'$/g, "").replace(/^([a-z])/g, function (g) {
Expand Down Expand Up @@ -776,6 +768,12 @@ function htmlToPdfMake(htmlText, options) {
} else {
// ignore some properties
if (ignoreProperties && (key.indexOf("margin-") === 0 || key === 'width' || key === 'height')) break;
// for IMG only (see issue #181)
if (nodeName === "IMG" && (key === 'width' || key === 'height')) {
ret.push({key:key, value: _this.convertToUnit(value)});
break;
}

// padding is not supported by PDFMake
if (key.indexOf("padding") === 0) break;
if (key.indexOf("-") > -1) key=_this.toCamelCase(key);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html-to-pdfmake",
"version": "2.4.19",
"version": "2.4.20",
"description": "Convert HTML code to PDFMake",
"main": "index.js",
"scripts": {
Expand Down
11 changes: 11 additions & 0 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -941,5 +941,16 @@ test("unit tests", function(t) {
t.finish();
});

t.test("img with invalid width/height in style", function (t) {
var html = `<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEBLAEsAAD/7QPQUGhvdG9zaG9wIDMuMAA4QklNA+kKUHJpbnQgSW5mbwAAAAB4AAMAAABIAEgAAAAAAtgCKP/h/+IC+QJGA0cFKAP8AAIAAABIAEgAAAAAAtgCKAABAAAAZAAAAAEAAwMDAAAAAScPAAEAAQA" style="width:100%;height:auto" />`;
var ret = htmlToPdfMake(html, {window: window});
// [{"nodeName":"IMG","image":"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEBLAEsAAD/7QPQUGhvdG9zaG9wIDMuMAA4QklNA+kKUHJpbnQgSW5mbwAAAAB4AAMAAABIAEgAAAAAAtgCKP/h/+IC+QJGA0cFKAP8AAIAAABIAEgAAAAAAtgCKAABAAAAZAAAAAEAAwMDAAAAAScPAAEAAQA","width":false,"height":false,"style":["html-img"]}]
if (debug) console.log(JSON.stringify(ret));
t.check(Array.isArray(ret) && ret.length === 1, "return is OK");
ret = ret[0];
t.check(ret.image.startsWith("data:image") && ret.width===false && ret.height===false, "width/height to false");
t.finish();
});

t.finish();
})

0 comments on commit 950b6c8

Please sign in to comment.