Is there updated version of how to fill form using syncfusion PDF Flutter?

31 Views Asked by At

I tried the code of how to fill preinsert forms on pdf using syncfusion that one created, and I think some argument is outdated because of the null safety. Can someone help me how to properly use the fill form on pdf please. This is my code :

import 'dart:io';

import 'package:syncfusion_flutter_pdf/pdf.dart';

class edit{
final PdfDocument doc = PdfDocument(inputBytes: File('template/cl.pdf').readAsBytesSync());

late PdfForm form = doc.form;
//Get text box and fill value.
late PdfTextBoxField name = doc.form.fields[0] as PdfTextBoxField;
name.text = 'John';
//to change the font or size use
name.font = PdfStandardFont(PdfFontFamily.timesRoman, 12,0);
}

I want a code that can fill the form with some textform field widget that I made through the widget.

1

There are 1 best solutions below

0
Jeyalakshmi T On

We suggest you to check the field type before accessing it properties to avoid unwanted exceptions. Please refer to the following code snippet for your reference.

final PdfDocument document = PdfDocument(inputBytes: await _readData('Input.pdf'));

late PdfForm form = document.form;

//Get text box and fill value.

for (int i = 0; i < form.fields.count; i++){

  PdfField field = form.fields[i];

   if(field is PdfTextBoxField) {

     // fill in the value

     field.text = 'John';

     // Change the font or size if needed

     field.font = PdfStandardFont(PdfFontFamily.timesRoman, 12);

   }

}

Please refer to the UG documentation for further details.

https://help.syncfusion.com/flutter/pdf/working-with-forms#filling-form-fields-in-an-existing-pdf-document

If still you are facing issues, we kindly request you to share the input PDF document to reproduce the reported issue on our end. It will be helpful for us to analyze and assist you further on this.

Note: I work for Syncfusion.