Recent

Author Topic: Japanese font with Bold font in fpPDF  (Read 675 times)

meeeeeeeeee

  • New Member
  • *
  • Posts: 17
Japanese font with Bold font in fpPDF
« on: April 04, 2025, 08:36:39 am »
Hello. I can make a PDF file with Japanese font, but I'm struggline with BOLD font.
In using "Yu Mincho Demibold" I can make Japanese font to kind of BOLD font, but
I can't make gothic font to BOLD font in Japanese.
I'd like use "Noto" series font possibly for BOLD font.
Can anyone help me how to use BOLD fond in fppdf?
I'm using Lazarus v3.8.

Code: Pascal  [Select][+][-]
  1. uses ...fppdf, fpttf, LCLIntf,custapp
  2.  
  3. procedure TForm1.Button1Click(Sender: TObject);
  4. var
  5.   xFpFcl   : TFPFontCacheList;
  6.  
  7.   xPdfDoc: TPDFDocument;
  8.   xPdfSec: TPDFSection;
  9.   xPdfPg : TPDFPage;    
  10.   xString:String;
  11.   xFt_NotoSerifJP :integer;
  12.  
  13.   procedure AddPage;
  14.   begin
  15.     xPdfPg                 := xPdfDoc.Pages.AddPage;
  16.     xPdfPg.PaperType       := ptA4;
  17.     xPdfPg.Orientation   := ppoLandScape;
  18.  
  19.     xPdfPg.UnitOfMeasure := uomPixels;  
  20.     xPdfSec.AddPage(xPdfPg);
  21.   end;
  22.   procedure AddFontsToPDFDoc(var d: TPDFDocument);
  23.   const
  24.     xFontAry: array [0..2] of String = ('Noto Sans JP', 'Noto Serif JP', 'Yu Mincho Demibold');
  25.   var
  26.     i, xCnt: Integer;
  27.     xFpFci: TFPFontCacheItem;
  28.   begin
  29.     xCnt :=0;
  30.     for i := 0 to High(xFontAry) do  begin
  31.       xFpFci := xFpFcl.Find(xFontAry[i], False, False);
  32.       if xFpFci <> nil then begin
  33.         xPdfDoc.AddFont(xFpFci.FileName, xFpFci.FamilyName);
  34.         xCnt :=xCnt+1;
  35.       end;
  36.     end;
  37.     if (xCnt = 0) and (xFpFcl.Count > 0) then begin
  38.       xFpFci := xFpFcl.Items[0];
  39.       xPdfDoc.AddFont(xFpFci.FileName, xFpFci.FamilyName);
  40.     end;
  41.   end;
  42. begin
  43.   //load fonts
  44.   xFpFcl := TFPFontCacheList.Create;
  45.   xFpFcl.SearchPath.Add('C:\Windows\Fonts');
  46.   xFpFcl.BuildFontCache;
  47.   xFpFcl.ReadStandardFonts;
  48.  
  49.   //doc
  50.   xPdfDoc                       := TPDFDocument.Create(nil);
  51.   xPdfDoc.Options               := [poPageOriginAtTop];
  52.   xPdfDoc.StartDocument;
  53.   xPdfSec                       := xPdfDoc.Sections.AddSection;
  54.   AddFontsToPDFDoc(xPdfDoc);
  55.  
  56.   AddPage;
  57.  
  58.   //xFt_NotoSerifJP := xPdfDoc.AddFont('NotoSerifJP-VF.ttf', 'Noto Serif JP');
  59.   xFt_NotoSerifJP := xPdfDoc.AddFont('yumindb.ttf', 'Yu Mincho Demibold');
  60.  
  61.   xPdfPg.SetFont(xFt_NotoSerifJP, 13);
  62.   xPdfPg.SetColor(clBlack, false);
  63.  
  64.   xString :='1行目。あいうえおガギグゲゴパピプペポ';
  65.   xPdfPg.WriteText(50, 50, xString);
  66.  
  67.   xString :='2行目';
  68.   xPdfPg.WriteText(50, 60, xString);
  69.  
  70.   xPdfDoc.SaveToFile('aaa.pdf');
  71.   xPdfDoc.free;
  72.   OpenDocument('aaa.pdf');
  73.   close;
  74. end;
  75.        
  76.  

paweld

  • Hero Member
  • *****
  • Posts: 1419
Re: Japanese font with Bold font in fpPDF
« Reply #1 on: April 04, 2025, 12:22:07 pm »
Hi,
read this thread: https://forum.lazarus.freepascal.org/index.php/topic,68657.0.html
you will find some examples there
Best regards / Pozdrawiam
paweld

meeeeeeeeee

  • New Member
  • *
  • Posts: 17
Re: Japanese font with Bold font in fpPDF
« Reply #2 on: April 08, 2025, 07:38:05 am »
Hi, paweld.
By installing NotoSansJP-Bold.ttf and using HumanFriendlyName, I can use "Noto Sans JP Bold". Thank you.

 

TinyPortal © 2005-2018