主要内容在页脚部分PDF文档iTextSharp上重叠 [英] Main content is overlapping on footer section PDF document iTextSharp
本文介绍了主要内容在页脚部分PDF文档iTextSharp上重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用itextsharp来创建文档。我在文档中创建了一个页脚部分,但页脚顶部的内容重叠。
我该如何解决这个问题?
我想在每页上添加页码我该怎么办?这样做吗?
请检查此链接
i am using itextsharp for creating document. I have created a footer section in document but content that over the top of footer is overlapping.
How can i fix this?
I want to add page number on each page how can i do this?
Please check this link
public class PdfNote
{
public int Create(int id, string path)
{
try
{
var file = path;
if (System.IO.File.Exists(file))
System.IO.File.Delete(file);
Document document = new Document(PageSize.A4, 10, 10, 10, 10);
var writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream(file, FileMode.Create));
document.Open();
writer.PageEvent = new Footer();
// main content
document.Close();
return 1;
}
catch (Exception ex)
{
throw ex;
}
}
public partial class Footer : PdfPageEventHelper
{
public override void OnEndPage(PdfWriter writer, Document doc)
{
PdfPTable fTbl = new PdfPTable(1);
fTbl.TotalWidth = 550;
fTbl.DefaultCell.Border = 0;
PdfPTable line = new PdfPTable(1);
line.DefaultCell.Border = 0;
line.DefaultCell.BorderWidthBottom = 0.2f;
line.DefaultCell.Padding = 5;
line.AddCell("");
fTbl.AddCell(line);
PdfPTable footerTbl = new PdfPTable(3);
footerTbl.TotalWidth = 550;
footerTbl.DefaultCell.Column.Alignment = 1;
footerTbl.HorizontalAlignment = Element.ALIGN_CENTER;
footerTbl.DefaultCell.Border = 0;
footerTbl.AddCell("Print Name:");
footerTbl.AddCell("Signature:");
footerTbl.AddCell("Date:");
PdfPCell cell = new PdfPCell();
cell.Padding = 20;
cell.Border = 0;
cell.BorderWidthBottom = 1;
footerTbl.AddCell(cell);
footerTbl.AddCell(cell);
footerTbl.AddCell(cell);
fTbl.AddCell(footerTbl);
fTbl.AddCell(line);
fTbl.WriteSelectedRows(0, -1, 15, 110, writer.DirectContent);
//footerTbl.WriteSelectedRows(0, -1, 15, 60, writer.DirectContent);
}
}
}
推荐答案
I增加了文档的底部边距,所以现在页脚和内容不会相互重叠。
文档文档=新文档(PageSize.A4,10,10, 10,80);
I have increased the bottom margin of document so now footer and content are not going to overlap each other.
Document document = new Document(PageSize.A4, 10, 10, 10, 80);
这篇关于主要内容在页脚部分PDF文档iTextSharp上重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文