Cannot generate a PDF file from localStorage


#1

Hello,

I have a problem when make an IOS ionic app with PDFmake plugin for generate a PDF file if we get any content from localstorage because got an undefined value on console log for $scope.model.selection on my browser. You should check my repo for this case to find a best solution.

Thanks before


#2

I can’t help you with pdfmake, but I’ve had a very good experience using a similar plugin, jsPDF. Maybe you can try to create a pdf file with that library.


#3

Do you have any example code for this?


#4

Nvm but How I can create a currency filter from any $scope such as US $ 4550?


#5
// needs jsPDF included in your index.html
// e.g. <script src="jspdf.js"></script>
var doc = new jsPDF('p', 'pt', 'a4');
doc.setProperties({
    'title': 'nice pdf',
    'subject': 'example pdf',
    'author': 'me',
    'keywords': 'pdf'
});
doc.setFontSize(40);
doc.text(35, 25, "jsPDF example");
dims.width = 500;
dims.height = 500;
doc.addPage(dims.width, dims.height);
var imgData = 'data:image/jpeg;base64,/9j/............'; // base 64 jpeg image data
doc.addImage(imgData, 'JPEG', 0, 0, dims.width, dims.height);
var pdfOutput = doc.output("blob");
var filePath = 'blabla.pdf';
$cordovaFile.writeFile(filePath, pdfOutput); //needs ngCordova and file plugin

#6

Thanks but How I can make a pdf file from jsPDF result to become an attachment in email?


#7

@claw

I have installed jspdf through “npm install jspdf”.

then I have included "script src=“https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.3/jspdf.debug.js” "/script"
in index.html

after that when I declaring "var doc = new jspdf() "

it is giving me error that cannot found jspdf.

I am working on Ionic 2 project
Do you know how to solve this problem ?