Jspdf: .html options

Created on 16 Jan 2019  路  11Comments  路  Source: MrRio/jsPDF

I'm having trouble learning anything from the documentation, how am I supposed to know which options exists in for example the .html method? It only says I can add an options object, but doesn't say what those options can be.

Also, I'm rendering an image from html with html2canvas, and want to use that as a front page before adding html from a different div with the .html method to a new page. How can I do that?

Also, is there a pure support channel somewhere that I can use, instead of opening new issues?

Extend Documentation html.js

Most helpful comment

I classify this issue as an "Extend Documentation" issue.

All 11 comments

I classify this issue as an "Extend Documentation" issue.

I figured it out looking at the source code, but it would certainly be helpful if it was more fleshed out in the documentation :). Thanks for the great work.

Trying to figure out myself .html options as well.
Cannot make it work when trying to convert a table element with three images into a pdf. Guess it is related to this SO question but I'd like to find a solution with this new method.
Can anybody point me to the right direction (I can open a new issue if this is the case)?

var legend = document.getElementsById("my-table");
var pdf = new jsPDF(orientation, undefined, format);
pdf.html(legend);
window.open(pdf.output('bloburl'))

`

my-table` is:

<table>
    <tr>
        <td><img src="image1.jpeg"></td>
    </tr>
    <tr>
        <td><img src="image2.jpeg"></td>
    </tr>
    ...
</table>

The output is a blank PDF. I get lot of messages in the console like html2canvas: Added image and 2732ms html2canvas: Render completed but I guess it's all happening AFTER the PDF is created and so I need a callback or something.
How could I do that with .html() method?

Sorry, just figured it out.
For the curious, the working code:

var legend = document.getElementsById("my-table");
var pdf = new jsPDF(orientation, undefined, format);
pdf.html(legend, {
    callback: function () {
        window.open(pdf.output('bloburl'));
     }
});

Is it possible to set font-size, line-height etc. for the html method inside the options object?

pdf.html function is not available. i am using version "jspdf": "^1.5.3", Can you please tell me how did ti worked for you

@s1100h

Is possible to set font-size, line-height etc. for the html method inside the options object?

You would change it by modifiying the css code in your stylesheet for the html2pdf__container.

like this:

.html2pdf__container{
line-height: 20px;
font-size: 20px
}

And yes it is not in the documentation and probably doesnt work, because I didnt tested it.

pdf.html function is not available. i am using version "jspdf": "^1.5.3", Can you please tell me how did ti worked for you

Probably, because you initialized another name for your jsPDF-instance.

Me too. some of the examples mentioned in stackoverflow, and github don't even work.

i did check source and could not find any .html() function.

https://github.com/MrRio/jsPDF/blob/master/src/modules/html.js#L914 ;)

Was this page helpful?
0 / 5 - 0 ratings