Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello
i have a situation,in which i have to convert element of a repeter into pdf. so i am using jsPDF plugin. first i am trying to convert the element of a div,but it is not working please help to overcome from this.

my script is
JavaScript
<script src="jquery-1.7.1.min.js"></script>
    <script src="jspdf.js"></script>
    <script src="jspdf.plugin.standard_fonts_metrics.js"></script>
    <script src="jspdf.plugin.split_text_to_size.js"></script>
    <script src="jspdf.plugin.from_html.js"></script>

    <title></title>
    <script>
        $(document).ready(function () {
            $(function () {
                var doc = new jsPDF();
                var specialElementHandlers = {
                    '#editor': function (element, renderer) {
                        return true;
                    }
                };

                $('#cmd').click(function () {
                    doc.fromHTML($('#content').html(), 15, 15, {
                        'width': 170,
                        'elementHandlers': specialElementHandlers
                    });
                    doc.save('sample-file.pdf');
                });
            });
        });
    </script>


and HTMl div is ;
ASP.NET
<body>
    <form id="form1" runat="server">
        <div id="content">
            <h3>Hello, this is a H3 tag</h3>
            <p>a pararaph</p>
        </div>
        <div id="editor"></div>
        <button id="cmd">generate PDF</button>
    </form>
</body>
Posted

1 solution

Hello Amit,
This problem an be solved by adding htm2canvas.js and addhtml.js along with jspdf.js.
You dont need any other js for that.
If you still have problems I'll come up with example code.
 
Share this answer
 
Comments
Member 10416382 3-Apr-17 5:55am    
Hi,

i have problem with Hindi fonts in my html div content. when i am using window.print() viwer i am getting hindi fonts.when i am using above code not able get hindi fonts can you please help me.

Thanks
Koni
Hitesh Rohilla 27-Jul-18 2:19am    
Dear @Seenivasagan.vrp Please share the addhtml.js link as I am unable to find this library.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900