Reputation: 1000
I'm trying to create a PDF and push to user in a standalone node-webkit app. Generating PDF is ok but i'm not able to send it to user. I'have followed indication find here : http://pdfkit.org/demo/browser.html .
Here my controller :
paiApp.controller('pdfCtrl', function($scope) {
var PDFDocument = require('pdfkit');
var blobStream = require('blob-stream');
var doc = new PDFDocument;
stream = doc.pipe(blobStream());
doc.fontSize(15).text('Hello World');
doc.end();
stream.on('finish', function() {
iframe = document.getElementById('myIframe');
iframe.src = this.toBlobUrl(); //Error here
// blob = stream.toBlob('application/pdf') //Error ...
});
// Writting PDF is working
// ###################################
// var PDFDocument = require('pdfkit');
// var fs = require('fs');
// doc = new PDFDocument;
// doc.pipe(fs.createWriteStream('output.pdf'));
// doc.fontSize(15);
// doc.text('Generate PDF coool!');
// doc.end();
// #####################################
});
Here my error :
Object [object Object] has no method 'toBlobUrl'
Any idea ?
Upvotes: 0
Views: 1389
Reputation: 153
I struggled with this as well but recently got it to work for my app. I'm just intending to display a dynamically generated PDF in the browser in a window - so I used an <object>
-- my client controller code is such:
$http({method: 'GET', url: 'SERVERCONTROLLER', responseType: 'arraybuffer'})
.success(function(response){
var file = new Blob([response], {type: 'application/pdf'}));
var fileURL = URL.createObjectURL(file);
$scope.mycontent = $sce.trustAsResourceUrl(fileURL);
});
Make sure you remember to inject $sce
to your controller and you should be good to go.
Upvotes: 1