Search code examples
javascriptjspdfjspdf-autotable

add div content before autotable


Iam using theese plugins ** 1) jspdf.plugin.autotable.js 2) jspdf.debug.js **

Iam using the following code

var pdf = new jsPDF("p", "pt");
pdf.fromHTML($("#otherdivcontent").get(0), 70, 300, {
width: 500
});
var res = pdf.autoTableHtmlToJson(document.getElementById("table2"));

pdf.autoTable(res.columns, res.data);

pdf.autoPrint();

pdf.save("Report.pdf");

script

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script type="text/javascript" src="jspdf.debug.js"></script>
<script type="text/javascript" src="jspdf.plugin.autotable.js"></script>

this is the generated pdf generated pdf

I want to combine the two contents into a single pdf...and i want the div content before the table....please help me to adjust the alignments. I want the table in a second page... How can i solve this..


Solution

  • here is the solution,

    pdf.fromHTML($("#test1").get(0), 30,100, {
                'width': margins.width
                },
                margins);
     pdf.autoTable(data.columns, data.rows, 
            {margin: {top: 80,bottom:50},
            startY:h+20,
            tableWidth: 500,
            styles: {
            overflow: 'linebreak',
            columnWidth: 'wrap',
            // rowHeight:'wra',
            lineWidth: 1
            }});
    

    "h" is the height of the div #test1.