zoukankan      html  css  js  c++  java
  • iTextSharp操作表格排版问题

    using iTextSharp.text;
    using iTextSharp.text.pdf;
    using System.IO;
    
    namespace testPdf
    {
        class Program
        {
            static void Main(string[] args)
            {
                BaseFont BF_Light = BaseFont.CreateFont(@"C:WindowsFontssimsun.ttc,0", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                Document doc = new Document();
    
                PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(string.Format("Demo.pdf"),FileMode.Create));
                doc.Open(); 
                Paragraph p = new Paragraph("标题
    
    ",new Font(BF_Light,18));
                p.Alignment = 1;//居中
                doc.Add(p);
    
                p = new Paragraph("第一个单元格", new Font(BF_Light,12));//测试再次调用P
    
                PdfPCell cell = new PdfPCell(p);
                cell.HorizontalAlignment = 1;//设置单元格内居中
                //cell.VerticalAlignment = 1;
                int[] widths = { 5, 10 };
                PdfPTable dt1 = new PdfPTable(2);
                dt1.SetWidths(widths);//设置每列的宽度(求和百分比5,10=1,2)
                cell.Rowspan = 2;//设置跨度行数(Colspan设置跨度列数)
                dt1.AddCell(cell);
                dt1.AddCell(new PdfPCell(new Paragraph("第二个单元格", new Font(BF_Light, 12))));
                dt1.AddCell(new PdfPCell(new Paragraph("第三个单元格", new Font(BF_Light, 12))));
                doc.Add(dt1);
    
                PdfPCell cell3 = new PdfPCell(new Paragraph("最后一个", new Font(BF_Light)));
                PdfPTable dt3 = new PdfPTable(2);
                dt3.AddCell(cell3);
                dt3.WidthPercentage = 85;
                PdfPCell cell4 = new PdfPCell(new Paragraph("再加一个", new Font(BF_Light)));
                dt3.AddCell(cell4);
    
                doc.Add(dt3);
                doc.Close();
            }
        }
    }
  • 相关阅读:
    【贪心+DFS】D. Field expansion
    【贪心+博弈】C. Naming Company
    【dp】E. Selling Souvenirs
    【multimap的应用】D. Array Division
    内存变量边界对齐
    3.8 高级检索方式(二)
    3.7 高级检索方式(一)
    openGL加载obj文件+绘制大脑表层+高亮染色
    3.6 Lucene基本检索+关键词高亮+分页
    3.5 实例讲解Lucene索引的结构设计
  • 原文地址:https://www.cnblogs.com/joiy/p/7384829.html
Copyright © 2011-2022 走看看