Requirement of Project :- Generating pdf file dynamically using iTextSharp. Give user option to print that file, and save record when user tried to print it without showing/saving file to user.
After lot of trial and error and research using below code for performing print operation. Please help!
I am trying to print pdf rendered in iframe which id hidden, as dont want user to see the file. Below is my jquery code :-
$('.btnPrintForm').click(function () {
if (confirm('Quetion to ask whether to go ahead with 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 all the browsers its behaving differently.
1) CHRMOE:- This code is working fine in chrome, but when print pop-up window comes, it doesn't wait, it redirects to the link in second or two. So I want it to wait for user to give print command or cancel it, only after that it should redirect to 'PrintAcceptanceURL'.
2) Mozilla This code is working, but it automatically starts downloading pdf file, which I dont want to happen? How do I stop it?
3) IE 10 :- In IE code is not working as expected. First its giving option to view/save pdf file option, I dont want user to get that option. And second its giving below error at PDF.contentWindow.print(); command as Invalid calling object.
Please check if you can help me in any way.