0

I am creating a web app in angularJS with asp.net, here i want to export data into pdf file but i am unable to get

i saw a working example on stackoverflow

Click Here

and i created a jsfiddle for the same which is not working

Click here for jsfiddle

and here is my code

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js" rel="Stylesheet" />
    <link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="Stylesheet" />
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<a href="javascript:demoFromHTML()" class="button">Run Code</a>
    <div id="content">
    <h1>  
        We support special element handlers. Register them with jQuery-style.
    </h1>
</div>
<script type="text/javascript">
    function demoFromHTML() {
        var pdf = new jsPDF('p', 'pt', 'letter');
        // source can be HTML-formatted string, or a reference
        // to an actual DOM element from which the text will be scraped.
        source = $('#content')[0];

        // we support special element handlers. Register them with jQuery-style 
        // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
        // There is no support for any other type of selectors 
        // (class, of compound) at this time.
        specialElementHandlers = {
            // element with id of "bypass" - jQuery style selector
            '#bypassme': function (element, renderer) {
                // true = "handled elsewhere, bypass text extraction"
                return true
            }
        };
        margins = {
            top: 80,
            bottom: 60,
            left: 40,
            width: 522
        };
        // all coords and widths are in jsPDF instance's declared units
        // 'inches' in this case
        pdf.fromHTML(
            source, // HTML string or DOM elem ref.
            margins.left, // x coord
            margins.top, { // y coord
                'width': margins.width, // max width of content on PDF
                'elementHandlers': specialElementHandlers
            },

            function (dispose) {
                // dispose: object with X, Y of the last line add to the PDF 
                //          this allow the insertion of new lines after html
                pdf.save('Test.pdf');
            }, margins
        );
    }
</script>
</asp:Content>

this is my complete page for better understanding

issues

1) why i am getting the error

2)what i need to do to resolve the error

Community
  • 1
  • 1

1 Answers1

0

You are missing jquery link , since you have source called with jquery.

https://code.jquery.com/jquery-latest.min.js

https://jsfiddle.net/noitse/xa9jrwr4/5/ I have called function directly

Edit: Here is version without jquery https://jsfiddle.net/noitse/xa9jrwr4/6/

 source = document.getElementById('content')

Calling source with javascript

noitse
  • 1,045
  • 9
  • 27