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();
            }
        }
    }
  • 相关阅读:
    MySQL存储过程中的3种循环【转载】
    单元样选择按钮
    JavaScript(jQuery)实现打印英文格式日期
    哈希算法
    Hello,Expression Blend 4 (含Demo教程和源码)
    Cocos2Dx for XNA类解析(2): CCDirector(上)
    github for Windows使用介绍
    Hello,Behavior
    Vue component+vuedraggable拖拽动态表单
    Vue Component
  • 原文地址:https://www.cnblogs.com/joiy/p/7384829.html
Copyright © 2011-2022 走看看