zoukankan      html  css  js  c++  java
  • iTextSharp pdf demo 学习总结

    PDF

    using iTextSharp.text;
    using iTextSharp.text.pdf;

    Document document = new Document();
    PdfWriter writer = null;
    int titleSize = 13;
    int contentSize = 8;
    Font font= new Font(baseFont, contentSize);

    //添加字体,支持pdf中文显示:
    BaseFont baseFont = BaseFont.CreateFont(@"C:WindowsFontssimsun.ttc,0", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

    PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(string.Format("{0}-{1}.pdf", DateTime.Now.Second, DateTime.Now.Millisecond),
    FileMode.Create));


    document.Open();

    PdfPTable table = new PdfPTable(5); //初始化5列表
    table.WidthPercentage = 94f; //表格宽度:1-100f
    table.SpacingBefore = 5f;
    table.HorizontalAlignment = Element.ALIGN_CENTER;
    table.SplitRows = true;

    PdfPCell cell;
    Paragraph p;

    //
    p = new Paragraph(" " + LaoshiPingyuValue, new Font(baseFont, contentSize));
    cell = new PdfPCell(p);
    cell.Border = Rectangle.NO_BORDER;
    cell.HorizontalAlignment = Element.ALIGN_LEFT;
    cell.Colspan = 5; //次cell跨5列
    cell.FixedHeight = 45f; //设置多行数据快的高度
    cell.SetLeading(4, 1); //设置多行数据的行间距
    table.AddCell(cell);
    return table;


    //加载本地图片到pdf上
    string imagePath = "../../Data/header.png";

    private PdfPTable GetTableHeader(string imagePath)
    {
    PdfPTable table = new PdfPTable(1);
    table.WidthPercentage = 100f;
    table.SplitRows = true;
    table.HeaderRows = 0;
    PdfPCell cell;

    //add 图片
    Image image = Image.GetInstance(imagePath);
    cell = new PdfPCell(image, true);
    table.AddCell(cell);

    return table;
    }

    document.Add(GetTableContent(content_zongji, titleSize, contentSize));

    document.Close();
    writer.Close();

  • 相关阅读:
    Linux 目录结构
    date命令--修改linux系统时间
    uniq linux下去除重复行命令
    Linux查看程序端口占用情况
    openfire连接登陆优化方案
    hdu 4848 搜索+剪枝 2014西安邀请赛
    经常使用ARM汇编指令
    一维DFT
    C++ lambda 表达式传递的变量默认不可变
    wm命令用法及LCD显示图标大小不正常时解决的方法
  • 原文地址:https://www.cnblogs.com/csj007523/p/13453588.html
Copyright © 2011-2022 走看看