Set Vertical Alignment for Multiline TextBox using Aspose.PDF for .NET - text position is incorrect

I am using version 10.6. When I fill a multiline textbox field using Aspose, the text is aligned at the top of the field, and the first line is chopped off (see attachment wrong.pdf). If I manually enter the same text using Adobe, the alignment is correct (see attachment correct.pdf).


var field = doc.Form[“Notices.Name”];
if (field is Aspose.Pdf.InteractiveFeatures.Forms.TextBoxField)
{
string Value = “A” + Environment.NewLine + “B” + Environment.NewLine + “C” + Environment.NewLine + “D”;

var tb = (Aspose.Pdf.InteractiveFeatures.Forms.TextBoxField)field;
tb.Value = Value;
}

Am I setting the value incorrectly? Or, is there a way to set the vertical alignment to Center?
Thank you.

Hi Gregory,

Thanks for your inquiry. I have tested the scenario using Aspose.Pdf for .NET 10.6.0 and managed to observe the reported alignment issue. For further investigation, I have logged an issue in our issue tracking system as PDFNEWNET-39121 and also linked your request to it. We will keep you updated via this thread regarding the issue status.

Please feel free to contact us for any further assistance.

Best Regards,

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan

@PITEDUNCAN

We would like to share with you that Acrobat does not support vertical alignment (although horizontal alignment is supported). However, we have now implemented TextVericalAlignment property which allows to specify vertical alignment for multiline text fields.

Set Vertical Alignment for Multiline TextBox

Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();
pdfDocument.Pages.Add();
// Create a field
TextBoxField textBoxField = new TextBoxField(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(100, 200, 400, 400));
textBoxField.PartialName = "textbox1";
textBoxField.Value = "Text Box Line 1" + Environment.NewLine + "Line 2";
// TextBoxField.Border = new Border(
Border border = new Border(textBoxField);
border.Width = 5;
border.Dash = new Dash(1, 1);
textBoxField.Border = border;
textBoxField.Color = Color.Black;
textBoxField.Characteristics.Border = System.Drawing.Color.Black;
textBoxField.Multiline = true;
textBoxField.TextVerticalAlignment = VerticalAlignment.Center;
// Add field to the document
pdfDocument.Form.Add(textBoxField, 1); 

Please note that this will work only when form is filled via Aspose.PDF for .NET, if contents is updated by other way (not Aspose) vertical alignment will not applied.

Asad are you confirming that user modified fields reset the TextVerticalAlignment? Have there been any updates to set this?

@NestedRAID

As we mentioned in our previous message that there is no Vertical Alignment supported by Adobe Reader. However, we have offered a property to set one only for multi-line text boxes. As far as the earlier logged ticket is concerned, it is still pending for resolution.

We introduced this property to set the alignment at the time of PDF generation. In case some issue is occurring at your side with existing PDF documents, we need to investigate the scenario. Please share a sample PDF document where the field is resetting its alignment after modification. We will further proceed accordingly.

Please escalate this ticket. My account is attached to paid support. I have included pdfs with prefilled info at compile time. You can then click inside one of those textboxes and notice the jump between where it was to where the text goes to after the field is altered.

In the version 2 document in “By the Committe on:” and “Chair” text boxes on the far left we have attempted to mitigate this using center and reducing the text box size but are unable to make them smaller due to text flow indicators not being wanted.

BillJacket346 (27).pdf (1.0 MB)

ByTheComm_Chair_CenterVerticalAlignment_v2.pdf (961.9 KB)

@NestedRAID

We were able to observe the text shifting inside field upon clicking it. However, could you please share a sample code snippet for creating only one text box like in your shared PDF document. We need to test the scenario using same properties and options that you have used to create the text box.

Furthermore, you need to post your issue in paid support forum in order to get it escalated accordingly. You can log in there using same email address which was used for subscription.

I have posted a link to this ticket with the requested code to paid support.

@NestedRAID

You may already have informed about the ticket logged for your case under paid support. You will surely be kept posted about the investigation progress there.

The issues you have found earlier (filed as PDFNET-39121) have been fixed in Aspose.PDF for .NET 20.12.