Page 1 of 1

Problem with unicode character representation with the pbPDFModule by Thorsten1867

Posted: Fri Aug 27, 2021 1:30 pm
by matlab2
Hello, a bit desperate I try to use the great pdPDF module from Thorsten1867 to embed Unicode fonts in a PDF to be able to use e.g. the Cyrillic character set (U+0400 to U+04FF).

The sample program from Thorsten (pbPDF-EmbedFont.pb) with the font Lucida Sanc Unicode (l_10646.ttf ) works, but does not support the styles bold, italic or bolditalic. With every other font tested so far there are the following problems:

1. a black square with a white cross or a small black square is placed in front of each string and

2. with some fonts the following message appears additionally (at least in Adobe Acrobat): "In the font [here the font name] the value for /Flags is incorrect".

Image

Image

3. as a side effect I noticed that "PDF::Bookmark" does not support Unicode (or I don't know how). Here the Cyrillic characters are output as question marks.

Has anyone ever gotten a font with multiple styles with Unicode characters to work.

To understand the problem I have attached the pictures and a small example program. For testing please copy this together with the "ArialMT" fonts (arial.ttf/ariali.ttf …) from c:\windows\fonts\ into the examples folder of the pdfModule.

Code: Select all

XIncludeFile "..\pbPDFModule.pbi"

Define.s Path2Font=""
Define.s Font="ArialMT-"
Define.s File=Font+"pbPDF-EmbedFont.pdf"
Define.s String=" <- "
Define.i i

For i=$0400 To $0410 ;testweise ein paar kyrillische Zeichen
  String=String+Chr(i)
Next i

#PDF = 1

If PDF::Create(#PDF)
  
  PDF::AddPage(#PDF)
   
  Debug PDF::EmbedFont(#PDF, Path2Font+"arial.ttf", "ArialMT", "", PDF::#Unicode)
  Debug PDF::EmbedFont(#PDF, Path2Font+"ariali.ttf", "ArialMT", "I", PDF::#Unicode)
  Debug PDF::EmbedFont(#PDF, Path2Font+"arialbd.ttf", "ArialMT", "B", PDF::#Unicode)
  Debug PDF::EmbedFont(#PDF, Path2Font+"arialbi.ttf", "ArialMT", "BI", PDF::#Unicode) 
  
  PDF::SetFont(#PDF,"ArialMT", "", 14)
  PDF::PlaceText(#PDF,Font+"Regular"+String, 10, 20) 
  PDF::SetFont(#PDF, "ArialMT", "I", 14)
  PDF::PlaceText(#PDF, Font+"Italic"+String, 10, 30)
  PDF::SetFont(#PDF, "ArialMT", "B", 14)
  PDF::PlaceText(#PDF, Font+"Bold"+string, 10, 40)
  PDF::SetFont(#PDF, "ArialMT", "BI", 14)
  PDF::PlaceText(#PDF, Font+"BoldItalic"+String, 10, 50)
  
  PDF::BookMark(#PDF, "Bookmark"+string, 0, #PB_Default, #PB_Default)
   
  PDF::Close(#PDF, File)
  
EndIf

RunProgram(File)
I hope someone has an idea or even a solution for the problem.

Re: Problem with unicode character representation with the pbPDFModule by Thorsten1867

Posted: Thu Sep 23, 2021 2:46 am
by 4otomax
I think that Arial, Helvetica and some other fonts are already contained in this library (but only ASCII range), so they are not loaded from external files. Extraneous characters at the beginning of a line do not always appear, depending on the font used. I did not bother and use drawing in a vector and output to a printer, since win 10 has a built-in pdf printer.