Recent

Author Topic: Multibyte special characters in fpPDF  (Read 1542 times)

sierdolg

  • New Member
  • *
  • Posts: 21
Multibyte special characters in fpPDF
« on: March 15, 2018, 04:57:30 pm »
Hello,
is it possible to generate a PDF containing multibyte characters (UTF-8) e.g. like a "ballot box" (UTF-8: 0xE2 0x98 0x90), and if so, how?

I tried

Code: Pascal  [Select][+][-]
  1. var
  2.   myPDF: TPDFDocument;
  3.   S: TPDFSection;
  4.   P: TPDFPage;
  5.   F: TFileStream;
  6.   FtTextRegular : Integer;
  7. begin
  8.   myPDF := TPDFDocument.Create(Nil);
  9.   myPDF.Options := [poPageOriginAtTop];
  10.   myPDF.StartDocument;
  11.   S := myPDF.Sections.AddSection;
  12.   P := myPDF.Pages.AddPage;
  13.   P.PaperType := ptA4;
  14.   P.UnitOfMeasure := uomMillimeters;
  15.   S.AddPage(P);
  16.   FtTextRegular := myPDF.AddFont('cabin.ttf', 'Cabin');
  17.   P.SetFont(FtTextRegular, 12);
  18.   P.SetColor(clBlack, false);
  19.   P.WriteText(50, 50, 'ANSI-Text works');
  20.   P.WriteText(50, 70, UTF8Decode('this way also ä,ö,ü etc.'));
  21.   P.WriteText(50, 90, UTF8Decode('but multibyte characters like ballot boxes ⮽ or ☐ will not work'));
  22.   F := TFileStream.Create('test.pdf',fmCreate);
  23.   try
  24.     myPDF.SaveToStream(F);
  25.   finally
  26.     F.Free;
  27.   end;
  28.  
  29. end;            

Analyzing the PDF you find "EF BF BF EF DF BD" instead of "BALLOT BOX WITH CHECK, UTF-8: 0xE2 0x98 0x91" for example (which show up nonprinting or garbage).
« Last Edit: March 15, 2018, 05:01:26 pm by sierdolg »

 

TinyPortal © 2005-2018