Recent

Author Topic: [resolved]How to use Chinese correctly in FPPDF?  (Read 179 times)

jianwt

  • Full Member
  • ***
  • Posts: 125
[resolved]How to use Chinese correctly in FPPDF?
« on: October 10, 2024, 04:26:00 am »
How to use Chinese correctly in FPPDF?

The Chinese font 'simfang.ttf' is also in this directory('C:\Windows\Fonts\').
Why is the PDF still garbled when I load the name 'Fangsong' of the Chinese font 'simfang.ttf'? How to load Chinese fonts correctly here?

See attachment for detailed routines. Thank you very much.

Code: Pascal  [Select][+][-]
  1.  g := TFPFontCacheList.Create;
  2.   g.SearchPath.Add('C:\Windows\Fonts\');  { 'simfang.ttf','Fangsong' The Chinese font 'simfang.ttf' is also in this directory,   }
  3.   g.BuildFontCache;
  4.   //doc properties
  5.   d := TPDFDocument.Create(nil);
  6.   d.Options := [poCompressText, poCompressImages, poUseRawJPEG, poNoEmbeddedFonts, poPageOriginAtTop];
  7.   d.Infos.Title := 'sample pdf';
  8.   d.Infos.Author := 'me';
  9.   d.Infos.Producer := 'lazarus';
  10.   d.Infos.ApplicationName := 'test';
  11.   d.Infos.CreationDate := Now;
  12.   d.StartDocument;
  13.   s := d.Sections.AddSection;
  14.  
  15.   f := g.Find('fangsong', False, False); {Why is the PDF still garbled when I load the name 'Fangsong' of the Chinese font 'simfang.ttf'?
  16.                                            How to load Chinese fonts correctly here?}
  17.  
  18.   if f <> nil then
  19.   d.AddFont(f.FileName, f.FamilyName);                                                    
  20.  
« Last Edit: October 10, 2024, 05:18:06 am by jianwt »

jianwt

  • Full Member
  • ***
  • Posts: 125
Re: How to use Chinese correctly in FPPDF?
« Reply #1 on: October 10, 2024, 04:58:21 am »
All right, when displaying Chinese characters, use the embedded font --
Code: Pascal  [Select][+][-]
  1. d.Options := [poCompressText, poCompressImages, poUseRawJPEG, poPageOriginAtTop]. //poNoEmbeddedFonts,
  2.  

 

TinyPortal © 2005-2018