如何使标题跳过第一页

时间:2019-06-27 09:55:43

标签: c# pdf itext

我只希望打印的标题跳过我的PDF文档的第一页,现在它正在我的所有页面上打印。我缺少什么,或者需要更改我的代码。

我认为使代码完成我想要的工作的方式可能是在OnEndPage()OnCloseDocument()

public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document)
{
    var titleFont = FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.BOLD, BaseColor.BLACK);

    base.OnEndPage(writer, document);

    PdfPTable table = new PdfPTable(9);
    table.SetWidths(new float[] { 6, 8, 10, 15, 8, 6, 10, 10, 8 });
    table.TotalWidth = document.PageSize.Width - 78;
    table.WidthPercentage = 93;

    PdfPCell cell = new PdfPCell(new Phrase("Ticket #", titleFont)); cell.BorderColor = BaseColor.BLACK; cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.Padding = 5; table.AddCell(cell);
    cell = new PdfPCell(new Phrase("Technician", titleFont)); cell.BorderColor = BaseColor.BLACK; cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.Padding = 5; table.AddCell(cell);
    cell = new PdfPCell(new Phrase("Address", titleFont)); cell.BorderColor = BaseColor.BLACK; cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.Padding = 5; table.AddCell(cell);
    cell = new PdfPCell(new Phrase("Descripton", titleFont)); cell.BorderColor = BaseColor.BLACK; cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.Padding = 5; table.AddCell(cell);
    cell = new PdfPCell(new Phrase("Severity", titleFont)); cell.BorderColor = BaseColor.BLACK; cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.Padding = 5; table.AddCell(cell);
    cell = new PdfPCell(new Phrase("Status", titleFont)); cell.BorderColor = BaseColor.BLACK; cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.Padding = 5; table.AddCell(cell);
    cell = new PdfPCell(new Phrase("Date Logged", titleFont)); cell.BorderColor = BaseColor.BLACK; cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.Padding = 5; table.AddCell(cell);
    cell = new PdfPCell(new Phrase("Date Resolved", titleFont)); cell.BorderColor = BaseColor.BLACK; cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.Padding = 2; table.AddCell(cell);
    cell = new PdfPCell(new Phrase(" ", titleFont)); cell.BorderColor = BaseColor.BLACK; cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.Padding = 2; table.AddCell(cell);

    table.WriteSelectedRows(0, -1, 39, document.PageSize.Height - 15, writer.DirectContent);
}

public override void OnCloseDocument(PdfWriter writer, iTextSharp.text.Document document)
{
    base.OnCloseDocument(writer, document);

    headerTemplate.BeginText();
    headerTemplate.SetFontAndSize(bf, 12);
    headerTemplate.SetTextMatrix(0, 0);
    headerTemplate.ShowText((writer.PageNumber - 1).ToString());
    headerTemplate.EndText();
}

0 个答案:

没有答案