2017-01-25 16 views
0

ich einen Web-App in AngularJS mit asp.net erschaffe, hier mag ich Daten in pdf-Datei exportieren, aber ich bin nicht in der LageFehler jspdf im Umgang mit Daten exportieren

i zu erhalten sahen ein funktionierendes Beispiel auf Stackoverflow

Click Here

und ich schaffte eine jsfiddle für das gleiche, die nicht

Click here for jsfiddle

arbeiten

und hier ist mein 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> 

dies zum besseren Verständnis

Fragen

1), warum ich erhalte den Fehler

2), was ich tun muss meine komplette Seite Um den Fehler zu beheben

Antwort

0

Sie fehlen Jquery Link, da Sie Quelle mit jquery aufgerufen haben.

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

https://jsfiddle.net/noitse/xa9jrwr4/5/ Ich habe Funktion aufgerufen direkt

Edit: Hier ist die Version ohne jquery https://jsfiddle.net/noitse/xa9jrwr4/6/

source = document.getElementById('content') 

aufrufen Quelle mit Javascript

+0

, aber ich möchte, dass Klick auf den Button Export –

+0

Sie können, wenn Sie es auf Ihrer Website machen, jsfiddle Handlungen komisch tho beim Aufruf von HTML-Funktionen – noitse