2016-11-23 75 views
1

在導入HTML頁面PDF我得到一個下載窗口彈出類似下面防止觀看

給出的一個,但我不希望用戶查看PDF已下載,但仍可以下載。

pop up image 我試着下面的代碼,但還是我在Firefox瀏覽器獲得一個窗口:

<!DOCTYPE html> 
<html> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script> 
<body> 


<script> 
window.stop(); 
var pdf = new jsPDF('p', 'pt', 'a4'); 
pdf.addHTML(document.body, function() { 
    pdf.save('web.pdf'); 
}); 
</script> 
    <p id="to-pdf">HTML content...</p> 
</body> 
</html> 

我試圖用window.stop,但沒有結果。更多關於此

回答

1

我理解正確你的問題,你要創建並顯示在另一個瀏覽器選項卡的PDF您的幫助:

<!DOCTYPE html> 
<html> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script> 
<body> 
    <p id="to-pdf">HTML content...</p> 
</body> 

<script> 
var pdf = new jsPDF('p', 'pt', 'a4'); 
var pdfFile; 
pdf.addHTML(document.body, function() { 
    console.log(pdf); 
    var pdfBlob = pdf.output('blob'); 
    var fileURL = URL.createObjectURL(pdfBlob); 
    window.open(fileURL); 
}); 
</script> 
</html> 

或者你也可以通過點擊打開onother標籤的PDF按鈕:

<!DOCTYPE html> 
<html> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script> 
<body> 
    <p id="to-pdf">HTML content...</p> 
    <p id="openPDFButton">Open PDF</p> 
</body> 

<script> 
var pdf = new jsPDF('p', 'pt', 'a4'); 
var pdfFile; 
pdf.addHTML(document.body,function(){}); 
document.getElementById('openPDFButton').onclick = function(){ 
    var pdfBlob = pdf.output('blob'); 
    var fileURL = URL.createObjectURL(pdfBlob); 
    window.open(fileURL); 
}; 
</script> 
</html> 

希望它能幫助!