Can I draw onto an existing PDF multiple lines of text in a paragraph section?

Screenshot 2022-02-02 000608.png

Above is a screenshot of a section of an existing PDF I'm trying to fill. I have a form that accepts sentences and was wondering if I could draw the text onto the lines of the PDF above because right now it just puts the text in the middle of that sectio


1 Reply 1 reply marked as answer

AG Anantha Gokula Raman Jeyaraman Syncfusion Team February 3, 2022 01:01 PM UTC

Hi Marlon,

The Syncfusion Flutter PDF allows you to draw and manipulate the text as per your requirement. In this case, to properly align the drawn text line with the existing page line sections, you can draw text using a format (PdfStringFormat class) and add a suitable line spacing to the paragraph.

Kindly use the following code snippet for reference,

  String text =

      'Essential Studio is a software package that provides state-of-the-art solutions for startups and enterprises. It includes more than 1,700 components and frameworks for WinForms, WPF, ASP.NET (Web Forms, MVC, Core), UWP, WinUI, Xamarin, Flutter, Blazor, JavaScript, Angular, Vue, and React that make developers’ work easier.';

 

  //Load existing document.

  PdfDocument doc =

      PdfDocument(inputBytes: File('path/input.pdf').readAsBytesSync());

 

  //Get existing page.

  PdfPage page = doc.pages[0];

 

  //Initialize coordinates.

  double margin = 40;

  double paragraphStartY = 35;

  double pageWidth = page.getClientSize().width;

  double pageHeight = page.getClientSize().height;

 

  //Create PdfStringFormat instance with a suitable line space.

  PdfStringFormat format = PdfStringFormat(lineSpacing: 2);

 

  //Draw text on the existing page.

  doc.pages[0].graphics.drawString(

      text, PdfStandardFont(PdfFontFamily.helvetica, 12),

      format: format,

      bounds: Rect.fromLTWH(

          margin,

          margin + paragraphStartY,

          pageWidth - (margin * 2),

          pageHeight - (margin * 2) - paragraphStartY));

  final List<int> bytes = doc.save();

  File('path/output.pdf').writeAsBytes(bytes);

 

  //Dispose the document instance.

  doc.dispose();


screenshot:

Graphical user interface, text, application

Description automatically generated


For more details about PdfStringFormat class, kindly refer this following link, https://pub.dev/documentation/syncfusion_flutter_pdf/latest/pdf/PdfStringFormat-class.html

Regards,

Anantha Gokula Raman J


Marked as answer
Loader.
Up arrow icon