I would like to know if I can make some kind of text that can exceed the size of the page. because I have a text that can change from user to user and it can exceed the size of the page.
I put the text like this below:
How can I make it change pages if it exceeds the page size?
The PdfLayoutFormat class helps to allow the text to flow across pages. The PdfLayoutResult class provides the rendered bounds of the previously added text, which can be used to place successive elements without overlapping.
The following code snippet explains how to add elements relatively and also allow the text to flow across multiple pages.
|
//Create a new PDF document PdfDocument document = PdfDocument();
//Adds a page to the document PdfPage page = document.pages.add();
String text = 'Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base.';
//Create a text element with the text and font PdfTextElement textElement = PdfTextElement( text: text, font: PdfStandardFont(PdfFontFamily.timesRoman, 20));
//Create layout format PdfLayoutFormat layoutFormat = PdfLayoutFormat( layoutType: PdfLayoutType.paginate, breakType: PdfLayoutBreakType.fitPage);
//Draw the first paragraph PdfLayoutResult result = textElement.draw( page: page, bounds: Rect.fromLTWH(0, 0, page.getClientSize().width / 2, page.getClientSize().height), format: layoutFormat)!;
//Draw the second paragraph from the first paragraph end position textElement.draw( page: page, bounds: Rect.fromLTWH(0, result.bounds.bottom + 300, page.getClientSize().width / 2, page.getClientSize().height), format: layoutFormat);
//Saves the document File('Output.pdf').writeAsBytes(await document.save());
//Disposes the document document.dispose(); |
please refer to the below links for more information:
https://help.syncfusion.com/flutter/pdf/working-with-text#creating-a-multicolumn-pdf-document
thanks for the answer... your support is excellent...
I will try what you proposed here
can i use this text in section?
Yes you can create one section for PDF document and add page on that section and draw the same. please use the below code snippet to achieve the same on your end:
//Create a new PDF document PdfDocument document = PdfDocument(); PdfSection section = document.sections!.add(); //Adds a page to the document PdfPage page = section.pages.add(); String text = 'Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base.'; //Create a text element with the text and font PdfTextElement textElement = PdfTextElement( text: text, font: PdfStandardFont(PdfFontFamily.timesRoman, 20)); //Create layout format PdfLayoutFormat layoutFormat = PdfLayoutFormat( layoutType: PdfLayoutType.paginate, breakType: PdfLayoutBreakType.fitPage); //Draw the first paragraph PdfLayoutResult result = textElement.draw( page: page, bounds: Rect.fromLTWH( 0, 0, page.getClientSize().width / 2, page.getClientSize().height), format: layoutFormat)!; //Draw the second paragraph from the first paragraph end position textElement.draw( page: page, bounds: Rect.fromLTWH(0, result.bounds.bottom + 300, page.getClientSize().width / 2, page.getClientSize().height), format: layoutFormat); |
If this was not your actual requirement. Can you please elaborate on your query.? So that we can assist you further in this.