flutter-packages
flutter-packages copied to clipboard
Allow obtaining the font files
Request
I'm the developer of the library pdf. This library renders PDF files from dart code. It can load TTF fonts to draw text in the document.
As far as I can see, this google-fonts library does not expose the font files, URL, or bytes in any way.
I would need something to get the Uint8List font data for any available fonts without duplicating this library.
Usage
import 'dart:io';
import 'dart:typed_data';
import 'package:pdf/widgets.dart';
void main() async {
final pdf = Document();
// Load the file here.
// A google_font API would be much appreciated to replace this line
// like: final Uint8List fontData = await GoogleFonts.getFontData('Lato');
final Uint8List fontData = await File('open-sans.ttf').readAsBytes();
final ttf = Font.ttf(fontData.buffer.asByteData());
pdf.addPage(
Page(
build: (context) {
return Center(
child: Text(
'Hello World',
style: TextStyle(
font: ttf,
fontSize: 40,
),
),
);
},
),
);
await File('output.pdf').writeAsBytes(pdf.save());
}
Platforms:
- iOS, Android, macOS, Web
++1
That would be awesome!!!
Any progress on this? would be great to have this feature.
Much Needed Feature!
bump
Absolutely Required
I will love it
This is a much required feature please
any new news !!
anu update ?
I am also using Google Fonts, I first download it and using like this
theme: pw.ThemeData.withFont(
base:
Font.ttf(await rootBundle.load("assets/fonts/Sarabun-Regular.ttf")),
bold: Font.ttf(await rootBundle.load("assets/fonts/Sarabun-Bold.ttf")),
),
@GuvanchBayryyyev can you please elaborate?
This is proving more complex than initially thought and requires a thorough refactor, along with tackling https://github.com/material-foundation/flutter-packages/issues/129.