簡體   English   中英

從服務器下載后打印pdf文件

[英]Print pdf file after downloaded from the server

我需要自動打印生成的pdf文件。 首先,我在生成pdf文件后將其保存到服務器,然后將其下載到客戶端計算機。 我需要打印從客戶端計算機下載的pdf文件。 下載后,有什么方法可以獲取pdf文件保存的確切位置文件嗎? 有什么方法可以使用客戶端/本地打印機直接打印pdf文件? 現在,我已經使用了spire pdf,問題是它使用了服務器的打印機,我需要對其進行修復以使用客戶端/本地打印機。

代碼:

window.location.href = "/Orders/Download?file=" + encodeURIComponent(data.fileName);

控制器:

[HttpGet]
[DeleteFileAttribute] //Action Filter, it will auto delete the file after download
public ActionResult Download(string file)
{
   //get the temp folder and file path in server
   string fullPath = Path.Combine(Server.MapPath("~/Content/PDF"), file);

   try
   {
       PdfDocument doc = new PdfDocument();
       doc.LoadFromFile(fullPath);
       doc.PrinterName = "HP Deskjet Ink Adv 2010 K010";
       //Use the default printer to print all the pages
       doc.PrintDocument.Print();
   }
   catch (Exception e)
   {
       var message = e.Message;
   }

   return File(fullPath, "application/pdf", file);
}

如果是此代碼,它將把pdf文件下載到“客戶端/用戶下載”,或者用戶將下載位置設置在該位置,並且也會打印,但是它使用了服務器的打印機,這就是問題所在。

我認為這在現代瀏覽器中是不可能的。

我看到的大多數解決方案( 在這里那里 )都依賴於已加載和打印的嵌入式PDF。 但是,如今,iframe已被沙盒化,並且由於PDF通常依賴於本機插件,因此您很不走運: 插件不會加載 -您無法更改它。

這是產生錯誤的示例代碼:

無法將“ ..sample.pdf”作為插件加載,因為插件要加載到的框架已沙箱化。

 $('#pdfDocument').attr("src", "https://upload.wikimedia.org/wikipedia/commons/8/85/I-20-sample.pdf").load(function(){ document.getElementById('pdfDocument').contentWindow.print(); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <embed sandbox="allow-top-navigation allow-scripts allow-popups allow-forms" type="application/pdf" src="https://upload.wikimedia.org/wikipedia/commons/8/85/I-20-sample.pdf" id="pdfDocument" width="100%" height="100%" /> 

暫無
暫無

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

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