PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Vertical text alignment in AcroFields
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1266
Page 1 of 1

Author:  wilson77 [ Sat Jul 17, 2010 7:05 am ]
Post subject:  Vertical text alignment in AcroFields

Hi there,

Hope someone can help with this issue, I have a PDF with AcroFields (mostly text fields) which I am populating using PDFSharp.

When I click on the AcroFields in Adobe Acrobat and type, the text is vertically centered in the text field.

However, when I insert text into the field using code:

((PdfSharp.Pdf.AcroForms.PdfTextField)pdfTemplateDocument.AcroForm.Fields["FIRST_NAME"]).Text = "John";

... the text defaults to top left corner of the text box.

I want the text to be vertically centered but I cannot find a setting that controls this.

Strangely, if I open the new PDF I create in Acrobat (with all the text values aligned top left of each AcroField) and click on each one, they align back to the center.

If I tab out, they return back to the left corner but if I type an additional character into the textbox it will stay vertically centered.

Anyone seen anything like this or have any tips to resolve?

Thanks,
Wilson.

Author:  wilson77 [ Sun Jul 18, 2010 1:06 am ]
Post subject:  Re: Vertical text alignment in AcroFields

For anyone looking for a resolution to this issue, I downloaded the source code and modified it to suit my requirements.

There are various XStringFormats, one of which is TopLeft, which was used in the rendering method for the PDFTextField class.

I added my own XStringFormat - CenterLeft - and changed the rendering method in the PDFTextClass to use that instead.

Rebuilt the DLL, included it into my project, problem solved.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/