I am using pdf package to generate a pdf file.
I want my custom font for the pdf file.
But I don't know how to add a font in the pubspec.yaml
for the Dart project. This pubspec.yaml
of the dart project doesn't have flutter:
.
Asked
Active
Viewed 18 times
0

Sittiphan Sittisak
- 486
- 4
- 15
-
1It looks like PdfTtfFont can construct a font from a byte data. Just gotta get that into your code. – Randal Schwartz Jul 05 '23 at 02:37
1 Answers
0
From the comment by Randal Schwartz: It looks like PdfTtfFont can construct a font from a byte data. Just gotta get that into your code.
The solution is
import 'dart:io';
import 'package:pdf/widgets.dart' as pw;
final fontFile = File('file path').readAsBytesSync();
final font = pw.Font.ttf(fontFile.buffer.asByteData());

Sittiphan Sittisak
- 486
- 4
- 15