这里使用代码为flutter创建pdf文件。我正在使用插件pdf 1.0.6。
我的问题:
如何创建具有不同字体大小的多行文本?
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;
Run Code Online (Sandbox Code Playgroud)
}
我建议您更新到最新版本,pdf: ^1.4.因为如何构建 pdf 发生了很多变化。
https://github.com/DavBfr/dart_pdf/blob/master/pdf/example/main.dart
就像这样简单
pdf.addPage(Page(
pageFormat: PdfPageFormat.a4,
build: (Context context) {
return Center(
child: Text('Hello World', style: TextStyle(fontSize: 40)),
); // Center
})); // Page
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3986 次 |
| 最近记录: |