text exceeds page size

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:


page2.graphics.drawString(
    'Foi realizada a vistoria em todos os Hidrantes '
    'e abrigos pertencentes ao sistema de pressurização'
    ' por Hidrantes do(a) ${relatorio.NomeCliente.toString().toUpperCase()}'
    '. Para tanto, a NT 2-02:2019, em seus itens 5.3 (Dos abrigos de '
    'Hidrantes), 5.5 (Dos tipos de sistemas) e 5.6 '
    '(Da instalação dos Hidrantes e Mangotinhos), '
    'descreve as exigências para a instalação dos '
    'Hidrantes, abrigos e seus dispositivos, conforme '
    'listado abaixo:',
    PdfStandardFont(PdfFontFamily.courier, 12),
    brush: PdfBrushes.black,
    bounds: Rect.fromLTWH(25, 55, page2.getClientSize().width - 80, 90),
    format: PdfStringFormat(
      lineAlignment: PdfVerticalAlignment.middle,
      alignment: PdfTextAlignment.justify,
    ),
  );


How can I make it change pages if it exceeds the page size?



4 Replies

IJ Irfana Jaffer Sadhik Syncfusion Team May 16, 2023 11:05 AM UTC

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




JB João Bosco Teixeira Junior May 17, 2023 06:37 AM UTC

thanks for the answer... your support is excellent...

I will try what you proposed here



JB João Bosco Teixeira Junior May 18, 2023 04:22 PM UTC

can i use this text in section?



IJ Irfana Jaffer Sadhik Syncfusion Team May 19, 2023 09:45 AM UTC

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.


Loader.
Up arrow icon