Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Nov 11, 2025 2:49 am

Hi,

Is there a way to vertically center the text in a PdfFreeTextAnnotation. The border width increase inwards which overlaps with the markup text.

Here it is the code I'm using:

Spire.Pdf.Graphics.PdfFont font = font;
SizeF textSize = font.MeasureString("sample");

RectangleF rect = new RectangleF(x, y, textSize.Width, textSize.Height);
Spire.Pdf.Annotations.PdfFreeTextAnnotation textAnnotation = new Spire.Pdf.Annotations.PdfFreeTextAnnotation(rect);

textAnnotation.Text = "sample";
textAnnotation.Subject = subject;
textAnnotation.Font = font;
textAnnotation.Border = border;
textAnnotation.LineEndingStyle = Spire.Pdf.Annotations.PdfLineEndingStyle.None;
textAnnotation.Size = new SizeF(textSize.Width * 1.5F, textSize.Height * 1.5F);
textAnnotation.TextAlignment = Spire.Pdf.Annotations.PdfAnnotationTextAlignment.Center;



Thanks

eddie.torres
 
Posts: 8
Joined: Thu Oct 16, 2025 6:06 pm

Tue Nov 11, 2025 9:03 am

Hello

Thank you for your inquiry.
In our current version, the setting of "PdfAnnotationTextAlignment.Center" only applies to the horizontal layout. For the requirement of vertical layout, I have already added it into our upgrade list using the number SPIREPDF-7826. Our Dev team will further investigate and implement it. Once its' version is available, we will let you know.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1536
Joined: Wed Apr 25, 2018 3:20 am

Mon Dec 08, 2025 3:09 am

Hello,

Thanks for your patience.
Glad to inform you that our latest version (Spire.PDF Pack(Hotfix) Version:11.12.0) contains the fixes of SPIREPDF-7826. Please test it using the following example code.
Code: Select all
PdfDocument newPdf = new PdfDocument();
PdfPageBase page = newPdf.Pages.Add();
Spire.Pdf.Graphics.PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 10f);
SizeF textSize = font.MeasureString("sample");

RectangleF rect = new RectangleF(50,50, textSize.Width, textSize.Height);
Spire.Pdf.Annotations.PdfFreeTextAnnotation textAnnotation = new Spire.Pdf.Annotations.PdfFreeTextAnnotation(rect);

textAnnotation.Text = "sample";
textAnnotation.Subject = "subject";
textAnnotation.Font = font;
Spire.Pdf.Annotations.PdfAnnotationBorder border = new Spire.Pdf.Annotations.PdfAnnotationBorder(8);
textAnnotation.Border = border;
textAnnotation.LineEndingStyle = Spire.Pdf.Annotations.PdfLineEndingStyle.None;
textAnnotation.Size = new SizeF(textSize.Width * 1.5F, textSize.Height * 1.5F);
//textAnnotation.TextAlignment = Spire.Pdf.Annotations.PdfAnnotationTextAlignment.Center;
textAnnotation.StringFormat.Alignment = PdfTextAlignment.Center;
textAnnotation.StringFormat.LineAlignment = PdfVerticalAlignment.Middle;
page.Annotations.Add(textAnnotation);
newPdf.SaveToFile(result);

https://www.e-iceblue.com/Download/download-pdf-for-net-now.html
https://www.nuget.org/packages/Spire.PDF/11.12.0
https://www.nuget.org/packages/Spire.PDFfor.NETStandard/11.12.0

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1536
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.PDF