• 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();
            }
        }
    }
  • 相关阅读:
    Django ajax 实现 loading 效果
    K8S service 简单介绍
    K8S Pod 生命周期 (二)
    异度之刃 Xenoblade 后感
    Nested Prefab Mode 嵌套预制体 保存问题 Dirty
    GIT速成
    Surface电池阈值
    如何删除通知栏无效图标(重置任务栏通知区域)
    Mouse For Winpad
    Re:LieF ~親愛なるあなたへ~ 后感
  • 原文地址:https://www.cnblogs.com/joiy/p/7384829.html
Copyright © 2020-2023  润新知