我将iTextSharp用于ASP.NET中的项目。 到目前为止,我已经生成了我想要的内容。
问题 1.我希望HEADER仅显示在PDF的第一页上。但是,标题内容会出现在每个生成的新页面上。
代码:
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, memoryStream);
Phrase phrase = null;
PdfPCell cell = null;
Color color = null;
pdfDoc.Open();
int columns = grdGridPrint.Columns.Count;
// Table and PdfTable classes removed in version 5.XXX
PdfPTable table = new PdfPTable(columns);
// table.TotalWidth = 500f;
// Draw first-page-only header
//ColumnText ct = new ColumnText(writer.DirectContent);
//XMLWorkerHelper.GetInstance().ParseXHtml(new ColumnTextElementHandler(ct), new StringReader(html));
//ct.SetSimpleColumn(document.Left, document.Top, document.Right, document.GetTop(-PDFMarginTop), 0, Element.ALIGN_MIDDLE);
//ct.Go();
phrase = new Phrase();
phrase.Add(new Chunk("Elam Fataka\u00AE \n", FontFactory.GetFont("Arial", 15, Font.BOLD, Color.BLACK)));
phrase.Add(new Chunk("Mahakali Complex, Tarsa Road,Kanhan \n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
phrase.Add(new Chunk("Proprietor : Liladhar Barve, ", FontFactory.GetFont("Arial", 10, Font.BOLD, Color.BLACK)));
phrase.Add(new Chunk("(M) 9326560090 | (O) 07102-236297 \n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)));
phrase.Add(new Chunk("\n\n", FontFactory.GetFont("Arial", 7, Font.NORMAL, Color.BLACK)));
phrase.Add(new Chunk("All Agent List - Total Agent :" + grdGridPrint.Rows.Count.ToString() + "\n", FontFactory.GetFont("Arial", 15, Font.NORMAL, Color.BLACK)));
phrase.Add(new Chunk("Printing Date : " + DateTime.Today.ToString("dd/MM/yyyy") + "\n", FontFactory.GetFont("Arial", 10, Font.NORMAL, Color.BLACK)));
phrase.Add(new Chunk("\n\n", FontFactory.GetFont("Arial", 7, Font.NORMAL, Color.BLACK)));
cell = ClsPDF.PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.VerticalAlignment = PdfCell.CHUNK;
答案 0 :(得分:4)
只需在第一页上创建一个段落。
pdfDoc.Add(new Paragraph("This Is My Header"));
您的行会根据需要自动溢出到下一页。