html - Print embedded PDF from browser with Javascript, HTML5, AngularJS -
i'm loading base64 encoded pdf string javascript server. client application using angularjs, html5.
my html looks this:
<div id="printablepdfcontainer"> <iframe id="printablepdf" width="100%" height="100%"></iframe> </div>
my javascript looks this:
var pdfname = 'data:application/pdf;base64,' + data[0].printimage; var embeddedpdf = document.getelementbyid('printablepdf'); embeddedpdf.setattribute('src', pdfname); $scope.printdocument(embeddedpdf);
my printdocument funtion looks this:
$scope.printdocument = function() { var test = document.getelementbyid('printablepdf'); if (typeof document.getelementbyid('printablepdf').print === 'undefined') { settimeout(function(){$scope.printdocument();}, 1000); } else { var x = document.getelementbyid('printablepdf'); x.print(); } };
the printdocument function has been taken pre-existing question in stack overflow (silent print embedded pdf) gives answer print embedded pdf. however, doesn't seem work anymore. i'm getting 'undefined'
typeof document.getelementbyid('printablepdf').print === 'undefined'
check. seems .print doesn't exist or something.
so, questions this: how can print embedded pdf in html5, using javascript, , without opening popup window?
regards, phil
also answered here: print pdf javascript embed tag
i'm going post learned here after lot of research in future might find this.
pdf's displayed differently based on browser, browser version, browser configuration, , operating system. there lot of variables i'll talk common situations here.
on browsers unable call sort of print() method through javascript, able use pdfactions. openaction call print. embedded these pdf using itext.
chrome uses adobe's viewer, doesn't give access sort of print() method execute pdfactions embedded in pdf. can embed 'openaction' in pdf , have pdf call print whenever it's opened application looks @ actions.
firefox (above version, recent versions though) uses adobe viewer in windows, recognizes pdfactions. however, in osx loses support adobe viewer , switches baked in firefox viewer (pdf.js). not support pdfactions.
ie: didn't test on ie. because gave on printing pdf's javascript after firefox didn't work on osx (a req. me).
my pdf's being generated server control ended making service changes in server , adding png service generated png based on same markup pdf generation uses. browsers handle images better pdfs, knew going in, hoped able re-use pdf generation service since it's used elsewhere in code.
it doesn't answer question, it's information have. suggestion might find in future: ditch pdf if possible in case , go simpler. otherwise, please update question if know how call print() through javascript in ff preview pdf viewer in osx.
-phil
Comments
Post a Comment