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();

  • 相关阅读:
    HolidayFileDisPersonViewList.js中的一些基础
    保存会话数据的两种技术,Cookie,Session
    web服务器调用Servlet的过程
    XML基础
    HttpServletRequest,HttpServletResponse
    金蝶handler中 collection 代码片段理解
    Rancher 容器云平台搭建
    Docker的安装及镜像加速配置
    MYSQL 合并行
    Spring Ioc 容器核心概览
  • 原文地址:https://www.cnblogs.com/csj007523/p/13453588.html
Copyright © 2011-2022 走看看