AddFormattedTextArea

AddFormattedTextArea

Forum member · Feb 10, 2014
Hello How can you get the height of a FormattedTextArea before adding it to the actual page? Right now i am doing this Set objFormattedTextArea = objPage.AddFormattedTextArea( txt, x, y, w, h,FontFamily,FontSize) height=objFormattedTextArea.GetRequiredHeight() I would like to create an instance in memory and then if i have enough space place it on the page. Hopefully that makes sense. Adam

Re: AddFormattedTextArea

Support · Feb 12, 2014
Hello Adam, It is not possible to create FormattedTextArea and other page element objects without adding it to a Page. You can calculate the available space in the page before adding the FormattedTextArea and decide on adding the FormattedTextArea to current page or new page. In order to calculate the available space in the PDF page, you will need to keep track of Y position and height of the page elements. Below is VB code sample to calculate the available space in the PDF page before adding the FormattedTextArea. Dim objDoc As DynamicPDF.Document Dim objPage As DynamicPDF.Page 'Create Document object Set objDoc = New DynamicPDF.Document 'Add a page to the document Set objPage = objDoc.AddPage() Dim MyText As String MyText = "This is a test of the functionality." MyText = MyText & MyText MyText = MyText & MyText Dim textAreaobj As DynamicPDF.TextArea Set textAreaobj = objPage.AddTextArea(MyText, 0, 0, 200, 200) textAreaobj.Height = textAreaobj.GetRequiredHeight() 'Calculate the space avaible in the page. Dim pageHeight As Single pageHeight = objPage.pageHeight - (objPage.MarginTop + objPage.MarginBottom) Dim newYPosition As Single newYPosition = textAreaobj.Y + textAreaobj.Height + 5 Dim availableSpace As Single availableSpace = pageHeight – newYPosition Dim MyFormattedText As String MyFormattedText = "<p>Formatted text area provide rich formatting support for " + _ "text that appears in the document. You have complete control over 8 paragraph " + _ "properties: spacing before, spacing after, first line indentation, left indentation,</p>" 'Check for the desired available space to add the page element. If availableSpace > 100 Then Dim MyFormattedTextArea As DynamicPDF.FormattedTextArea Set MyFormattedTextArea = objPage.AddFormattedTextArea(MyFormattedText, 0, newYPosition, 256, availableSpace, DPDF_FontFamily_Helvetica, 12, False) Else 'Add the FormattedTextArea to new page. Dim objNewPage As DynamicPDF.Page Set objNewPage = objDoc.AddPage() Dim MyNewFormattedTextArea As DynamicPDF.FormattedTextArea Set MyFormattedTextArea = objNewPage.AddFormattedTextArea(MyFormattedText, 0, 0, 256, 200, DPDF_FontFamily_Helvetica, 12, False) MyNewFormattedTextArea.Height = MyNewFormattedTextArea.GetRequiredHeight() End If 'Save the file to disk in same folder as the app objDoc.DrawToFile ("C:\MyDocument.pdf") Thanks, ceTe Software Support Team.