uses ...fppdf, fpttf, LCLIntf,custapp
procedure TForm1.Button1Click(Sender: TObject);
var
xFpFcl : TFPFontCacheList;
xPdfDoc: TPDFDocument;
xPdfSec: TPDFSection;
xPdfPg : TPDFPage;
xString:String;
xFt_NotoSerifJP :integer;
procedure AddPage;
begin
xPdfPg := xPdfDoc.Pages.AddPage;
xPdfPg.PaperType := ptA4;
xPdfPg.Orientation := ppoLandScape;
xPdfPg.UnitOfMeasure := uomPixels;
xPdfSec.AddPage(xPdfPg);
end;
procedure AddFontsToPDFDoc(var d: TPDFDocument);
const
xFontAry: array [0..2] of String = ('Noto Sans JP', 'Noto Serif JP', 'Yu Mincho Demibold');
var
i, xCnt: Integer;
xFpFci: TFPFontCacheItem;
begin
xCnt :=0;
for i := 0 to High(xFontAry) do begin
xFpFci := xFpFcl.Find(xFontAry[i], False, False);
if xFpFci <> nil then begin
xPdfDoc.AddFont(xFpFci.FileName, xFpFci.FamilyName);
xCnt :=xCnt+1;
end;
end;
if (xCnt = 0) and (xFpFcl.Count > 0) then begin
xFpFci := xFpFcl.Items[0];
xPdfDoc.AddFont(xFpFci.FileName, xFpFci.FamilyName);
end;
end;
begin
//load fonts
xFpFcl := TFPFontCacheList.Create;
xFpFcl.SearchPath.Add('C:\Windows\Fonts');
xFpFcl.BuildFontCache;
xFpFcl.ReadStandardFonts;
//doc
xPdfDoc := TPDFDocument.Create(nil);
xPdfDoc.Options := [poPageOriginAtTop];
xPdfDoc.StartDocument;
xPdfSec := xPdfDoc.Sections.AddSection;
AddFontsToPDFDoc(xPdfDoc);
AddPage;
//xFt_NotoSerifJP := xPdfDoc.AddFont('NotoSerifJP-VF.ttf', 'Noto Serif JP');
xFt_NotoSerifJP := xPdfDoc.AddFont('yumindb.ttf', 'Yu Mincho Demibold');
xPdfPg.SetFont(xFt_NotoSerifJP, 13);
xPdfPg.SetColor(clBlack, false);
xString :='1行目。あいうえおガギグゲゴパピプペポ';
xPdfPg.WriteText(50, 50, xString);
xString :='2行目';
xPdfPg.WriteText(50, 60, xString);
xPdfDoc.SaveToFile('aaa.pdf');
xPdfDoc.free;
OpenDocument('aaa.pdf');
close;
end;