【发布时间】:2014-01-08 12:37:34
【问题描述】:
我正在使用 itextsharp 创建文档。我在文档中创建了一个页脚部分,但页脚顶部的内容重叠。
我该如何解决这个问题?
我想在每个页面上添加页码,我该怎么做?
请检查此链接 Pdf document Image
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);
}
}
}
【问题讨论】:
标签: c# pdf-generation itextsharp