Start a Project

Create PDF with text and images in Flutter

create-a-pdf-with-text-and-images-in-flutter

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. So we will create a PDF with text and images in flutter.

The PDF document is independent of application software, hardware as well as Operating System and it is helpful to create invoice, online resume, printing tickets and many more applications are there.

You may also check our flutter app development services.

Implementation

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

pdf :- The Pdf creation library is simple to use and offer Widgets system similar to Flutter, It can create a full multi-pages document with graphics, images, and text.

printing :- The Printing plugin that allows Flutter apps to generate and print documents to compatible printers on Android, iOS, macOS, Windows, and Linux, as well as web print.

Code to Create User interface

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 :-

Code to Preview and print PDF

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

Conclusion

Thanks for reading this article ❤️

I hope this blog will help you to learn about create PDF in Flutter and you will be able to implement it. For more updates, make sure to keep following Mobikul Blogs to learn more about mobile app development.

Happy Learning ✍️

You can also check create pdf document in swift.

References

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

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

Exit mobile version