<html>
<body>
<h1>Reporting</h1>
<!-- <iframe id="reportView" name="reportView" style="display:none;" ></iframe> -->
<hr/>
<button onclick="javascript:printIframe();">Print</button>
<script type="text/javascript">
function createIframeReportViewer()
{
var ifm = document.createElement("IFRAME");
ifm.id = 'reportView';
ifm.style = "display:none;";
document.body.appendChild(ifm);
}
function printIframe(){
createIframeReportViewer();
document.getElementById("reportView").onload = function(){
alert("PDF was loaded.");
var frm = document.getElementById("reportView").contentWindow;
frm.focus();
frm.print();
}
document.getElementById('reportView').src = "data.pdf";
return false;
}
</script>
</body>
</html>
Do iFrame se načte PDF a jakmile se dokončí jeho stahování tak se vyvolá dialog tisku.Poznámka:
Je potřeba zkoušet pře server protože při spouštění lokálního HTML souboru se nenastaví origin a je problém s vyvoláním akce tisku nad iFramem.
Zdroje:
http://stackoverflow.com/questions/9616426/javascript-print-iframe-contents-only
http://stackoverflow.com/questions/6000987/dynamically-set-iframe-src
https://en.wikipedia.org/wiki/Same-origin_policy
https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy
http://www.w3schools.com/jsref/met_document_createelement.asp
Žádné komentáře:
Okomentovat