iTextSharp V5.0.2. This code works perfectly 95% of the time. But some landscape pdfs that clients load come in shifted down and to the left. I can see the amount in the Rectangle properties .Left and .Bottom, but I have no idea how to fix this. This is adding a header to the top of each page.
I would like to shift the content back up and over to the left and top for the pages where everything is off so the header is flush with the top of the page
public string Add(string path)
{
string tempPath = path + "HFtemp";
PdfStamper pdf = new PdfStamper(new PdfReader(path), new FileStream(tempPath, FileMode.Create));
for (Int32 nPage = 1; nPage <= pdf.Reader.NumberOfPages; nPage++)
{
if ((Header))
{
PdfContentByte content = pdf.GetOverContent(nPage);
Rectangle pageRectangle = pdf.Reader.GetPageSizeWithRotation(nPage);
float h = pageRectangle.Height;
float w = pageRectangle.Width;
//float left = pageRectangle.Left; //(-) 13.011
//float bottom = pageRectangle.Bottom; //(+) 13.011
float y = h - Header_Height;
// x, y, w, h
content.Rectangle(0, y, w, Header_Height);
content.SetRGBColorFill(Header_Color.R, Header_Color.G, Header_Color.B);
content.Fill();
content.SaveState();
content.RestoreState();
}
}
pdf.Close();
return tempPath;
}
This is how the bad documents look. Even though I'm setting x and y to the correct values, the document's x and y are off.