Thu Dec 20, 2018 2:29 am
Hi Jane
We have coordinates of PDF form fields in the database as such (as mentioned there may be hundreds for a single page, the below is just an example of a single field)
FieldName = CertificateNo
FontSize = 10
FontName = Helvetica
PositionX = 611.00
PositionY = 534.00
SizeHeight = 21.00
SizeWidth = 115.00
PositionUnit = Point
PageNumber = 1
(The above field position is in the top right(ish) corner)
Speed (or lack of) was a major issue using FormFields, we have therefore moved to using Canvas.DrawString
Using any existing PDF that has an orientation of landscape, where field below is just an object holding the above position values)
var font = new PdfTrueTypeFont(new System.Drawing.Font(field.FontName, float.Parse(field.FontSize), FontStyle.Regular));
PdfPageBase page = pdfDocument.Pages[field.PageNumber - 1];
Doing this positions the text correctly
PointF pointF = new PointF((float)field.PositionX, page.ActualSize.Height - (float)field.PositionY - (float)field.SizeHeight);
page.Canvas.DrawString(text ?? "", font, new PdfSolidBrush(Color.Black), pointF);
Doing this (ignoring the subtle offset by the field.SizeHeight difference) does not place the text on the form
page.Canvas.TranslateTransform(0, page.ActualSize.Height);
PointF pointF = new PointF((float)field.PositionX, (float)field.PositionY);
page.Canvas.DrawString(text ?? "", font, new PdfSolidBrush(Color.Black), pointF);
Regards
Paul