Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create images in A4 or PDF in Flutter from widgets?

My app needs to create an image or a pdf in A4 format from Widgets, actually a Column that will have a dynamic height (depending on the content the user adds on that SingleChildScrollView -> Column, the user can add images and texts to that Column).

How do I create images in A4 format or PDF in Flutter from Widgets of a Column that will have a dynamic height? (I can have a Column with a list of widgets that will fit the screen and others that doesn't, like 20 big widgets that will go out of the screen.)

Column 1

Column 1-2

like image 886
djalmafreestyler Avatar asked May 25 '21 01:05

djalmafreestyler


People also ask

How do I add an image to a PDF in flutter?

The 'PdfBitmap' API accepts List and base64 string as inputs, so you can retrieve the image from the web URL as base64 or List and assign it to the bitmap class. Steps to insert an image to the PDF using Web URL: Add http package to the dependencies section of the pubspec. yaml file.

What are the different types of image widgets in flutter?

The following image formats are supported: JPEG, PNG, GIF, Animated GIF, WebP, Animated WebP, BMP, and WBMP.


1 Answers

Method 1: Generate for one page, then (automatically) scroll to next page, then generate for the second page, etc.

Method 2: For each page, wrap by one RepaintBoundary and one Key. Say you have 10 pages, then you have 10 keys, and use those keys to generate all pages.

If only visible thing is generated, try the following:

List<Widget> yourPages = ...;
List<Key> yourKeys = yourPages.map((_) => GlobalKey()).toList(); // or other kinds of keys? what do you use
Stack(children:[
for(var i=0;i< yourPages.length;i++) 
RepaintBoundary(key: yourKeys[i], child: yourPages[i]),
])

In this way, everything may be generate-able.

like image 168
ch271828n Avatar answered Sep 27 '22 23:09

ch271828n