jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

Can not render € symbol

Open IngoManthey opened this issue 8 years ago • 16 comments

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

IngoManthey avatar Aug 24 '18 10:08 IngoManthey

PDF is pure ASCII file. In ASCII is no Euro sign. You need to add and use an custom UTF 8 Font.

Uzlopak avatar Aug 31 '18 05:08 Uzlopak

Hi arasabbasi ,

thanks for your help. But how I make it??? Sorry I am very new with javascript.

regards Ingo

IngoManthey avatar Sep 01 '18 14:09 IngoManthey

Open examples/basic.html Look the fourth tab "Using Fonts"

Uzlopak avatar Sep 01 '18 16:09 Uzlopak

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

IngoManthey avatar Sep 02 '18 11:09 IngoManthey

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.

Uzlopak avatar Sep 05 '18 08:09 Uzlopak

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

IngoManthey avatar Sep 12 '18 13:09 IngoManthey

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.

Uzlopak avatar Sep 12 '18 13:09 Uzlopak

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 ?

duykhanh1411 avatar Sep 22 '18 08:09 duykhanh1411

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?

calldeludo avatar Sep 22 '18 14:09 calldeludo

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.

calldeludo avatar Sep 23 '18 09:09 calldeludo

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!

calldeludo avatar Sep 27 '18 22:09 calldeludo

Hi calledludo, can you make a example from " i created a new class, there contains all font in base64 text".

IngoManthey avatar Oct 02 '18 14:10 IngoManthey

yeah, we waiting for the example?? Arasabbasi or calldeludo, make example please.

spacewalkingninja avatar Apr 08 '19 13:04 spacewalkingninja

@spacewalkingninja

Example exists.

Uzlopak avatar Apr 08 '19 14:04 Uzlopak

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 avatar Apr 08 '19 20:04 calldeludo

@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);

IngoManthey avatar Apr 09 '19 14:04 IngoManthey