Here with the code to create a pdf file for flutter. I am using plugin pdf 1.0.6.
My questions:
How to create multi lines of text with different font size?
PDFDocument _generateDocument() {
final pdf = new PDFDocument(deflate: zlib.encode);
final page = new PDFPage(pdf, pageFormat: PDFPageFormat.A4);
final g = page.getGraphics();
final font = new PDFFont(pdf);
final top = page.pageFormat.height;
g.setColor(new PDFColor(0.0, 1.0, 1.0));
g.drawRect(50.0 * PDFPageFormat.MM, top - 80.0 * PDFPageFormat.MM,
100.0 * PDFPageFormat.MM, 50.0 * PDFPageFormat.MM);
g.fillPath();
g.setColor(new PDFColor(0.3, 0.3, 0.3));
g.drawString(font, 12.0, "Hello World!", 10.0 * PDFPageFormat.MM,
top - 10.0 * PDFPageFormat.MM);
return pdf;
}
I recommend you to update to the latest version pdf: ^1.4.
as a lot has changed on how to build a pdf.
https://github.com/DavBfr/dart_pdf/blob/78232de1f962ea04c7e950d0f737417a35863071/pdf/lib/src/page_format.dart#L49
https://github.com/DavBfr/dart_pdf/blob/master/pdf/example/main.dart
As simple as
pdf.addPage(Page(
pageFormat: PdfPageFormat.a4,
build: (Context context) {
return Center(
child: Text('Hello World', style: TextStyle(fontSize: 40)),
); // Center
})); // Page
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With