VintaSoft PDF .NET Plug-in Discussions
Questions, comments and suggestions concerning VintaSoft PDF .NET Plug-in.
Board index < VintaSoft Imaging < VintaSoft PDF .NET Plug-in Discussions
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);
If the page has a rotation the annotation is rotated with the page. I don't want this.//....
RotateAnnotation(annotation, page.Rotate);
page.Annotations.Add(annotation);
//....
private void RotateAnnotation(Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotation annotation, int pageAngle)
{
if (pageAngle != 0)
{
Vintasoft.Imaging.Pdf.Tree.PdfFormXObjectResource appearance = annotation.GetNormalAppearance(true);
System.Drawing.RectangleF sourceRect = annotation.Rectangle;
if (pageAngle == 90 || pageAngle == 270)
{
annotation.Rectangle = new System.Drawing.RectangleF(annotation.Rectangle.X, annotation.Rectangle.Y, annotation.Rectangle.Height, annotation.Rectangle.Width);
}
Vintasoft.Imaging.Pdf.Tree.PdfFormXObjectResource newAppearance = new Vintasoft.Imaging.Pdf.Tree.PdfFormXObjectResource(annotation.Document, new RectangleF(0, 0, annotation.Rectangle.Width, annotation.Rectangle.Height));
using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics g = Vintasoft.Imaging.Pdf.Drawing.PdfGraphics.FromForm(newAppearance))
{
Vintasoft.Imaging.AffineMatrix matrix = null;
switch (pageAngle)
{
case 90:
matrix = new Vintasoft.Imaging.AffineMatrix(0, 1, -1, 0, sourceRect.Height, 0);
break;
case 180:
matrix = new Vintasoft.Imaging.AffineMatrix(-1, 0, 0, -1, sourceRect.Width, sourceRect.Height);
break;
case 270:
matrix = new Vintasoft.Imaging.AffineMatrix(0, -1, 1, 0, 0, sourceRect.Width);
break;
}
g.MultiplyTransform(matrix);
g.DrawForm(appearance);
}
annotation.Appearances.Normal = newAppearance;
}
}
Best regards, Alexander