代码之家  ›  专栏  ›  技术社区  ›  jonathan Cunha 4Cubo

当内容溢出时,如何在Flutter中动态地向PDF添加新页面?

  •  0
  • jonathan Cunha 4Cubo  · 技术社区  · 2 年前

    我正在做一个Flutter项目,我需要生成一个PDF文档,并在内容溢出当前页面时自动添加新页面。我正在使用pdf包生成pdf。

    我尝试过向页面添加内容并检查溢出,但在实现方面遇到了一些挑战。当内容超过当前页面的可用空间时,如何有效地添加新页面?

    以下是我的代码的简化版本:

      Future<void> generate() async {
    final logo = await _logo();
    final pdf = pw.Document(); 
    pdf.addPage(pw.Page(
      pageFormat: PdfPageFormat.a4,     
      build: (pw.Context context) {
        return pw.Column(
          children: [
            pw.Row(
              crossAxisAlignment: pw.CrossAxisAlignment.center,
              children: [
                logo,
                pw.Text(
                  Texts.title.toUpperCase(),
                  textAlign: pw.TextAlign.center,
                  style: pw.TextStyle(
                    fontSize: 18,
                    fontWeight: pw.FontWeight.bold,
                  ),
                ),
              ],
            ),
            _buildTableDadosTransformador(),
            _buildTablePotencia(),
            _buildTableNucleo(),
            _buildTablePrimario(),
          ],
        );
      },
    ));
    savePDF(pdf);
    

    }

    1 回复  |  直到 2 年前
        1
  •  1
  •   Md. Yeasin Sheikh    2 年前

    您可以使用 MultiPage 而不是 Page 当页面溢出时,这将增加页面。

    pdf.addPage(
      pw.MultiPage(
        build: (context) {
          return [.....];
        }
       ),
    )