【发布时间】:2021-06-01 17:45:30
【问题描述】:
问题:我有一个现有的 PDF 表格 ( *.pdf ) 需要填写。如何使用 dart 动态填充它?
【问题讨论】:
问题:我有一个现有的 PDF 表格 ( *.pdf ) 需要填写。如何使用 dart 动态填充它?
【问题讨论】:
我已经使用了 syncfusion 扩展来做到这一点。 您可以在 pub.dev 上找到信息: https://pub.dev/packages/syncfusion_flutter_pdf 跟随样本
//Load the existing PDF document.
final PdfDocument document =
PdfDocument(inputBytes: File('input.pdf').readAsBytesSync());
//Get the form.
PdfForm form = document.form;
//Get text box and fill value.
PdfTextBoxField name = document.form.fields[0] as PdfTextBoxField;
name.text = 'John';
//to change the font or size use
name.font = PdfStandardFont(PdfFontFamily.timesRoman, 12,0);
//Get the radio button and select.
PdfRadioButtonListField gender = form.fields[1] as PdfRadioButtonListField;
gender.selectedIndex = 1;
//Save and dispose the document.
File('output.pdf').writeAsBytesSync(document.save());
document.dispose();
【讨论】: