I am currently trying to add a PdfFreeTextAnnotation to a page independent of the page rotation.
Everything is working fine if the page has no rotation. This is my code:
Code: Select all
Vintasoft.Imaging.Pdf.Tree.Annotations.PdfFreeTextAnnotation annotation = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfFreeTextAnnotation(page);
annotation.Color = System.Drawing.Color.Transparent;
annotation.IsReadOnly = true;
annotation.IsReadOnly = true;
annotation.Contents = "Text Content";
annotation.TextQuadding = Vintasoft.Imaging.Pdf.Tree.InteractiveForms.TextQuaddingType.Centered;
annotation.Font = page.Document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.Helvetica);
annotation.TextColor = System.Drawing.Color.Red;
annotation.FontSize = 12;
Vintasoft.Imaging.Pdf.Drawing.PdfGraphics pdfGraphics = page.GetGraphics();
float width;
float height;
pdfGraphics.MeasureString(annotation.Contents,
annotation.Font,
annotation.FontSize,
500,
false,
out width,
out height);
width = width + width * 0.1f + annotation.BorderWidth * 2 + annotation.TextPadding.Horizontal;
height = height + height * 0.1f + annotation.BorderWidth * 2 + annotation.TextPadding.Vertical;
SizeF sizeF = new SizeF(width, height);
PointF location = new PointF((page.CropBox.Width - sizeF.Width) / 2, page.CropBox.Height - 25);
annotation.Rectangle = new RectangleF(page.MediaBox.X + location.X,
page.MediaBox.Y + location.Y,
sizeF.Width,
sizeF.Height);
page.Annotations.Add(annotation);
Changing the location of the annotation if the page is rotated is easy but I can't figure out how to rotate the annotation itself so it stays horizontally.
Thanks!
Matt