Skip to content

Commit

Permalink
Added option showHidden (v2.4.10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aymkdn committed Dec 20, 2022
1 parent b6411f2 commit 5f5eb0f
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ You can overwrite the default styles using `defaultStyles` ([see below](https://

In [some cases](https://github.com/Aymkdn/html-to-pdfmake/issues/145), you may see some extra blank spaces in the PDF. Because removing them could be quite resource consuming, the option is `false` by default.

#### `ignoreHidden`
#### `showHidden`

You can choose to not parse elements where they are not displayed through css display:none
By default the `display:none` elements won't be parsed. Set this option to `true` to display the hidden elements in the PDF.

#### `imagesByReference`

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

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/browser-2.4.10.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/browser-2.4.9.js

This file was deleted.

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.9.js"></script>
<script src="browser-2.4.10.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
3 changes: 3 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ var html = htmlToPdfMake(`
</tr>
</table>
<div style="display:none">display:none</div>
<div style="visibility:hidden">visibility:hidden</div>
<svg version="1.1" baseProfile="full" width="300" height="200" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="red" />
<circle cx="150" cy="100" r="80" fill="green" />
Expand Down
Binary file modified example.pdf
Binary file not shown.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @param {Boolean} [tableAutoSize=false] It permits to use the width/height defined in styles for a table's cells and rows
* @param {Boolean} [imagesByReference=false] It permits to return two objets ({content, images}) to handle the `<img>` tags by reference
* @param {Boolean} [removeExtraBlanks=false] Some blank spaces in your code may cause extra blank lines in the PDF – use this option to remove them
* @param {Boolean} [showHidden=false] TRUE if the 'display:none' elements should be displayed
* @param {Function} [customTag] It permits to handle non-regular HTML tag
* @param {Object} [window] The `window` object (required for NodeJS server side use)
* @return {Object} it returns a PdfMake object
Expand Down Expand Up @@ -42,7 +43,7 @@ function htmlToPdfMake(htmlText, options) {
this.tableAutoSize = (options && typeof options.tableAutoSize === "boolean" ? options.tableAutoSize : false);
this.imagesByReference = (options && typeof options.imagesByReference === "boolean" ? options.imagesByReference : false);
this.removeExtraBlanks = (options && typeof options.removeExtraBlanks === "boolean" ? options.removeExtraBlanks : false);
this.ignoreHidden = (options && typeof options.ignoreHidden === "boolean" ? options.ignoreHidden : false);
this.showHidden = (options && typeof options.showHidden === "boolean" ? options.showHidden : false);

// Used with the size attribute on the font elements to calculate relative font size
this.fontSizes = (options && Array.isArray(options.fontSizes) ? options.fontSizes : [10, 14, 16, 18, 20, 24, 28]);
Expand Down Expand Up @@ -173,7 +174,7 @@ function htmlToPdfMake(htmlText, options) {
if (element.id) ret.id = element.id;
parents.push(element);

if (this.ignoreHidden && element.style.display && element.style.display === 'none') {
if (!this.showHidden && (element.style.display && element.style.display === 'none') || (element.style.visibility && element.style.visibility === 'hidden')) {
return;
}

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.9",
"version": "2.4.10",
"description": "Convert HTML code to PDFMake",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,12 +888,12 @@ test("parse HSL color", function (t) {
t.finish();
});

test("ignoreHidden", function (t) {
test("showHidden", function (t) {
var html = `<div><div style="display:none">hidden</div><div>visible</div></div>`;
var ret = htmlToPdfMake(html, {window: window, ignoreHidden:true});
var ret = htmlToPdfMake(html, {window: window, showHidden:true});
if (debug) console.log(JSON.stringify(ret));
t.check(Array.isArray(ret) && ret.length === 1, "return is OK");
ret = ret[0];
t.check(ret.stack.length === 1 && ret.stack[0].text === "visible", "display:none");
t.check(ret.stack.length === 2 && ret.stack[0].text === "hidden", "showHidden");
t.finish();
});
});

0 comments on commit 5f5eb0f

Please sign in to comment.