标签:nbsp conf element tco write 用法 table pre not
//字体
private static BaseFont bfChinese = BaseFont.CreateFont(@"C:\Windows\Fonts\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); private Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, new BaseColor(0, 0, 0)); private Font fontHeader = new Font(bfChinese, 14, Font.BOLD, new BaseColor(0, 0, 0)); private Font fontTitle = new Font(bfChinese, 18, Font.BOLD, new BaseColor(0, 0, 0));
Document document = new Document(PageSize.A4.Rotate(), 5, 5, 10, 10);//创建纸张为A4,横向的纸张 using (MemoryStream pdfStream = new MemoryStream()) { PdfWriter pdfWriter = PdfWriter.GetInstance(document, pdfStream); document.Open(); Paragraph header = new Paragraph(config.Title, fontTitle); header.Alignment = 1; header.SpacingAfter = 10;//段落后空10行 document.Add(header); Paragraph table = new Paragraph(); document.Add(SetPdfTable(config, type, list)); document.Close(); pdfWriter.Close(); return pdfStream.ToArray(); }
private PdfPTable SetPdfTable() { int columCount=5 PdfPTable table = new PdfPTable(5); float[] columnsWidth = new float[5]; PdfPCell cell; while (index < 18) { cell = new PdfPCell(new Phrase(index.ToString(), fontChinese)); index = index + 1; SetAlign(cell); table.AddCell(cell); cell = new PdfPCell(new Phrase(string.Empty)); for (int i = 0; i < columCount; i++) { table.AddCell(cell); } listCount = listCount + 1; } cell = new PdfPCell(new Paragraph("调查人:", fontChinese)); cell.Colspan = columCount + 1; cell.Border = 0; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.PaddingRight = 80; cell.PaddingTop = 10; table.AddCell(cell); table.SetTotalWidth(columnsWidth); return table; } private void SetAlign(PdfPCell cell) { cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.Padding = 4.0f; }
标签:nbsp conf element tco write 用法 table pre not
原文地址:http://www.cnblogs.com/tangchun/p/7724757.html