-2

I want to convert my html data with inline css into pdf using jquery . can anyone please guide me

Arpit Shah
  • 37
  • 1
  • 9
  • Possible duplicate of [Convert HTML to PDF in .NET](https://stackoverflow.com/questions/564650/convert-html-to-pdf-in-net) – Arpit Shah May 25 '17 at 10:58

2 Answers2

1

Use this library: https://cdnjs.com/libraries/jspdf

And here is a pen demonstrating how to implement it.

HTML

<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>
<!--Add External Libraries - JQuery and jspdf-->
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/0.9.0rc1/jspdf.min.js"></script>

JS

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');
});

http://codepen.io/nagasai/pen/JKKNMK

Korgrue
  • 3,430
  • 1
  • 13
  • 20
1
HtmlToPdf HtmlToPdf = new IronPdf.HtmlToPdf();
PdfResource PDF = HtmlToPdf.RenderHtmlAsPdf(htmlstring);
string str = Server.MapPath("~/File1.Pdf");
PDF.SaveAs(str);
Julian
  • 33,915
  • 22
  • 119
  • 174
Arpit Shah
  • 37
  • 1
  • 9