neoPDF , help with js fonts - Forum

Forum Navigation
You need to log in to create posts and topics.

neoPDF , help with js fonts

Hi

I want to use neoPDF for some tests and use.
For using utf-8 Languages like Persian, you need to make js fonts and load it to neoPDF...

Look at this guide from their website:

Use of Unicode Characters / UTF-8:

The 14 standard fonts in PDF are limited to the ASCII-codepage. If you want to use UTF-8 you have to integrate a custom font, which provides the needed glyphs. jsPDF supports .ttf-files. So if you want to have for example Chinese text in your pdf, your font has to have the necessary Chinese glyphs. So, check if your font supports the wanted glyphs or else it will show garbled characters instead of the right text.

To add the font to jsPDF use our fontconverter in /fontconverter/fontconverter.html. The fontconverter will create a js-file with the content of the provided ttf-file as base64 encoded string and additional code for jsPDF. You just have to add this generated js-File to your project. You are then ready to go to use setFont-method in your code and write your UTF-8 encoded text.

Alternatively you can just load the content of the *.ttf file as a binary string using fetch or XMLHttpRequest and add the font to the PDF file:

const doc = new jsPDF(); const myFont = ... // load the *.ttf font file as binary string // add the font to jsPDF doc.addFileToVFS("MyFont.ttf", myFont); doc.addFont("MyFont.ttf", "MyFont", "normal"); doc.setFont("MyFont");

I have converted my font to JS version, and I added my js to VisualNEO project body like this:

<script src="/js/Vazirmatn.js" type="text/javascript"></script>

(Vazirmatn.js is on my output 'js' folder of app, is this right way to add js to project?)

but when i set 'Vazirmatn' which is name of my font, I cant get a Persian text on generated pdf. (just random symbols)

@noyzen, please check this:

https://visualneo.com/forum/topic/does-neo-pdf-support-persian-language

noyzen has reacted to this post.
noyzen

Thanks Luis!

Font is working now, but RTL text don't.
For example text goes out of screen, maybe it's because i made whole app right-to-left.

Another problem is my Persian text will not show RTL.
Align right is different from Right-to-Left direction text.

Aligned Right But not RTL:
متن فارسی؟English.

Correct RTL text:
متن فارسی؟English.

FabricJS also have same problems with Persian texts.

@noyzen, neoPDF depends on jsPDF JavaScript library. This is what I have found:

jsPDF is a js library which is used for creating pdf on the client as well as server-side. It has implemented the BiDi algorithm which is essential to support RTL. In nutshell, jsPDF is supporting RTL, partially. Why partially, because it works great for a sentence containing only Arabic script. But if there is a sentence containing Arabic and English ex. “عربى hello اشخاص” will render words in the reverse direction.

noyzen has reacted to this post.
noyzen

yea thats what I'm talking about, thanks for research and info Luis.

I'm making a super powerful advanced novel writing app and I need to be able to compile or export story somwhow...

I can do plain text files but if there are many text it's not possible I think.

maybe I look for other pdf libraries or epub or other methods and make a plugin myself later, if you have any idea or solution please let me know.

regards.

@noyzen have you considered using neoWord?
It's the solution I use to generate complete Amazon KDP AI Books as shown here.

noyzen has reacted to this post.
noyzen

yes I checked every ways and neoWord also.

I have to test it more to see if thats a good option for my case (mobile - desktop) and if it supprts all languages well.

I will let you know for sure if I managed to create anything worth mentionaning. thanks

luishp has reacted to this post.
luishp