简体   繁体   中英

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.)

第 1 列

1-2栏

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM