简体   繁体   English

Flutter 创建多个 PDF 页面

[英]Flutter Creating multiple PDF Pages

I am trying to show results of a sql query as PDF page in flutter application.我试图在 flutter 应用程序中将 sql 查询的结果显示为 PDF 页面。 As long as the data do not cross a pagefull, it displays correctly.只要数据不跨页,它就可以正确显示。 When data is more than a pagefull it results in "Exception: This widget created more than 20 pages. This may be an issue in the widget or the document. See https://pub.dev/documentation/pdf/latest/widgets/MultiPage-class.html"当数据超过一页时,它会导致“异常:此小部件创建了 20 多个页面。这可能是小部件或文档中的问题。请参阅https://pub.dev/documentation/pdf/latest/widgets/多页类.html"

My pdf generating code is like below where 'data' is a list of map data.我的 pdf 生成代码如下所示,其中“数据”是 map 数据的列表。

    pdf.addPage(pw.MultiPage(
        pageFormat: PdfPageFormat.a4,
        build: (pw.Context context) {
          return <pw.Widget>[
            pw.Column(children: [
              pw.Table(children: [
                pw.TableRow(children: [
                  ...data[0].keys.map((e) => pw.Text(e)),
                ]),
                ...data.map((e) {
                  return pw.TableRow(children: [
                    ...e.values.map((v) => pw.Text(v)),
                  ]);
                }),
              ])
            ])
          ];
        }));
    return pdf.save();
  }

I tried wrapping the pw.Column in various combinations (Flex, Partition, Table, Wrap, GridView, and Column.) as listed in https://pub.dev/documentation/pdf/latest/widgets/MultiPage-class.html我尝试以https://pub.dev/documentation/pdf/latest/widgets/MultiPage-class.https中列出的各种组合(Flex、Partition、Table、Wrap、GridView 和 Column)包装 pw.Column。

I am not able to grasp how to span the data over multiple pages automatically using the Flex, Partition, Table, Wrap, GridView, and Column.我无法掌握如何使用 Flex、Partition、Table、Wrap、GridView 和 Column 自动跨越多个页面。 How Do I do that?我怎么做?

Or is there a way to detect current TableRow/Widget position and create new page on exceeding the page length (of course - margins)?或者有没有办法检测当前的 TableRow/Widget position 并在超过页面长度(当然 - 边距)时创建新页面? Thanks a lot.非常感谢。

I resolved it by removing pw.Column in the above code.我通过删除上面代码中的 pw.Column 来解决它。 It works perfectly now.它现在完美运行。 ie IE

return <pw.Widget>[
  pw.Table(children: [
  // rest of the code follows

Thanks谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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