Page Break

Page Break

Forum member · Aug 23, 2012
Hi, How to give page break in a pdf document for paragraph thanks yashwant

Re: Page Break

Support · Aug 23, 2012
Hello Yashwant, It is not possible to directly add page break for the paragraph using our DynamicPDF Generator for .NET product. You will need to add the text contents to the PDF page using TextArea or FormattedTextArea. You will need to keep track of height of the TextArea, required height to fit the text and available page height. You can take the overflow text of TextArea and add a new page dynamically to add the remaining contents of TextArea. Please refer documentation on text continuation here . Thanks, ceTe Software Support Team.

Re: Page Break

Forum member · Aug 24, 2012
Hi // Define Formatted Text Area FormattedTextArea formattedTextArea = new FormattedTextArea(Paragraph, 0, 0, 256, 400, ceTe.DynamicPDF.FontFamily.Helvetica, 12, false); dont want to give the height 400(hardcoded value) to the FormattedTextArea it should auto adjust as per the text in FormattedTextArea is there any other way to adjust the height of the FormattedTextArea?

Re: Page Break

Support · Aug 24, 2012
Hello, You will need to set some height to the FormattedTextArea at the time of creating object of it and you can dynamically change the height in the further process using Height property of the FormattedTextArea. You can get the required height to fit the contents using GetRequiredHeight method and you can compare this height with the page height and change it accordingly. Below is sample code to add the text contents using FormattedTextArea. Document document = new Document(); String paragraph = "When working with dynamic data, the length of text is not always known. Because of this, the TextArea and FormattedTextArea classes have built-in support for text continuation. This allows for quick and easy continuation of text over multiple columns or multiple pages. "; // Define Formatted Text Area FormattedTextArea formattedTextArea = new FormattedTextArea(paragraph, 0, 0, 256, 400, ceTe.DynamicPDF.FontFamily.Helvetica, 12, false); //Setting desired height to fit the contents. formattedTextArea.Height = formattedTextArea.GetRequiredHeight(); do { Page page = new Page(); document.Pages.Add(page); if (formattedTextArea.GetRequiredHeight() > page.Dimensions.Body.Height) { formattedTextArea.Height = page.Dimensions.Body.Height; } else { formattedTextArea.Height = formattedTextArea.GetRequiredHeight(); } page.Elements.Add(formattedTextArea); formattedTextArea = formattedTextArea.GetOverflowFormattedTextArea(); } while (formattedTextArea != null); document.Draw(@"C:\MyDocument.pdf"); Thanks, ceTe Software Support Team.

Re: Page Break

Forum member · Jul 11, 2016
Hello, Is there a method that I can use to get the page body's AVAILABLE height for comparison against the text area's required height for when there are already existing elements assigned to the page body? Thanks, Johnathan

Re: Page Break

Support · Jul 14, 2016
Hello Jonathan, There is no direct method or property available in DynamicPDF API to get the page body’s available height where in some page elements already present in the PDF page. If you are adding page elements to the PDF page then you will need to keep track of Y position accordingly as per the page element’s Y position and height. Below is the code sample for calculating the available space using yPosition in the PDF page. Document document = new Document(); Page page = new Page(); string text = "This is to test"; for (int i = 0; i < 6; i++) { text = text + text; } float yPosition = 0; float padding = 5; TextArea area1 = new TextArea(text, 0, yPosition, 400, 200); area1.Height = area1.GetRequiredHeight(); page.Elements.Add(area1); //Calculating the Y position. yPosition = area1.Y + area1.Height + padding; //Calculating the available space in the page. float availableSpace = page.Dimensions.Body.Height - yPosition; //Adding new page element. string text1 = "This is text in second TextArea. "; for (int i = 0; i < 5; i++) { text1 = text1 + text1; } TextArea area2 = new TextArea(text1, 0, yPosition, 400, 200); area2.Height = area2.GetRequiredHeight(); if (area2.Height < availableSpace) { area2.Height = area2.GetRequiredHeight(); } else { area2.Height = availableSpace; } page.Elements.Add(area2); document.Pages.Add(page); document.Draw(@"C:\Temp\MyDocument.pdf"); Thanks, ceTe Software Support Team.