c# 4.0 - Print pdf in hidden iframe javascript/jquery C# MVC -


requirement of project :- generating pdf file dynamically using itextsharp. give user option print file, , save record when user tried print without showing/saving file user.

after lot of trial , error , research using below code performing print operation. please help!

i trying print pdf rendered in iframe id hidden, dont want user see file. below jquery code :-

$('.btnprintform').click(function () {             if (confirm('quetion ask whether go ahead printing or     not?')) {                 $("#waitprintdiv").show();                 var pdf = document.getelementbyid('iprintform');                 console.log(pdf);                 pdf.focus();                 pdf.contentwindow.print();                  pdf.contentwindow.onafterprint = function () {                     console.log("printing completed...");                     alert("printing completed...");                 }                 window.location = 'printacceptanceurl';             }             else {                  window.location = 'printrejecetionurl';             }         }); 

in browsers behaving differently.

1) chrmoe:- code working fine in chrome, when print pop-up window comes, doesn't wait, redirects link in second or two. want wait user give print command or cancel it, after should redirect 'printacceptanceurl'.

2) mozilla code working, automatically starts downloading pdf file, dont want happen? how stop it?

3) ie 10 :- in ie code not working expected. first giving option view/save pdf file option, dont want user option. , second giving below error @ pdf.contentwindow.print(); command invalid calling object.

please check if can me in way.

$("#btnprint").live("click", function () {             var divcontents = $("#dvcontainer").html();             var printwindow = window.open('', '', 'height=400,width=800');             printwindow.document.write('<html><head><title>div contents</title>');           printwindow.document.write('</head><body >');           printwindow.document.write(divcontents);           printwindow.document.write('</body></html>');           printwindow.document.close();           printwindow.print();           }); 

Comments