簡體   English   中英

單擊按鈕時打開空白窗口

[英]blank window is opened when clicked on button

我正在嘗試使用 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變量的字符串。

如果您不想打開新窗口,請使用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM