簡體   English   中英

html 頁面 javascript/jQuery 的 Pdf 預覽

[英]Pdf preview of html page javascript/jQuery

我正在嘗試通過單擊按鈕在 HTML 頁面的 javascript 的新頁面上創建 pdf 預覽。

我想要的是,通過單擊頁面上的此按鈕,它將在瀏覽器上打開一個新選項卡,其中包含源頁面的 pdf 預覽,然后我將從那里下載 pdf。

此刻我已經使用了這段代碼

function printopen() {
    var w = window.open();
    var html = $("#divtoprint").html();
    $(w.document.body).html(html);
    w.print();
}

這將打開一個新的空白頁面和彈出窗口。 我不想顯示彈出窗口,但相應的下載按鈕和頁面應該包含 pdf 預覽。

實現這一目標的正確方法是什么?

這將在新選項卡中打開 pdf 預覽,您也可以下載它。

在您的 window.open 中,將您的資源路徑作為參數https://developer.mozilla.org/en-US/docs/Web/API/Window/open

 function printopen(){

                var w = window.open("path_to_your_file");
                var html = $("#divtoprint").html();
                  $(w.document.body).html(html);
                  w.print();
              }

但請記住,不能保證用戶可以決定選項卡是否會出現在新選項卡中。

暫無
暫無

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

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