As a follow up to this post I have done some more digging and the issue only seems to appear when Drawing Strings to the PDF. For example, I currently have this function which I use to Draw the Text directly onto the PDF:
Code:
internal void DrawToPDF(PdfRectangle rect, PdfPage elementPage, XFont font, XParagraphAlignment alignment)
{
if (!rect.IsEmpty)
{
using (var gfx = XGraphics.FromPdfPage(elementPage))
{
// Note: Page origin [0,0] is bottom left !
var text = Text;
XTextFormatter tf = new XTextFormatter(gfx);
if (text.Length > 0)
{
var xRect = new XRect(rect.X1, elementPage.Height.Point - rect.Y2, rect.Width, rect.Height);
if ((Flags & PdfAcroFieldFlags.Comb) != 0 && MaxLength > 0)
{
gfx.Save();
gfx.IntersectClip(xRect);
tf.Alignment = alignment;
tf.DrawString(text, font, new XSolidBrush(ForeColor), xRect + new XPoint(0, 1.5), XStringFormats.TopLeft);
gfx.Restore();
}
else
{
gfx.Save();
gfx.IntersectClip(xRect);;
tf.Alignment = alignment;
tf.DrawString(text, font, new XSolidBrush(ForeColor), xRect + new XPoint(2, 2), XStringFormats.TopLeft);
gfx.Restore();
}
}
}
}
}
If I run this code as it currently stands, the resulting PDF looks like this:
Note: This also happens with gfx.DrawString() instead of tf.DrawString().
However if I replace the code
Code:
tf.Alignment = alignment;
tf.DrawString(text, font, new XSolidBrush(ForeColor), xRect + new XPoint(2, 2), XStringFormats.TopLeft);
With code to draw rectangles at the same rectangle location
Code:
gfx.DrawRectangle(new XSolidBrush(XColor.FromArgb(255, 255, 0, 0)), xRect);
Then it produces a PDF that looks like this
I also attempted to write a function which would flip the Height and Width of the PdfRectangles that are used to draw the text on the PDF, which "worked" in the sense it fixed the height and width variables, but it did not affect how the Text was drawn onto the PDF.
Does anyone have any ideas?
Quick Edit:
It is as if the DrawString() function simply looks at the Rotation of the PDF (in this case 90 degrees) and Draws it as if it was a Portrait PDF that was rotated 90 degrees, instead of an actual Landscape PDF which should Draw objects as if they were at 0 degrees. Can anyone point me in the right direction?