我正在使用pdf,我首先将它们合并,然后为合并的pdf的每个页面创建一个标题和页脚。我正在使用一种方法进行合并,使用另一种方法来设置页眉和页脚。
对于某些文档,页眉和页脚与内容重叠。我试图为文档设置保证金,但它不会改变任何内容。
public byte[] HeaderAndFooter(byte[] inputPdf)
{
var dest = new MemoryStream();
PdfDocument pdfDoc = new PdfDocument(new PdfReader(inputPdf.ToMemoryStream()),
new PdfWriter(dest));
Document doc = new Document(pdfDoc);
doc.SetMargins(200,200, 200, 200); /* It doesn't matter the
numbers I set in here the document remains the same...*/
numberOfPages = pdfDoc.GetNumberOfPages();
Paragraph header = new Paragraph("This is a header for every page...")
.SetFont(PdfFontFactory.CreateFont(FontConstants.HELVETICA))
.SetFontSize(10)
.SetFontColor(Color.BLACK);
for (int i = 1; i <= numberOfPages; i++)
{
var pageSize = pdfDoc.GetPage(i).GetPageSize();
float LeftMargin = 36;
float BottomMargin = 24;
float y = pageSize.GetTop() - 72;
float center = pageSize.GetWidth() / 2;
doc.ShowTextAligned(header, LeftMargin, y, i, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0);
doc.ShowTextAligned(footerL, LeftMargin, BottomMargin, i, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0);
doc.ShowTextAligned(footerC, center, BottomMargin, i, TextAlignment.CENTER, VerticalAlignment.BOTTOM, 0);
}
doc.Close();
return dest.ToArray();
}
如何避免页眉和页脚与内容重叠?