How to add font to the pubspec.yml for the dart server

24 views Asked by At

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:.

1

There are 1 answers

0
Sittiphan Sittisak On

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());