0

I have a controller that is returning a pdf file, this is temporary save in a local folder. It is possible to open a print dialog directly with out open the pdf file using javascript??

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

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.

Community
  • 1
  • 1
Howl Jenkins
  • 323
  • 1
  • 2
  • 18

1 Answers1

0

After a lot of researching finally get it using iframe. This code was very helpful http://www.sitepoint.com/load-pdf-iframe-call-print/ I have an empty hidden iframe in my view. This is working in Chrome, FF, but not in 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();
}
Howl Jenkins
  • 323
  • 1
  • 2
  • 18