简体   繁体   English

打开打印对话框,从控制器C#接收pdf文件

[英]Open print dialog receiving a pdf file from controller C#

I have a controller that is returning a pdf file, this is temporary save in a local folder. 我有一个返回pdf文件的控制器,这是临时保存在本地文件夹中。 It is possible to open a print dialog directly with out open the pdf file using javascript?? 可以直接打开打印对话框,而无需使用javascript打开pdf文件?

public ActionResult LoadDownloadAndPrint(string Download)
{ return File(System.IO.File.ReadAllBytes(target);)

The file is saved in C:\\Windows\\Temp\\3ac416b7-7120-4169-bc4d-61e105ec197c\\output.pdf 该文件保存在C:\\ Windows \\ Temp \\ 3ac416b7-7120-4169-bc4d-61e105ec197c \\ output.pdf

I've have tried to used embed tag like in this thread Print PDF directly from JavaScript but did not work I guess because is a local place where the file is stored. 我已经尝试在此线程中使用嵌入标记,例如直接从JavaScript打印PDF,但是我想它不起作用,因为它是文件存储的本地位置。

After a lot of researching finally get it using iframe. 经过大量研究,终于可以使用iframe获得它。 This code was very helpful http://www.sitepoint.com/load-pdf-iframe-call-print/ I have an empty hidden iframe in my view. 这段代码非常有帮助http://www.sitepoint.com/load-pdf-iframe-call-print/我的视图中有一个空的隐藏iframe。 This is working in Chrome, FF, but not in IE 这适用于Chrome,FF,但不适用于IE

Search.openPrintDialog = function () {
var printJobIds = $("input:checkbox[name='Print']:checked").map(function () { return this.value; }).get().join(',');
if (printJobIds.length > 0)
{ 
    JSUtil.BlockUI();
    print('/' + JSUtil.GetWebSiteName() + '/Search/LoadDownloadAndPrint?Print=' + printJobIds)
}
return false;
}
function print(url) {
    var _this = this,
    iframeId = 'iframeprint',
    $iframe = $('iframe#iframeprint');
    $iframe.attr('src', url);
    $iframe.load(function () {
       _this.callPrint(iframeId);
    });
}

//initiates print once content has been loaded into iframe
function callPrint(iframeId) {
  var PDF = document.getElementById(iframeId);
  PDF.focus();
  PDF.contentWindow.print();
  JSUtil.UnBlockUI();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM