We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

When creating a PDF from a string it does not auto increment pages

Hello,

Is there a way to have the PDF document increment pages on it's own based on the content? 

        public static string CreatePDF(string message)

        {

            // Create a new PDF document

            PdfDocument document = new PdfDocument();



            //Add a page to the document

            Syncfusion.Pdf.PdfPage page = document.Pages.Add();




            //Create PDF graphics for the page

            PdfGraphics graphics = page.Graphics;



            PdfStringFormat format = new PdfStringFormat();

            //Set the text alignment.

            format.WordWrap = PdfWordWrapType.Word;


            //Draw the text

            graphics.DrawString(message, new PdfStandardFont(PdfFontFamily.Helvetica, 16), PdfBrushes.Black, new PointF(0, 0), format);


            //Save the document to the stream

            MemoryStream stream = new MemoryStream();

            document.Save(stream);


            //Close the document

            document.Close(true);


            //Save the stream as a file in the device and invoke it for viewing

            var path = DependencyService.Get<IWriteToFile>().Save("Output.pdf", stream);



            return path.ToString();

        }



Thanks,

David


1 Reply

IJ Irfana Jaffer Sadhik Syncfusion Team October 17, 2022 09:09 AM

Hi David,

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.


Please follow the below links for more information:

https://help.syncfusion.com/file-formats/pdf/working-with-text?cs-save-lang=1&cs-lang=csharp


Please let us know if you need any further assistance with this.

Regards,

Irfana J.







Loader.
Live Chat Icon For mobile
Up arrow icon