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
var
myPDF: TPDFDocument;
S: TPDFSection;
P: TPDFPage;
F: TFileStream;
FtTextRegular : Integer;
begin
myPDF := TPDFDocument.Create(Nil);
myPDF.Options := [poPageOriginAtTop];
myPDF.StartDocument;
S := myPDF.Sections.AddSection;
P := myPDF.Pages.AddPage;
P.PaperType := ptA4;
P.UnitOfMeasure := uomMillimeters;
S.AddPage(P);
FtTextRegular := myPDF.AddFont('cabin.ttf', 'Cabin');
P.SetFont(FtTextRegular, 12);
P.SetColor(clBlack, false);
P.WriteText(50, 50, 'ANSI-Text works');
P.WriteText(50, 70, UTF8Decode('this way also ä,ö,ü etc.'));
P.WriteText(50, 90, UTF8Decode('but multibyte characters like ballot boxes ⮽ or ☐ will not work'));
F := TFileStream.Create('test.pdf',fmCreate);
try
myPDF.SaveToStream(F);
finally
F.Free;
end;
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).