zoukankan      html  css  js  c++  java
  • C# 将数据写入PDF文档

    首先添加引用:

    using iTextSharp.text.pdf;
    using iTextSharp.text;
             //列,虚拟一个Table用来测试
             DataTable dt = new DataTable();
                for (int i = 0; i < 5; i++)
                {
                    dt.Columns.Add();
                }
                //
                for (int i = 0; i < 20; i++)
                {
                    dt.Rows.Add(0, 1, 2, 3, 4);
                }
    
    
                this.dataGridView1.DataSource = dt;
     BaseFont bf = BaseFont.CreateFont("C:/WINDOWS/Fonts/SIMYOU.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Document document
                    = new iTextSharp.text.Document();
    
                //通过IO来操作,以创建的方式保存在应用程序根目录。
                iTextSharp.text.pdf.PdfWriter.GetInstance(document,
                        new System.IO.FileStream("Demo123.pdf", System.IO.FileMode.Create)
                    );
                document.Open();
    
                //载入字体,这里调用了PC本地的字体
                iTextSharp.text.Font font = new iTextSharp.text.Font(bf);
    
                document.Add(new Paragraph("Col1" + " " + "Col2" + "" + "Col3" + " " + "Col4" + " " + "Col5", font));
                for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                    document.Add(new Paragraph(dataGridView1.Rows[i].Cells[0].Value.ToString() + " " + dataGridView1.Rows[i].Cells[1].Value.ToString()
                        + " " + dataGridView1.Rows[i].Cells[2].Value.ToString() + " " + dataGridView1.Rows[i].Cells[3].Value.ToString()
                        + " " + dataGridView1.Rows[i].Cells[4].Value.ToString(), font));
                }
    
                document.Close();
查看全文
  • 相关阅读:
    Notepad++编写Markdown
    解决Unable to create new native thread
    Outlook2016 新装进阶操作指南
    卷积神经网络
    反向传播算法
    神经网络的基本组成
    cs231n课程索引
    快速入门特征工程
    快速入门Sklearn
    快速入门Matplotlib
  • 原文地址:https://www.cnblogs.com/allen0118/p/3011790.html
  • Copyright © 2011-2022 走看看