Size of text in a Actofield

Size of text in a Actofield

Forum member · Feb 11, 2010
I have a pdf with a large Acrofield that can take around 15 lines of text inside it. I am currently filling this field using the CreateLabel() method. Is there any way of finding out whether the text that I am trying to enter will fit into the acrofield or not ?.

Re: Size of text in a Actofield

Support · Feb 11, 2010
Hello, Currently it is not possible to find out the amount of text which can fit in a text field. However you may try using the TextArea object which gives the height required to the given text. You will have to create a TextArea using the text you have and get the height required by using the GetRequiredHeight method of the text area and you can compare this height with the height of the TextField. The CreateLabel method will add the text on top of the TextField and it will not fill the field. If the text is more then it will come out of the field. Thanks, ceTe Software Support Team.

Re: Size of text in a Actofield

Forum member · Feb 12, 2010
Thanks for coming back to me. My requirements are a bit more complicated. What I have is two large Text boxes which can contain 15-20 lines of text on two different pdf pages. The Text that is supposed to go into the text box is dynamic. What I need to do is check if the text can be put into the Text Box on 1st Pdf. If the full text cannot be put into this text box then I have to cut out the portion of text that can fit into this text box and put into it. I would then have to put the remaining portion of text that cannot be displayed on the First text box into the second text box on the 2nd pdf. Can you suggest any way of achieving this ?

Re: Size of text in a Actofield

Support · Feb 12, 2010
Hello, Yes, you can achieve this requirement without any problem. You can do this by using the TextArea page element instead of the CreateLabel method. CreateLabel method actually adds text in place of the text field, so here we have to add the text area in place of the text field. Below is a sample code for this. PdfDocument pdf = new PdfDocument(@"C:\Temp\fields.pdf"); MergeDocument document = new MergeDocument(pdf, new MergeOptions(false)); string str = "This is a very big text....."; //Get the field PdfFormField field = pdf.Form.Fields["fieldname"]; //Page which has the field Page page = document.Pages[field.GetOriginalPageNumber() - 1]; //Get X, Y position of the field float x = field.GetX(page); float y = field.GetY(page); //Add text area in that position to that page TextArea area = new TextArea(str, x, y, field.Width, field.Height); page.Elements.Add(area); //Get the overflow text area and you can add this to another page or in place of another field. area = area.GetOverflowTextArea(); Page p2 = new Page(); p2.Elements.Add(area); document.Pages.Add(p2); document.Draw(@"C:\Temp\output.pdf"); Thanks, ceTe Software Support Team.

Re: Size of text in a Actofield

Forum member · Apr 8, 2011
I am using this code //Get X, Y position of the field float x = pdf.Form.Fields[fieldName].GetX(page); float y = pdf.Form.Fields[fieldName].GetY(page); // Create an formatted style FormattedTextAreaStyle style = new FormattedTextAreaStyle(setting.FontFamily, setting.FontSize, false); FormattedTextArea formattedTextArea = new FormattedTextArea(dataValue, x + setting.XOffset, y + setting.YOffset, pdf.Form.Fields[fieldName].Width, pdf.Form.Fields[fieldName].Height, style); page.Elements.Add(formattedTextArea); //Get the overflow text area and you can add this to another page or in place of another field. FormattedTextArea overflowArea = formattedTextArea.GetOverflowFormattedTextArea(); if (overflowArea != null) _overflowFieldText = overflowArea.Text; I have a large text field in which some text has to be shown as Bold and the remaining text has to be shown with Regular font. So I am using FormattedTextArea to display this text. The text to be diplayed in this is totally dynamic. If the Text is too large and cannot fit inside the Pdf Form Field then I have to get the Overflow text and put that in another form field on next page. However the code fails at following line FormattedTextArea overflowArea = formattedTextArea.GetOverflowFormattedTextArea(); Can you please let me know how to fix this issue

Re: Size of text in a Actofield

Support · Apr 8, 2011
Hello, We did some testing on our end using the similar code which you have posted and we are able to add the overflow text over the other form field without any problem using our version 5 DynamicPDF Merger for .NET product. Please note that the width of the FormattedTextArea is constant. Below is the sample code. PdfDocument pdf = new PdfDocument(@"C:\temp\fw9AcroForm_03.pdf"); MergeDocument document = new MergeDocument(pdf, new MergeOptions(false)); string str = "Yes, you can achieve this requirement without any problem. You can do this by using the FormattedTextArea page element instead of the CreateLabel method. CreateLabel method actually adds text in place of the text field, so here we have to add the text area in place of the text field. Below is a sample code for this."; //Get the field PdfFormField field = pdf.Form.Fields["f1-6"]; //Page which has the field Page page = document.Pages[field.GetOriginalPageNumber() - 1]; //Get X, Y position of the field float x = field.GetX(page); float y = field.GetY(page); //Add text area in that position to that page FormattedTextArea area = new FormattedTextArea(str, x, y, field.Width, field.Height,FontFamily.Helvetica,12,true); page.Elements.Add(area); //Get the overflow text area and you can add this in place of another field. if (area.HasOverflowText()) { PdfFormField field1 = pdf.Form.Fields["f1-1"]; //Page which has the field Page page1 = document.Pages[field1.GetOriginalPageNumber() - 1]; //Get X, Y position of the field float x1 = field1.GetX(page); float y1 = field1.GetY(page); area = area.GetOverflowFormattedTextArea(x1, y1,field1.Height); page1.Elements.Add(area); } document.Draw(@"C:\Temp\output.pdf"); If you continue getting the error then please send over the input PDF document,stack trace of the error message and the sample text which you are trying to add it to the PDF document to our support at: [^a|mailto:support@cete.com|opennewiwndow|support@cete.com^] so that they can look into it further. Thanks, ceTe Software Support Team.

Re: Size of text in a Actofield

Forum member · Apr 8, 2011
In the Code that I have posted before the following Line Gives the Error :- //Get the overflow text area and you can add this to another page or in place of another field. FormattedTextArea overflowArea = formattedTextArea.GetOverflowFormattedTextArea(x + setting.XOffset, y + setting.YOffset, pdf.Form.Fields[fieldName].Height); if (overflowArea != null) _overflowFieldText = overflowArea.Text; When I try to get the Text that has overflown using "overflowArea.Text" then this gives an exception message "Text cannot be read on an overflown formattedTextArea"

Re: Size of text in a Actofield

Support · Apr 8, 2011
Hello, It is not possible to get or set the text of OverflowFormattedTextArea object using our DynamicPDF Generator product. Thanks, ceTe Software Support Team.