我在OnEndPage中添加了表锥页面标题的创建。在表I中,没有打印的RowSpan,其余的是。
> Tasks: Terminate Running Task
如果我删除RowSpan打印件!
答案 0 :(得分:0)
这是我使用的代码:
public override void OnEndPage(PdfWriter writer, Document document)
{
if (document.PageNumber != 1)
{
if (report.repeatHead) //ripete l'intestazione del report su tutte le pagine di stampa
{
repeatHead(writer, document);
}
else
{
if (document.PageNumber == 2) //ripete l'intestazione del report solo sulla second pagina dopo la copertina
{
repeatHead(writer, document);
}
}
}
}
public void repeatHead(PdfWriter writer, Document document)
{
//OnStartPage
base.OnStartPage(writer, document);
Rectangle pageSize = document.PageSize;
PdfPTable table = new PdfPTable(2);
//table.WidthPercentage = 100;
table.TotalWidth = pageSize.Width - 50;
table.DefaultCell.Border = Rectangle.NO_BORDER;
//impostazione larghezza celle
iTextSharp.text.Rectangle rect = PageSize.A4;
float pageWidth = rect.Width;
table.SetWidthPercentage(new float[]
{
(float).70 * pageWidth ,
(float).30 * pageWidth,
}, rect);
//Cella nome banca
table.AddCell(CellTest(report.banca, 1, 2));
//Cella descrizione indagine
table.AddCell(CellTest("Valore1", 0, 0));
//Cella data apertura
table.AddCell(CellTest("Data apertura: " + DateTime.Now, 0, 0));
//Cella descrizione
table.AddCell(CellTest("Descrizione", 0, 0));
//Cella data chiusura
table.AddCell(CellTest("Data chiusura: " + DateTime.Now, 0, 0));
table.WriteSelectedRows(0, -1, pageSize.GetLeft(25), pageSize.GetTop(10), cb);
}
private PdfPCell CellTest(string value, int colSpan, int rowSpan)
{
iTextSharp.text.Font font = FontFactory.GetFont("Arial");
PdfPCell c = new PdfPCell(new Phrase(value, font));
c.BorderWidthLeft = 1f;
c.BorderWidthTop = 1f;
c.BorderWidthRight = 1f;
c.BorderWidthBottom = 1f;
if (rowSpan != 0) { c.Rowspan = rowSpan; }
if (colSpan != 0) { c.Colspan = colSpan; }
return c;
}
public override void OnCloseDocument(PdfWriter writer, Document document)
{
base.OnCloseDocument(writer, document);
template.BeginText();
template.SetFontAndSize(bf, 8);
template.SetTextMatrix(0, 0);
template.ShowText("" + (writer.PageNumber - 1));
template.EndText();
}