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.)
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.
The following image formats are supported: JPEG, PNG, GIF, Animated GIF, WebP, Animated WebP, BMP, and WBMP.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With