【发布时间】:2018-10-11 03:28:13
【问题描述】:
我需要自动打印生成的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 的用户的下载位置?
-
没有。您无权访问客户端文件系统
-
有没有其他方法可以自动打印 pdf 文件?
-
否(这是幸运的,因为如果可以,网络就不会存在)。但我不明白你为什么要这样做。如果您导航到某个站点并且您的打印机刚刚开始打印文档,您会怎么想。
标签: c# jquery asp.net-mvc-4 pdf printing