jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

addfont not working

Open Ema7 opened this issue 11 years ago • 14 comments

Hej, I have searched on the web and also looked into your examples and code, but I was not able to add a custom font to the pdf. As I understand as such it should work?

What I tried: in the css-file added: @font-face { font-family: 'Verdana'; src: url('verdana.ttf') format('truetype'); } The font works on the webpage.

and in the js-file: doc.addFont('Verdana', 'Verdana', 'normal'); doc.setFont('Verdana'); doc.text(20, 80, 'Some Verdana Text.');

but in the pdf it keeps saying "The font 'Verdana' contains a bad /BBox." and does not show it right. Acrobat takes the font "Adobe Sans MM" instead. (Tried without the css part as well.)

However it works fine with 'Arial' font, by just adding: doc.addFont('Arial', 'Arial', 'normal'); doc.setFontType('normal'); doc.setFont('Arial'); doc.text(20, 70, 'Some Arial Text.');

Any ideas? Thanks in advance for the help and for the wonderful jsPDF package. /Ema

Ema7 avatar Apr 22 '15 08:04 Ema7

Removing lines 777-797 from jspdf.js helped for me. (After that invoke make to build it.) See also: https://github.com/MrRio/jsPDF/issues/509

Maybe related?

Eusebius1920 avatar Jun 03 '15 13:06 Eusebius1920

Hi Eusebius1920, thank you for your answer.

Actually https://github.com/MrRio/jsPDF/issues/509 is not related as the basic example works fine for me also locally.

The funny thing is, if I use my minimum example it displays the right font if I open the pdf in bluebeam Rev. However in acrobat reader it does take a default font.

Strange... Any one else having the same issue? Thanks, Ema

Ema7 avatar Jun 10 '15 10:06 Ema7

hi even i want to add Flama Basic to my pdf but not working with above steps help me if anyone knows or tried.

ashakoshti1988 avatar Jan 08 '16 12:01 ashakoshti1988

HI, I have the same issue with Verdana font -> bad bbox. Has anyone found a solution ? Thanks, Leo

LeoAbu-Saa avatar Mar 21 '16 10:03 LeoAbu-Saa

@LeoAbu-Saa you can see that PDF in browser it will not show any error,But with adobe it shows error.as the fonts are not embedded in it.

ashakoshti1988 avatar Mar 21 '16 10:03 ashakoshti1988

Thank you @ashakoshti1988 for your reply. Does this mean that in the browser the document is displayed correctly and with Adobe reader I can't open it without that warning ?

Thanks, Leo

LeoAbu-Saa avatar Mar 21 '16 10:03 LeoAbu-Saa

@LeoAbu-Saa yes,in browser it will display correctly but for adobe or other pdf viewer you need to embed that particular font in pdf,as with current version they have embed halvetica,times,arial,courier in it.you can see in js files.

ashakoshti1988 avatar Mar 21 '16 10:03 ashakoshti1988

@ashakoshti1988 In my case I have the text in finnish language.. For example something like this: "Med avtalet säkerställer man att skogsägaren får den överenskomna servicen avskogsvårdsföreningen."

In the browser the result is not the same: "Med avtalet s kerst ller man att skogs garen f r den verenskomna servicen av skogsv rdsf reningen".

The 'special chars' like this one "ä" are omitted. Should I use a different encoding ?

Thank you, Leo.

LeoAbu-Saa avatar Mar 21 '16 10:03 LeoAbu-Saa

@LeoAbu-Saa It will support whetever in ascii character range. http://stackoverflow.com/questions/22080799/jspdf-library-cannot-insert-utf8-letters-into-pdf

ashakoshti1988 avatar Mar 21 '16 11:03 ashakoshti1988

@LeoAbu-Saa Hi, maybe little late and you solved already, you have to write the letters as unicode, see here: https://en.wikipedia.org/wiki/List_of_Unicode_characters

like for if you want to write "år" (danish year) you have to write in java script '\u00E5r'

Cheers, Emanuel

Ema7 avatar Mar 29 '16 20:03 Ema7

@Ema7 Thank you, I will try shortly your solution. :)

LeoAbu-Saa avatar Mar 30 '16 10:03 LeoAbu-Saa

@Ema7 Hi Ema, this works fine with the default font. As soon as I set the font to 'Verdana' it doesn't encode it properly. This is the text: säkerställer -> s\u00E4kerst\u00E4ller Have you succeeded to use Verdana and special chars ?

Thanks for your support.

LeoAbu-Saa avatar Mar 30 '16 11:03 LeoAbu-Saa

@LeoAbu-Saa

I have tried as well.. but unfortunately can't figure out why it is not working. Seems that the font is not incorporated correctly in jsPDF. Sorry! In case you find a solution please post here so all know! :) Cheers, Ema

Ema7 avatar Mar 30 '16 20:03 Ema7

https://github.com/sphilee/jsPDF-CustomFonts-support

sphilee avatar Jan 27 '17 11:01 sphilee