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();
            }
        }
    }
  • 相关阅读:
    asp.net 奇淫技巧
    生成缩略图不清晰
    NPOI相关
    Dapper
    Newtonsoft.Json高级用法(转载)
    swfobject2.2
    如何把SQLServer数据库从高版本降级到低版本? (转载)
    Smallpdf 轻松玩转PDF。我们爱它。
    Simple Data
    在HTML中优雅的生成PDF
  • 原文地址:https://www.cnblogs.com/joiy/p/7384829.html
Copyright © 2011-2022 走看看