Arabic Prawn Gem - ruby-on-rails

Since the Arabic letters appeared as unknown characters while using prawn gem alone , I installed the Arabic-Prawn gem 0.0.1 to print data in arabic .
I used as a test the below code
Prawn::Document.generate('hello.pdf') do
font "#{Prawn::BASEDIR}/data/fonts/artro.ttf"
font_size 16
self.text_direction = :rtl
long_text = "مرحبا يا العالم"
text long_text.fix_arabic_glyphs
end
First it displays the below error:
undefined method `fix_arabic_glyphs'
so I included the prawn in the class , the error disappeared but the Arabic letters are still not shown (represnted as _).
Someone can help me?

I had the same problem, and this solved it for me:
https://github.com/prawnpdf/prawn/issues/921

I have solved the problem by using another font only.
Some characters are not defined for some fonts .
So using a font that defines all characters for arabic language is the best solution

Related

adding a jsPDF font?

I found some information on the Internet, but it works. I get errors when I add my own font. Here the error.
Function Error output#file:///C:/Users/jspdf.debug.js line 1449 > srcScript : 1985: 87: string contains invalid character
Could you maybe share the section of your code where you add the font, it's hard to give an answer from the error.
But normally you add a font by converting a tff file to a base64 string and adding it like this:
doc.addFileToVFS('font-name.ttf', base64StringOfTffFile);
doc.addFont('font-name.ttf', 'font-name', 'normal');
doc.setFont('font-name', 'normal');

Arabic word in rails prawn shows reverse order

When I try to create a pdf in Arabic Language, I'm getting the letters in reverse order.
I use the following code to generate a pdf file.
note_section = {content: "#{order_item.try(:notes).try(:connect_arabic_letters)}" ,
size: 8,
font: "app/assets/fonts/ufonts.com_arial-unicode-ms.ttf",
text_color: "313131"}
Expected text is:
In prawn it looks like:
Gem version => Prawn version:2.2.2 Rails version:5.1.6
Any help is highly appreciated, thanks!

got wrong characters encoding using pdfbox to extract text from pdf

Recently,I have to index pdf into ElasticSearch and using pdfbox to extract text from pdf, however I got wrong characters encoding like this
Ýëĭ2ĈjŬj§ė¥
1 ŋ?nij"2$ 2016£ 2Ú 5Õ,”Òªj§?ně#ij"2ě
^ë2ļŘœ A$j§?n 2016£ě#ëÖĭ2Ĉļê
2 èÅŋ?n$ 2016£ 2Ú 6ÕöĿS¿ ĿS¿ ĿS
Õ¿ ĿSÖ¿ eöĿS&غĨĘ
http://www.sse.com.cnLćĈ
A$j§Ýëĭ2ĈŘĐ
My code is exactly the same as this page says here. I try pdfbox lib version from 0.8.x to 2.0.x, but it still can not work.
Any help or advice will be grateful!
I got answer from #Tilman comment.
See pdfbox.apache.org/1.8/faq.html#notext and the answer below too.

Why numbers getting reversed when formatted in RTL Arabic - Rails application?

I'm using Prawn gem in my Rails app to generate PDF reports.
I read the documentation for putting the text in Arabic with text_direction RTL in arabic.
But, issue is that numbers are getting reversed here.
I wanted semester 1234 as الفصل الدراسي 1234,
but in my app the output is الفصل الدراسي 4321.
My two lines of code is here:
pdftable = Prawn::Document.new
pdftable.text(t('org.semester') + " " + #semester)
#semester = '1234' (The reason would be that it is being treated as a text/string, thus changes to RTL (reversed))
Anyway, Please help me to retain numbers in proper order without changing the RTL format.
Without hacking too much you could use
#semester.to_s.reverse
So you reverse the string twice

BlackBerry webworks native dialog unicode

I have been searching for an answer all around the web, but couldn't find anything.
I am developing Blackberry Webworks application and the problem is with dialog and unicode. For example:
when I use simple javascript alert(unicodeMsg); unicode works fine, I can use any character including Russian or Lithuanian. The problem is that the alert box has title "JavaScript Alert" and it annoys a bit.
when I use native alert either phonegap or webworks like:
blackberry.ui.dialog.standardAskAsync(unicodeMsg,
blackberry.ui.dialog.D_OK, {
title : unicodeTitle,
size: blackberry.ui.dialog.SIZE_MEDIUM,
position : blackberry.ui.dialog.CENTER
});
it doesn't show any unicode characters. I tried pretty much everything (setting my document in utf-8, using \uxxxx characters, changing meta tags from utf-8 to windows-1257 but nothing works)
I suppose the problem is not with html or js documents neither with the script. Can someone help me?
You need to encode the unicode characters like so text: unescape(encodeURIComponent(unicodeStr)) .
There is an example here - http://blackberry-webworks.github.com/WebWorks-API-Docs/WebWorks-API-Docs-next-BB10/view/blackberry.invoke.html

Resources