Skip to content Skip to sidebar Skip to footer

Print Iframe With Pdf Generated On The Fly Ie 11

I wanted to print a pdf which is generated on the fly in an Iframe, but can't get that print this pdf file. This is what i have now, am i doing something wrong?. Works fine on Goog

Solution 1:

My workaround was generate the pdf first (save into disk) and then use the url of the generated and place it into an <embed> object (with this you are able to use the print method from IE )

var ua = window.navigator.userAgent,
        msie = ua.indexOf("MSIE "),
        obj = null;

// Generate the embed object for IEif (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
        obj = document.createElement('embed');
        obj.setAttribute("type", "application/pdf");
        obj.setAttribute("id", "pdf1");
        obj.style.width = '100%';
        obj.height = heightBody + 'px';
        obj.setAttribute("src", url); // here set the url for generated pdf file
}

// Place this where you print the embed (button, link...)if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
  document.getElementById('pdf1').print();
}

For other browsers like Chrome you can use the same approach (save file into disk) and use iframe (this works)

obj = document.createElement('iframe');
obj.setAttribute("type", "application/pdf");
obj.setAttribute('id', 'pdf2');
obj.setAttribute('src', url);
obj.style.width = '100%';
obj.height = heightBody + 'px';

In the print button you can place this:

document.getElementById('pdf2').contentWindow.print();

Hope this helps someone else

Post a Comment for "Print Iframe With Pdf Generated On The Fly Ie 11"