javascript - Create downloable pdf file from JSON -
basically, issue i'm experiencing have queried server homecoming pdf file returned in json format.
i have tried create html element auto download pdf (this not issue), issue pdf downloaded can not opened because fails , reports error, illustration in adobe reader:
"adobe reader not open 'test.pdf' because either not supported file type or because file has been damaged (for example, sent email attachment , wasn't correctly decoded)"
i'm working angularjs create ajax phone call server json object , seek format , download it:
... var pdf = pdfservice.get({id:pdfid}); console.log(pdf); pdf.$promise.then(function(data){ var element = angular.element('<a/>'); element.attr({ href: 'data:attachment/pdf;charset=utf-8,' + encodeuri(data), target: '_self', download:'test.pdf' })[0].click(); }); ... update using $http service angular , same code, downloads pdf it's empty, maybe issue of encoding or formating json object...
... $http({ method: 'get', url: 'http://www.testweb.com/pdf/1') .success(function(data) { console.log(data); var element = angular.element('<a/>'); element.attr({ href: 'data:attachment/pdf;charset=utf-8,' + encodeuri(data), target: '_self', download:'test.pdf' })[0].click(); }); ...
pdf files aren't same text (or json) files, seek using library jspdf create client sided pdf files.
javascript html json angularjs
No comments:
Post a Comment