zoukankan      html  css  js  c++  java
  • iTextSharp导出PDF模板(报告)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using iTextSharp;
    using iTextSharp.text;
    using iTextSharp.text.pdf;

    namespace WpfApp
    {
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
    public MainWindow()
    {
    InitializeComponent();
    }
    /// <summary>
    /// 导出成绩
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void Button_Click(object sender, RoutedEventArgs e)
    {
    //创建文档
    Document docPDF = new Document(PageSize.A4,0,0,0,0);
    PdfWriter write = PdfWriter.GetInstance(docPDF,new FileStream(@"E:"+DateTime.Now.ToString("yyyyMMddhhmmss")+"pdfFile.pdf",FileMode.OpenOrCreate,FileAccess.Write));
    BaseFont baseFont = BaseFont.CreateFont(@"C:WindowsFontssimsun.ttc,0",BaseFont.IDENTITY_H,BaseFont.EMBEDDED);
    Font font = new Font(baseFont);
    docPDF.Open();
    docPDF.Add(new iTextSharp.text.Paragraph("第一个PDF文件",font));//将一句话写入PDF
    iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph();

    PdfPTable tablerow1 = new PdfPTable(new float[] { 20, 20, 20 });
    //PdfPCell cell1 = new PdfPCell(new iTextSharp.text.Paragraph("单元格测试",font));
    //for (int i = 0; i <= 27; i++)//表示创建一个3列9行的表格
    //{
    // cell1 = new PdfPCell(new iTextSharp.text.Paragraph(i.ToString(), font));

    // // tablerow1.AddCell(
    // tablerow1.AddCell(cell1);//将单元格添加到表格中

    //}
    //docPDF.NewPage();//新的一页显示
    PdfPTable tablerow2 = new PdfPTable(new float[] { 20, 20, 20 });
    PdfPCell cell2 = new PdfPCell(new iTextSharp.text.Paragraph("单元格测试", font));
    cell2 = new PdfPCell(new iTextSharp.text.Paragraph("表格跨行 row1 col1", font));
    cell2.MinimumHeight = 40F;//设置表格的高度
    cell2.Rowspan = 2;//单元格夸2行
    tablerow2.AddCell(cell2);
    cell2 = new PdfPCell(new iTextSharp.text.Paragraph("表格跨行row1 col2", font));
    cell2.MinimumHeight = 40F;//设置表格的高度
    tablerow2.AddCell(cell2);
    cell2 = new PdfPCell(new iTextSharp.text.Paragraph("表格跨行row1 col3", font));
    cell2.MinimumHeight = 40F;//设置表格的高度
    tablerow2.AddCell(cell2);
    cell2 = new PdfPCell(new iTextSharp.text.Paragraph("表格跨行row2 col3", font));
    cell2.MinimumHeight = 40F;//设置表格的高度
    tablerow2.AddCell(cell2);
    cell2 = new PdfPCell(new iTextSharp.text.Paragraph("表格跨行row2 col3", font));
    cell2.MinimumHeight = 40F;//设置表格的高度
    tablerow2.AddCell(cell2);
    docPDF.Add(tablerow2);
    docPDF.Add(tablerow1);//将表格添加到pdf文档中
    docPDF.Close();

    }
    }
    }

  • 相关阅读:
    多项式全家桶——Part.3 多项式求逆、除法、开根号
    多项式全家桶——Part.2 多项式位运算
    多项式全家桶——Part.1 多项式加减乘
    CSP2019总结
    jzoj6384. 【NOIP2019模拟2019.10.23】珂学家
    jzoj6377. 【NOIP2019模拟2019.10.05】幽曲[埋骨于弘川]
    jzoj6374. 【NOIP2019模拟2019.10.04】结界[生与死的境界]
    jzoj6370. 【NOIP2019模拟2019.9.28】基础 fake 练习题
    一个初学者的辛酸路程-基于Django写BBS项目
    一个初学者的辛酸路程-依旧Django
  • 原文地址:https://www.cnblogs.com/yuwentao/p/13745892.html
Copyright © 2011-2022 走看看