Skip to content

Commit

Permalink
v2.4.9
Browse files Browse the repository at this point in the history
See #155
  • Loading branch information
Aymkdn committed Nov 2, 2022
1 parent 03bcc0e commit d42656d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 28 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.8.js → docs/browser-2.4.9.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.8.js"></script>
<script src="browser-2.4.9.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.
38 changes: 14 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,29 +465,6 @@ function htmlToPdfMake(htmlText, options) {
}
break;
}
case "FONT": {
if (element.getAttribute("color")) {
ret.color = this.parseColor(element.getAttribute("color"));
}
// Checking if the element has a size attribute
if (element.getAttribute("size")) {
// Getting and sanitizing the size value: it should be included between 1 and 7
var size = Math.min(Math.max(1, parseInt(element.getAttribute("size"))), 7);

// Getting the relative fontsize
var fontSize = Math.max(this.fontSizes[0], this.fontSizes[size - 1]);

// Assigning the font size
ret.fontSize = fontSize;
}

// Applying inherited styles
ret = this.applyStyle({
ret: ret,
parents: parents.concat([element]),
});
break;
}
default: {
// handle other cases
if (options && typeof options.customTag === "function") {
Expand Down Expand Up @@ -632,6 +609,7 @@ function htmlToPdfMake(htmlText, options) {
*/
this.parseStyle = function(element, ignoreProperties) {
var style = element.getAttribute("style") || "";
var ret = [];
style = style.split(';');
// check if we have "width" or "height"
var width = element.getAttribute("width");
Expand All @@ -642,8 +620,20 @@ function htmlToPdfMake(htmlText, options) {
if (height) {
style.unshift("height:" + this.convertToUnit(height + (isNaN(height) ? "" : "px")));
}
// check if we have 'color' or 'size' -- mainly for '<font>'
var color = element.getAttribute("color");
if (color) {
ret.push({key:"color", value:this.parseColor(color)});
}
var size = element.getAttribute("size");
if (size !== null) {
// Getting and sanitizing the size value: it should be included between 1 and 7
size = Math.min(Math.max(1, parseInt(size)), 7);
// Assigning the font size
ret.push({key:'fontSize', value:Math.max(this.fontSizes[0], this.fontSizes[size - 1])});
}

var styleDefs = style.map(function(style) { return style.toLowerCase().split(':') });
var ret = [];
var borders = []; // special treatment for borders
var nodeName = element.nodeName.toUpperCase();
var _this=this;
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.8",
"version": "2.4.9",
"description": "Convert HTML code to PDFMake",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit d42656d

Please sign in to comment.