【发布时间】:2015-09-24 16:51:39
【问题描述】:
我正在根据在我的 datagridview 中选择的记录生成 PDF 文件。它将由 3-5 页组成。我创建了一个包含 2 列的表来表示我的标题。第一个单元格左对齐,第二个单元格右对齐。我希望在所有页面上都显示相同的信息。
做了一些谷歌搜索后,我看到了一个 header.WriteSelectedRows() 属性,它应该有助于解决这个问题?一个例子是:
header.WriteSelectedRows(0, -1, doc.PageSize.GetLeft(5), doc.PageSize.GetTop(5), wri.DirectContent);
第二个是:
header.WriteSelectedRows(0, -1, doc.LeftMargin, doc.PageSize.Height - 36, wri.DirectContent);
但是,两者都导致只有第一页有表格/标题。关于我需要解决的问题有什么想法吗?谢谢!
代码:
PdfPTable header = new PdfPTable(2);
header.HorizontalAlignment = Element.ALIGN_LEFT;
header.TotalWidth = doc.PageSize.Width - 20f;
header.LockedWidth = true;
Phrase cell1 = new Phrase(signal.ProformaType);
Phrase cell2 = new Phrase("text" + Environment.NewLine + "text"
+ Environment.NewLine + signal.Signal);
PdfPCell c1 = new PdfPCell(cell1);
c1.Border = iTextSharp.text.Rectangle.NO_BORDER;
c1.VerticalAlignment = iTextSharp.text.Element.ALIGN_TOP;
c1.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
header.AddCell(c1);
PdfPCell c2 = new PdfPCell(cell2);
c2.Border = iTextSharp.text.Rectangle.NO_BORDER;
c2.VerticalAlignment = iTextSharp.text.Element.ALIGN_TOP;
c2.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
header.AddCell(c2);
header.WriteSelectedRows(0, -1, doc.LeftMargin, doc.PageSize.Height - 36, wri.DirectContent);
【问题讨论】:
标签: c# pdf itextsharp