Closed limelect closed 5 years ago
It is quite sophisticated but doable with the help of FriBiDi library, which is builtin in my version of libharu. There are required few additional steps in loading font and setting up a THaruDocument. Here is a working example with a UTF-8 encoder and the font you have linked to:
pdf := THaruDocument.Create;
try
// enable UTF encodings
pdf.Encoder.UseUTFEncodings;
// load ttf font, select encoding name and enable FriBiDi converter
fontName := pdf.Fonts.LoadTTFontFromFile('absolute_path_to_font\VarelaRound-Regular.ttf', [foEmbedding]);
font := pdf.Fonts.GetFont(fontName, 'Modern-UTF8-H');
font.PushBuiltInConverter('BiDi', nil);
font.SetCharacterEncoding(HPDF_CHARENC_UTF8);
// add a new page
page := pdf.Pages.Add;
page.SetSize(HPDF_PAGE_SIZE_B5, HPDF_PAGE_PORTRAIT);
// print some text
page.BeginText;
page.SetFontAndSize(font, 16);
page.TextOut(10, page.Height - 30, 'השם שלי THaruPDF');
page.EndText;
// save the document to a file
pdf.SaveToFile('utf_text.pdf');
finally
pdf.Free;
end;
Produces a PDF file:
Thanks so much I changed a bit and it is OK
pdf.Fonts.LoadTTFontFromFile('TaameyDavidCLM-Bold.ttf',[foEmbedding]); font := pdf.Fonts.GetFont('TaameyDavidCLM-Bold', 'Modern-UTF8-H');
P.S it will be nice to add loadfromresource so to have ttf in resource
I loaded Hebrew font pdf.Fonts.LoadTTFontFromFile('VarelaRound-Regular.ttf',[foEmbedding]); font := pdf.Fonts.GetFont('VarelaRound-Regular');
page.TextOut(page.Width - 100, page.Height - 30, 'השם שלי THaruPDF'); I get empty space for Hebrew what do i have to do to write Hebrew ?
P.S Hebrew font https://alefalefalef.co.il/resources/%D7%A4%D7%95%D7%A0%D7%98%D7%99%D7%9D-%D7%91%D7%97%D7%99%D7%A0%D7%9D/?lang=en