Skip to content

Commit

Permalink
v2.2.1
Browse files Browse the repository at this point in the history
added 'em' support (#103)
  • Loading branch information
Aymkdn committed May 30, 2021
1 parent 8e59152 commit 2d22055
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,11 @@ var docDefinition = {

PDFMake uses `pt` units for the numbers. `html-to-pdfmake` will check the inline style to see if a number with unit is provided, then it will convert it to `pt`.

It only works for `px`, `pt` and `rem` (for `rem` it's based on `1rem = 16px`);
It only works for `px`, `pt`, `em` and `rem` (for `em`/`rem` it's based on `1rem = 16px`);

Examples:
- `font-size:16px` will be converted to `fontSize:12`
- `margin:1em` will be ignored because it's not a valid unit
- `margin:1em` will be converted to `margin:12`

### `<img>`

Expand Down
2 changes: 1 addition & 1 deletion browser.js

Large diffs are not rendered by default.

Binary file modified example.pdf
Binary file not shown.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ module.exports = function(htmlText, options) {
}

/**
* Convert 'px'/'rem'/'cm' to 'pt', and return false for the other ones. If it's only a number, it will just return it
* Convert 'px'/'rem'/'cm'/'em' to 'pt', and return false for the other ones. If it's only a number, it will just return it
*
* @param {String} val The value with units (e.g. 12px)
* @return {Number|Boolean} Return the pt value, or false
Expand All @@ -747,6 +747,7 @@ module.exports = function(htmlText, options) {
val = Math.round(val * 0.75292857248934); // 1px => 0.75292857248934pt
break;
}
case 'em':
case 'rem':{
val *= 12; // default font-size is 12pt
break;
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.2.0",
"version": "2.2.1",
"description": "Convert HTML code to PDFMake",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 2d22055

Please sign in to comment.