使用 Dart / flutter 在现有 PDF 表单中填写数据

Sno*_*owy 5 pdf dart flutter

问题:我有一个现有的 PDF 表单 ( *.pdf ) 需要填写。如何使用 dart 动态填充它?

CNK*_*CNK 2

我已经使用了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();
Run Code Online (Sandbox Code Playgroud)