DavBfr / dart_pdf

Pdf creation module for dart/flutter
https://pub.dev/packages/pdf
Apache License 2.0
1.41k stars 630 forks source link

large Paragraph (bigger than one page) does not work #610

Closed ameenQ closed 3 years ago

ameenQ commented 3 years ago
final pdf = pw.Document();
  var test =
      'The Portable Document Format (PDF) is a file format developed by Adobe in the 1990s to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. Based on the PostScript language, each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, vector graphics, raster images and other information needed to display it. PDF was standardized as an open format, ISO 32000, in 2008, and no longer requires any royalties for its implementation.';
  test +=
      'zzzzzzzzzzzThe Portable Document Format (PDF) is a file format developed by Adobe in the 1990s to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. Based on the PostScript language, each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, vector graphics, raster images and other information needed to display it. PDF was standardized as an open format, ISO 32000, in 2008, and no longer requires any royalties for its implementation.';
  test +=
      'yyyyyyyyyyyyyyyyyyyThe Portable Document Format (PDF) is a file format developed by Adobe in the 1990s to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. Based on the PostScript language, each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, vector graphics, raster images and other information needed to display it. PDF was standardized as an open format, ISO 32000, in 2008, and no longer requires any royalties for its implementation.';
  test +=
      'xxxxxxxxxxxxThe Portable Document Format (PDF) is a file format developed by Adobe in the 1990s to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. Based on the PostScript language, each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, vector graphics, raster images and other information needed to display it. PDF was standardized as an open format, ISO 32000, in 2008, and no longer requires any royalties for its implementation.';
  test +=
      'aaaaaaaaaaaaThe Portable Document Format (PDF) is a file format developed by Adobe in the 1990s to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. Based on the PostScript language, each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, vector graphics, raster images and other information needed to display it. PDF was standardized as an open format, ISO 32000, in 2008, and no longer requires any royalties for its implementation.';
  test +=
      'wwwwwwwwwwwwThe Portable Document Format (PDF) is a file format developed by Adobe in the 1990s to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. Based on the PostScript language, each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, vector graphics, raster images and other information needed to display it. PDF was standardized as an open format, ISO 32000, in 2008, and no longer requires any royalties for its implementation.';
  test +=
      'ccccccccccccccccThe Portable Document Format (PDF) is a file format developed by Adobe in the 1990s to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. Based on the PostScript language, each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, vector graphics, raster images and other information needed to display it. PDF was standardized as an open format, ISO 32000, in 2008, and no longer requires any royalties for its implementation.';
  test +=
      '111111111111111111111The Portable Document Format (PDF) is a file format developed by Adobe in the 1990s to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. Based on the PostScript language, each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, vector graphics, raster images and other information needed to display it. PDF was standardized as an open format, ISO 32000, in 2008, and no longer requires any royalties for its implementation.';

  pdf.addPage(pw.MultiPage(
    pageFormat: PdfPageFormat.a4,
    build: (pw.Context context) => [pw.Paragraph(text: test)],
  ));

  final file = File('example.pdf');
  await file.writeAsBytes(await pdf.save());

Exception: Widget won't fit into the page as its height (1047.1332283464558) exceed a page height (728.5039370078739). You probably need a SpanningWidget or use a single page layout

and if warp it

pw.Wrap(children: [pw.Paragraph(text: test)])

the program stuck and don't do anthing

any help ?

DavBfr commented 3 years ago

Putting a single widget in a Wrap will not help cutting it in half. A Paragraph can't be split. Just do multiple smaller Paragraphs.

ameenQ commented 3 years ago

Putting a single widget in a Wrap will not help cutting it in half. A Paragraph can't be split. Just do multiple smaller Paragraphs.

the problem I have dynamic content with dynamic font size and even dynamic language (Arabic, English). and some times the content is bigger than 4 pages.

cutting the dynamic content into smaller random size paragraphs make the page so messy

I'm using php with mpdf and it work just fine.

I want to jump to dart and this is my only problem so far.

can you help me with it ?

DavBfr commented 3 years ago

How do you do it with mpdf?

foxmedo commented 3 years ago

same issue we have a big table and we do not know how to split it in multi page we do not know what it the height of each row what we need is when we arrive to the End of file it move us to the next one

any suggestion ?

DavBfr commented 3 years ago

A table will spread on multiple pages, put it as a direct child of a MultiPage object.

MohammadEzoo commented 3 years ago

still not working

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] commented 3 years ago

Closing this stale issue because it has no activity.

tulioccalazans commented 1 year ago

I tried to do this with a TextSpan, but it didn't work either!

pw.RichText(
      //textAlign: pw.TextAlign.justify,
      text: pw.TextSpan(
          children: [ ... TextSpan... ]
      ),
    )
DavBfr commented 1 year ago

use overflow: span