Can not render € symbol
I use angular 6. this.doc = new jsPDF('p', 'mm', 'a4'); this.doc.text(20, 4, 'Test ' + this.currencyPipe.transform(row.unitPrice, 'EUR')); console.log('Test ' + this.currencyPipe.transform(row.unitPrice, 'EUR'));
In the console all show ok. Test 9,00 € Here you can see how show it in the pdf file. https://drive.google.com/file/d/1XQGqPnZy1HGU6IJrsNUbNBjWb0EwHFKy/view
What can I do?
Regards Ingo
PDF is pure ASCII file. In ASCII is no Euro sign. You need to add and use an custom UTF 8 Font.
Hi arasabbasi ,
thanks for your help. But how I make it??? Sorry I am very new with javascript.
regards Ingo
Open examples/basic.html Look the fourth tab "Using Fonts"
Hi arasabbasi , First of all, thank you for your help. I look into the basic.html and the basic.js files. I try to implement this in Angular. I import in my index.html the font:
and add it in the styles.scc body { font-family: "Roboto","Helvetica Neue Light","Helvetica Neue",Helvetica,Arial,"Lucida Grande", 'PT Sans',sans-serif; margin: 0; } then I use jspdf: this.doc = new jsPDF('p', 'mm', 'a4'); this.doc.setFont('PT Sans'); this.doc.setFontType('normal'); this.doc.text(20, 50, ' €!'); this.doc.save('test.pdf');what I make wrong??
regards Ingo
Hello Ingo,
please dont write me emails for private (and free) support. I wont answer to those type of emails.
You are simply ignoring the example. Why? I wrote that example with the purpose to not be forced to provide support... Just because you are new to Javascript doesnt mean that you should not dig deep into the code.
We did not implement a css lookup nor a download mechanism to download webfonts. As the example clearly shows you have to provide the dataUrl of the ttf font. Please google wha a dataurl is.
Hi,
sorry I had not ignored the sample just did not understand. Now I think that I understood it.
In install the jspdf-customfonts. I create a default_vjs.js with:
(function (jsPDFAPI) {
"use strict";
jsPDFAPI.addFileToVFS('PTSans-Regular.ttf', 'Base64-encoded string of my font');
jsPDFAPI.addFileToVFS('PTSans-Bold.ttf', 'Base64-encoded string of my font'); })(jsPDF.API);
But I use angular 6. The example:
<script src="https://unpkg.com/jspdf@latest/dist/jspdf.min.js"></script>
<script src="dist/jspdf.customfonts.min.js"></script>
<script src="dist/default_vfs.js"></script>
Do not work. How I include the default_vjs.js file in the project? Can you help me?
regards Ingo
jspdf-customfonts got merged into jsPDF with version 1.4.0. You dont need to include it to your project. Actually your code will break when you use jspdf-customfonts.
I can't render € when use jsPDF-AutoTable I try add jspdf-customfonts it work only on jsPDF But not working on jsPDF-AutoTable. @arasabbasi Do you have solution for this ?
i have the same problem, i am using Angular 6, and i really dont know how to import the custom font to jspdf to make it works... do you know guys any example?
i have been checking the example examples/js/basic.js about how to add a ttf font... there is any other way to declare the PTSans variable? i mean is a huuuuuge text.
i solved it... i created a new class, there contains all font in base64 text. then in my component i import that class and create a new instance of this class. Everything is working fine!
Hi calledludo, can you make a example from " i created a new class, there contains all font in base64 text".
yeah, we waiting for the example?? Arasabbasi or calldeludo, make example please.
@spacewalkingninja
Example exists.
You can check the file examples/js/basic.js , there you can find a function called demoUsingTTFFont where they show you how to import a font, what i did to clean the code... is just created a class in other file and then import that class in my component... hope it helps you
@spacewalkingninja
@calldeludo import { Injectable } from '@angular/core';
import * as jsPDF from 'jspdf';
@Injectable() export class JsPDFFontService { regularNormal = 'base64font'; regularBold = 'base64font'; AddFontArimo(doc: jsPDF) { (doc as any).addFileToVFS('arimo.regular-normal.ttf', this.regularNormal); (doc as any).addFileToVFS('arimo.regular-bold.ttf', this.regularBold); doc.addFont('arimo.regular-normal.ttf', 'arimo', 'normal'); doc.addFont('arimo.regular-bold.ttf', 'arimo', 'bold'); doc.setFont('arimo'); } }
this.doc = new jsPDF('p', 'mm', 'a4'); this.jsPDFFontService.AddFontArimo(this.doc);