iTextSharp V5.0.2。这段代码在 95% 的时间里都能完美运行。但是客户端加载的一些横向 pdf 文件向下和向左移动。我可以在 Rectangle 属性 .Left 和 .Bottom 中看到数量,但我不知道如何解决这个问题。这是在每一页的顶部添加一个标题。
对于所有内容都关闭的页面,我想将内容向上和向上移动到左侧和顶部,以便标题与页面顶部齐平
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;
}
这就是不良文件的外观。即使我将 x 和 y 设置为正确的值,文档的 x 和 y 也是关闭的。