Create PDF with text and images in Flutter

Save

PDF stands for “portable document format”.  Essentially, the format is used when you need to save files that cannot be modified but still need to be easily shared and printed, also this is helpful to create invoice, online resume, printing tickets and many more applications are there. So let’s create PDF in flutter with text and images.

Implementation

First Create a new flutter project and then add following dependency packages in pubspec.yaml file.

pdf :- For latest dependency and official documentation refer here.

printing :- For latest dependency and official documentation refer here.

Create the Stateless (CreatePdfMainPage) Widget and call from main.dart by the following code.

FloatingActionButton navigate to PDF preview page when user click on it.

Image.assets :- add image from the local directory, to use assets image add your image path in puspec.yaml file.

Preview of the UI :-

Lastly create a new stateless widget to preview and print the PDF (where the page is navigated after clicking on floating action button) and import the packages in this Preview page :-

Uint8List :- basically It is the List of integers where the values are in the List is 1 Byte or 8-Bits.

makePdf() :- asynchronous method that make the PDF preview layout and return the List of unsigned integers bytes (Uint8List), and following method performed :-

Output

Preview PDF
Save as PDF

Conclusion

In this Blog we have discussed about how to create PDF in flutter with text and images and share PDF.

I hope this blog will help you to understand the topic.

Thanks for reading!

References

https://blog.logrocket.com/how-create-pdfs-flutter/

https://www.geeksforgeeks.org/flutter-simple-pdf-generating-app/

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php

It was a successful collaboration. The Mobikul team provided the client everything they needed in a timely and high-quality manner. They were very professional, reliable, and accessible during the entire process. The client also saw no room for any improvements in the vendor's performance.

Vincenzo Carrano

Vincenzo Carrano

Administrator, Segshop

Talk to Sales

Global

Live Chat
Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home