2017-11-01 28 views
1

html2pdfを使用してデータをPDFにエクスポートしようとしています。まず、簡単な例を書いています。エクスポートボタンをクリックすると、新しい空白のウィンドウが開いて、内容がエクスポートされずに開きます。ボタンをクリックすると空白のウィンドウが開きます

デモ:https://plnkr.co/edit/ruWKJBQiZ9QgUjxaBzbo?p=preview

htmlコード:

<div ng-controller="listController"> 
     <button ng-click="export()">export</button> 
    <h3> Simple Test</h3> 

    </div> 

JSコード:エクスポートボタン上のユーザーをクリックすると

app.controller("listController", ["$scope", 
    function($scope) { 

$scope.export = function() { 

    var pdf = new jsPDF('p', 'pt', 'letter'); 
     var canvas = pdf.canvas; 
     canvas.height = 72 * 11; 
     canvas.width= 72 * 8.5;; 
     // can also be document.body 
     var html = '<html><body>Hello from JS file <strong> World</strong></body></html>'; 
     html2pdf(html, pdf, function(pdf) { 
       pdf.output('dataurlnewwindow'); 
     }); 
    } 
    } 
]); 

html変数に割り当てられた文字列をエクスポートして表示する必要があります。

答えて

1

新しいウィンドウを開くためにしたくない場合は、使用:

pdf.output('datauri'); 

dataurinewwindowは、具体的には、新しいウィンドウで開くようにPDFを要求します。

全例:

var app = angular.module("app", []); 

app.controller("listController", ["$scope", 
    function($scope) { 

    $scope.export = function() { 

     var pdf = new jsPDF('p', 'pt', 'letter'); 
     var canvas = pdf.canvas; 
     canvas.height = 72 * 11; 
     canvas.width = 72 * 8.5;; 
     // can also be document.body 
     var html = '<html><body>Hello from JS file <strong> World</strong></body></html>'; 
     html2pdf(html, pdf, function(pdf) { 
     pdf.output('dataurl'); 
     }); 
    } 
    } 
]); 
+0

データが1ページだけで収まるように大きい場合にはサポートされていません。デモhttps://plnkr.co/edit/E0xVpRhtMMyNqOd4d69P?p=previewをご覧ください。エクスポートボタンをクリックすると、PDFがダウンロードされますが、残りのデータは表示されません(複数のページではサポートされていません)。どんなインプットも役に立ちます。@ Fenton – UIS

関連する問題