C#使用itextsharp生成PDF文件含页脚页眉-程序员宅基地

技术标签: PDF  C#基础  itextsharp  

一、引用itextsharp库文件

下载链接为:https://download.csdn.net/download/xiaochenxihua/11014068

二、编写生成PDF的基础页面框架生成脚本

/***
*	Title:"智慧工厂" 项目
*		主题:PDF基础设置
*	Description:
*		功能:XXX
*	Date:2018
*	Version:1.2版本
*	Author:Coffee
*	Modify Recoder:
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace ITextSharpTest
{
    public class PDFBase : PdfPageEventHelper
    {
        #region 属性
        private String _fontFilePathForHeaderFooter = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "SIMHEI.TTF");
        /// <summary>
        /// 页眉/页脚所用的字体
        /// </summary>
        public String FontFilePathForHeaderFooter
        {
            get
            {
                return _fontFilePathForHeaderFooter;
            }

            set
            {
                _fontFilePathForHeaderFooter = value;
            }
        }

        private String _fontFilePathForBody = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "SIMSUN.TTC,1");

        /// <summary>
        /// 正文内容所用的字体
        /// </summary>
        public String FontFilePathForBody
        {
            get { return _fontFilePathForBody; }
            set { _fontFilePathForBody = value; }
        }


        private PdfPTable _header;
        /// <summary>
        /// 页眉
        /// </summary>
        public PdfPTable Header
        {
            get { return _header; }
            private set { _header = value; }
        }

        private PdfPTable _footer;
        /// <summary>
        /// 页脚
        /// </summary>
        public PdfPTable Footer
        {
            get { return _footer; }
            private set { _footer = value; }
        }


        private BaseFont _baseFontForHeaderFooter;

        /// <summary>
        /// 页眉页脚所用的字体
        /// </summary>
        public BaseFont BaseFontForHeaderFooter
        {
            get { return _baseFontForHeaderFooter; }
            set { _baseFontForHeaderFooter = value; }
        }

        private BaseFont _baseFontForBody;

        /// <summary>
        /// 正文所用的字体
        /// </summary>
        public BaseFont BaseFontForBody
        {
            get { return _baseFontForBody; }
            set { _baseFontForBody = value; }
        }

        private Document _document;

        /// <summary>
        /// PDF的Document
        /// </summary>
        public Document Document
        {
            get { return _document; }
            private set { _document = value; }
        }

        #endregion


        public override void OnOpenDocument(PdfWriter writer, Document document)
        {
            try
            {
                BaseFontForHeaderFooter = BaseFont.CreateFont(FontFilePathForHeaderFooter, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                BaseFontForBody = BaseFont.CreateFont(FontFilePathForBody, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                Document = document;
            }
            catch (DocumentException de)
            {
                throw de;
            }
            catch (System.IO.IOException ioe)
            {
                throw ioe;
            }
        }

        #region 生成页头
        /// <summary>
        /// 生成页眉
        /// </summary>
        /// <param name="writer"></param>
        /// <returns></returns>
        public virtual PdfPTable GenerateHeader(iTextSharp.text.pdf.PdfWriter writer)
        {
            return null;
        }
        #endregion

        #region 生成页脚
        /// <summary>
        /// 生成页脚
        /// </summary>
        /// <param name="writer"></param>
        /// <returns></returns>
        public virtual PdfPTable GenerateFooter(iTextSharp.text.pdf.PdfWriter writer)
        {
            return null;
        }
        #endregion

        public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document)
        {
            base.OnEndPage(writer, document);

            //输出页眉
            Header = GenerateHeader(writer);
            Header.TotalWidth = document.PageSize.Width - 20f;
            ///调用PdfTable的WriteSelectedRows方法。该方法以第一个参数作为开始行写入。
            ///第二个参数-1表示没有结束行,并且包含所写的所有行。
            ///第三个参数和第四个参数是开始写入的坐标x和y.
            Header.WriteSelectedRows(0, -1, 10, document.PageSize.Height - 20, writer.DirectContent);

            //输出页脚
            Footer = GenerateFooter(writer);
            Footer.TotalWidth = document.PageSize.Width - 20f;
            Footer.WriteSelectedRows(0, -1, 10, document.PageSize.GetBottom(50), writer.DirectContent);
        }
    }
}

三、测试生成PDF文件内容脚本

/***
*	Title:"智慧工厂" 项目
*		主题:实现PDF文件的设置_关于交接班信息
*	Description:
*		功能:XXX
*	Date:2019
*	Version:1.2版本
*	Author:Coffee
*	Modify Recoder:
*/

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using iTextSharp.text;
using iTextSharp.text.pdf;
using ITextSharpTest;
using kernal;
using Global;

namespace Control
{
	public class Export_ChangeShifts_PDF : PDFBase
    {
        private static Export_ChangeShifts_PDF _Instance;//本类实例


        /// <summary>
        /// 本类实例
        /// </summary>
        /// <returns></returns>
        public static Export_ChangeShifts_PDF GetInstance()
        {
            if (_Instance==null)
            {
                _Instance = new Export_ChangeShifts_PDF();
            }
            return _Instance;
        }

        #region 属性

        private int _pageRowCount = 26;                                         //每页展示的数据行数
        private int _pageColCount = 4;                                          //每页展示的列数

        /// <summary>
        /// 每页的数据行数
        /// </summary>
        public int PageRowCount
        {
            get { return _pageRowCount; }
            set { _pageRowCount = value; }
        }

        /// <summary>
        /// 每页展示的列数
        /// </summary>
        public int PageColCount
        {
            get
            {
                return _pageColCount;
            }

            set
            {
                _pageColCount = value;
            }
        }

        #endregion

        #region   需要导出为PDF的数据内容
        /// <summary>
        /// 导出为PDF文件的数据
        /// </summary>
        private DataTable _dtExportPDFDatas = null;

        /// <summary>
        /// 需要导出为PDF文件的数据集合
        /// </summary>
        /// <returns></returns>
        private DataTable ExportPDFDatas()
        {
            DataTable dtAllInfoData = new DataTable();
            dtAllInfoData.Columns.Add("Number");                                //数据序号
            dtAllInfoData.Columns.Add("OperaterName");                          //操作者
            dtAllInfoData.Columns.Add("HandoverTime");                          //交接班时间
            dtAllInfoData.Columns.Add("HandoverContents");                      //交接班内容

            DataRow row = null;
            int TotalNumbers=0;                                                 //当前导出系统交接班信息的总数
            List<Ctrl_View_System_OperationInfo_Data> _View_System_OperationInfo_Datas = new List<Ctrl_View_System_OperationInfo_Data>();//当前需要导出的系统交接班信息集合
          
            TotalNumbers = Ctrl_CommonView_System_OperationInfoOperation.GetInstance().QueryView_System_OperationInfoTotalNumbers();//系统操作总数
            _View_System_OperationInfo_Datas = Ctrl_CommonView_System_OperationInfoOperation.GetInstance().QueryAllView_System_OperationInfoOfIndex(0, TotalNumbers);
            

            for (int i = 0; i < TotalNumbers; i++)
            {
                row = dtAllInfoData.NewRow();
                row["Number"] = i+1;
                row["OperaterName"] = _View_System_OperationInfo_Datas[i].OperaterName;
                row["HandoverTime"] = _View_System_OperationInfo_Datas[i].HandoverTime;
                row["HandoverContents"] = _View_System_OperationInfo_Datas[i].HandoverContents;

                dtAllInfoData.Rows.Add(row);
            }
            return dtAllInfoData;
        }

        #endregion

        #region    生成页眉

        /// <summary>
        /// 生成页眉
        /// </summary>
        /// <param name="writer">文件流</param>
        /// <returns></returns>
        public override PdfPTable GenerateHeader(iTextSharp.text.pdf.PdfWriter writer)
        {
            BaseFont baseFont = BaseFontForHeaderFooter;
            iTextSharp.text.Font font_logo = new iTextSharp.text.Font(baseFont, 30, iTextSharp.text.Font.BOLD);
            iTextSharp.text.Font font_header1 = new iTextSharp.text.Font(baseFont, 18, iTextSharp.text.Font.BOLD);
            iTextSharp.text.Font font_header2 = new iTextSharp.text.Font(baseFont, 10, iTextSharp.text.Font.BOLD);
            iTextSharp.text.Font font_headerContent = new iTextSharp.text.Font(baseFont, 8, iTextSharp.text.Font.NORMAL);


            float[] widths = new float[] { 200,280,80,70, 50, 40,15,10,15 };

            PdfPTable header = new PdfPTable(widths);
            PdfPCell cell = new PdfPCell();


            cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_LEFT);
            cell.Phrase = new Paragraph("测试XXX科技有限公司"+"\n"+"XXX型号设备", font_header2);
            header.AddCell(cell);

            cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_CENTER);
            cell.Phrase = new Paragraph("交接班信息记录", font_header1);
            header.AddCell(cell);


            cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_RIGHT);
            cell.Phrase = new Paragraph("导出日期:", font_header2);
            header.AddCell(cell);

            cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_LEFT);
            cell.Phrase = new Paragraph(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), font_headerContent);
            header.AddCell(cell);

            cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_RIGHT);
            cell.Phrase = new Paragraph("导出人员:", font_header2);
            header.AddCell(cell);

            cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_CENTER);
            cell.Phrase = new Paragraph(GlobalParaMgr.userName, font_headerContent);
            header.AddCell(cell);

            cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_RIGHT);
            cell.Phrase = new Paragraph("第", font_header2);
            header.AddCell(cell);

            cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_CENTER);
            cell.Phrase = new Paragraph(writer.PageNumber.ToString(), font_headerContent);
            header.AddCell(cell);

            cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_RIGHT);
            cell.Phrase = new Paragraph("页", font_header2);
            header.AddCell(cell);
            return header;
        }

        #region   生成只有底边的Cell
        /// <summary>
        /// 生成只有底边的cell
        /// </summary>
        /// <param name="bottomBorder"></param>
        /// <param name="horizontalAlignment">水平对齐方式<see cref="iTextSharp.text.Element"/></param>
        /// <returns></returns>
        private PdfPCell GenerateOnlyBottomBorderCell(int bottomBorder,int horizontalAlignment)
        {
            PdfPCell cell = GenerateOnlyBottomBorderCell(bottomBorder, horizontalAlignment, iTextSharp.text.Element.ALIGN_BOTTOM);
            cell.PaddingBottom = 5;
            return cell;
        }

        /// <summary>
        /// 生成只有底边的cell
        /// </summary>
        /// <param name="bottomBorder"></param>
        /// <param name="horizontalAlignment">水平对齐方式<see cref="iTextSharp.text.Element"/></param>
        /// <param name="verticalAlignment">垂直对齐方式<see cref="iTextSharp.text.Element"/</param>
        /// <returns></returns>
        private PdfPCell GenerateOnlyBottomBorderCell(int bottomBorder, int horizontalAlignment, int verticalAlignment)
        {
            PdfPCell cell = GenerateOnlyBottomBorderCell(bottomBorder);
            cell.HorizontalAlignment = horizontalAlignment;
            cell.VerticalAlignment = verticalAlignment; ;
            return cell;
        }

        /// <summary>
        /// 生成只有底边的cell
        /// </summary>
        /// <param name="bottomBorder"></param>
        /// <returns></returns>
        private PdfPCell GenerateOnlyBottomBorderCell(int bottomBorder)
        {
            PdfPCell cell = new PdfPCell();
            cell.BorderWidthBottom = 2;
            cell.BorderWidthLeft = 0;
            cell.BorderWidthTop = 0;
            cell.BorderWidthRight = 0;
            return cell;
        }
        #endregion

        #endregion

        #region   生成页脚
        public override PdfPTable GenerateFooter(iTextSharp.text.pdf.PdfWriter writer)
        {
            BaseFont baseFont = BaseFontForHeaderFooter;
            iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, 10, iTextSharp.text.Font.NORMAL);

            PdfPTable footer = new PdfPTable(3);
            AddFooterCell(footer, "审阅:", font);
            AddFooterCell(footer, "审批:", font);
            AddFooterCell(footer, "日期:", font);
            return footer;
        }

        private void AddFooterCell(PdfPTable foot, String text, iTextSharp.text.Font font)
        {
            PdfPCell cell = new PdfPCell();
            cell.BorderWidthTop = 2;
            cell.BorderWidthRight = 0;
            cell.BorderWidthBottom = 0;
            cell.BorderWidthLeft = 0;
            cell.Phrase = new Phrase(text, font);
            cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
            foot.AddCell(cell);
        }
        #endregion

        #region   导出PDF

        /// <summary>
        /// 导出PDF
        /// </summary>
        /// <param name="path">导出路径</param>
        public void ExportPDF(String path)
        {
            Export_ChangeShifts_PDF pdfReport = new Export_ChangeShifts_PDF();
            Document document = new Document(PageSize.A4.Rotate(), -90, -90, 60, 10);//此处设置的偏移量是为了加大页面的可用范围,可以使用默认.
            PdfWriter pdfWriter = PdfWriter.GetInstance(document, new FileStream(path, FileMode.Create, FileAccess.Write));
            pdfWriter.PageEvent = pdfReport;//此处一定要赋值,才能触发页眉和页脚的处理
            document.Open();
            pdfReport.AddBody(document);
            document.Close();
        }

        /// <summary>
        /// 导出PDF
        /// </summary>
        /// <param name="path">导出路径</param>
        public  byte[] ExportPDF()
        {
            Export_ChangeShifts_PDF pdfReport = new Export_ChangeShifts_PDF();
            Document document = new Document(PageSize.A4.Rotate(), -90, -90, 60, 10);//此处设置的偏移量是为了加大页面的可用范围,可以使用默认.
            MemoryStream ms = new MemoryStream();
            PdfWriter pdfWriter = PdfWriter.GetInstance(document, ms);
            pdfWriter.PageEvent = pdfReport;//此处一定要赋值,才能触发页眉和页脚的处理
            document.Open();
            pdfReport.AddBody(document);
            document.Close();
            byte[] buff = ms.ToArray();
            return buff;
        }
        #endregion

        #region   添加内容

        /// <summary>
        /// 循环添加所有数据到每一页中
        /// </summary>
        /// <param name="document"></param>
        private void AddBody(Document document)
        {
            _dtExportPDFDatas = ExportPDFDatas();
            int count = (_dtExportPDFDatas.Rows.Count + (PageRowCount - 1)) / PageRowCount;
            for (int i = 0; i < count; i++)
            {
                AddBodySinglePage(i + 1);
                document.NewPage();
            }
        }

        /// <summary>
        /// 添加每页的数据信息
        /// </summary>
        /// <param name="pageNumber">页码</param>
        private void AddBodySinglePage(int pageNumber)
        {
            BaseFont baseFont = BaseFontForBody;
            iTextSharp.text.Font font_columnHeader = new iTextSharp.text.Font(baseFont, 11f, iTextSharp.text.Font.BOLD);
            iTextSharp.text.Font font_contentNormal = new iTextSharp.text.Font(baseFont, 9.5f, iTextSharp.text.Font.NORMAL);
            iTextSharp.text.Font font_contentSmall = new iTextSharp.text.Font(baseFont, 7f, iTextSharp.text.Font.NORMAL);

            //此处是为了当列数很多时,便于循环生成所要的表格列宽比例
            int columnCount = PageColCount;
            float[] widths = new float[columnCount];
            for (int i = 0; i < columnCount; i++)
            {
               
                if (i == 3)
                {
                    widths[i] = 3F;
                }
                else
                {
                    widths[i] = 0.7F;
                }
               
            }


            PdfPTable bodyTable = new PdfPTable(widths);
            bodyTable.SpacingBefore = 10;//与头部的距离

            //添加表头
            AddBodyHeader(bodyTable, font_columnHeader);

            //添加对应每页的数据
            AddSinglePageData(bodyTable, font_contentNormal, font_contentSmall, pageNumber);

            Document.Add(bodyTable);
        }

       

        #region   添加内容标题

        /// <summary>
        /// 添加Body的列标题
        /// </summary>
        /// <param name="document"></param>
        /// <param name="font_columnHeader"></param>
        private void AddBodyHeader(PdfPTable bodyTable, iTextSharp.text.Font font_columnHeader)
        {
            //采用Rowspan和Colspan来控制单元格的合并与拆分,类似于HTML的Table. 
            AddColumnHeaderCell(bodyTable, "序号", font_columnHeader, 1, 2);
            AddColumnHeaderCell(bodyTable, "操作者", font_columnHeader, 1, 2);
            AddColumnHeaderCell(bodyTable, "交接班时间", font_columnHeader, 1, 2);
            AddColumnHeaderCell(bodyTable, "交接班内容", font_columnHeader, 1, 2);
        }
        #endregion

        #region 添加报表正文

        /// <summary>
        /// 添加对应每页的数据
        /// </summary>
        /// <param name="bodyTable">表格</param>
        /// <param name="fontNormal">普通字体</param>
        /// <param name="fontSmall">小字体,当内容显示不下,需要使用小字体来显示时,可以使用.</param>
        /// <param name="pageNumber">页码</param>
        private void AddSinglePageData(PdfPTable bodyTable,
                                   iTextSharp.text.Font fontNormal,
                                   iTextSharp.text.Font fontSmall, int pageNumber)
        {
            int count = _dtExportPDFDatas.Rows.Count;//数据总量
            int startIndex = (pageNumber - 1) * PageRowCount;//开始索引
            int endIndex = pageNumber * PageRowCount;//结束索引
            int startIndex1 = count - startIndex;//下一页的开始索引
            int surplusNumbers = count - endIndex;//剩下的数量

            //Log.Write("pageNumber="+ pageNumber + "  count=" + count+ " startIndex=" + startIndex+ "  endIndex=" + endIndex+ "  startIndex1=" + startIndex1+ "  surplusNumbers=" + surplusNumbers);

            if (surplusNumbers > PageRowCount)
            {
                for (int i = startIndex; i < endIndex; i++)
                {
                    AddBodyContent(bodyTable, fontNormal, fontSmall, i);
                }

            }
            else
            {
                if (surplusNumbers > 0)
                {
                    for (int i = startIndex; i < endIndex; i++)
                    {
                        AddBodyContent(bodyTable, fontNormal, fontSmall, i);
                    }
                }
                else
                {
                    for (int i = startIndex; i < startIndex + startIndex1; i++)
                    {
                        AddBodyContent(bodyTable, fontNormal, fontSmall, i);
                    }
                }

            }
        }

        /// <summary>
        /// 添加报表正文
        /// </summary>
        /// <param name="bodyTable"></param>
        /// <param name="fontNormal">普通字体</param>
        /// <param name="fontSmall">小字体,当内容显示不下,需要使用小字体来显示时,可以使用.</param>
        /// <param name="index">索引便于从数据库中按页拉取数据时使用.</param>
        public void AddBodyContent(PdfPTable bodyTable,
                                   iTextSharp.text.Font fontNormal,
                                   iTextSharp.text.Font fontSmall,
                                   int index)
        {

            DataRow row = _dtExportPDFDatas.Rows[index];
            AddBodyContentCell(bodyTable, String.Format("{0}", row["Number"]), fontNormal);                 //数据序号
            AddBodyContentCell(bodyTable, String.Format("{0}", row["OperaterName"]), fontNormal);           //操作者
            AddBodyContentCell(bodyTable, String.Format("{0}", row["HandoverTime"]), fontNormal);           //交接班时间
            AddBodyContentCell(bodyTable, String.Format("{0}", row["HandoverContents"]), fontNormal);       //交接班内容

        }

        private static void AddBodyContentCell(PdfPTable bodyTable, String text, iTextSharp.text.Font font, int rowspan = 2, bool needRightBorder = true)
        {
            PdfPCell cell = new PdfPCell();
            float defaultBorder = 0.5f;
            cell.BorderWidthLeft = defaultBorder;
            cell.BorderWidthTop = 0;
            cell.BorderWidthRight = needRightBorder ? defaultBorder : 0;
            cell.BorderWidthBottom = defaultBorder;
            cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
            cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_BASELINE;
            cell.Rowspan = rowspan;
            cell.PaddingBottom = 4;
            cell.Phrase = new Phrase(text, font);
            cell.FixedHeight = 18f;
            bodyTable.AddCell(cell);
        }
        #endregion

        #region 添加列标题单元格

        /// <summary>
        /// 添加列标题单元格
        /// </summary>
        /// <param name="table">表格行的单元格列表</param>
        /// <param name="header">标题</param>
        /// <param name="font">字段</param>
        /// <param name="colspan">列空间</param>
        /// <param name="rowspan">行空间</param>
        /// <param name="needLeftBorder">是否需要左边框</param>
        /// <param name="needRightBorder">是否需要右边框</param>
        public void AddColumnHeaderCell(PdfPTable table,
                                                String header,
                                                iTextSharp.text.Font font,
                                                int colspan,
                                                int rowspan,
                                                bool needLeftBorder = true,
                                                bool needRightBorder = true)
        {
            PdfPCell cell = GenerateColumnHeaderCell(header, font, needLeftBorder, needRightBorder);
            if (colspan >= 1)
            {
                cell.Colspan = colspan;
            }

            if (rowspan >= 1)
            {
                cell.Rowspan = rowspan;
            }

            table.AddCell(cell);
        }

        /// <summary>
        /// 添加列标题单元格
        /// </summary>
        /// <param name="table">表格</param>
        /// <param name="header">标题</param>
        /// <param name="font">字段</param>
        /// <param name="needLeftBorder">是否需要左边框</param>
        /// <param name="needRightBorder">是否需要右边框</param>
        public void AddColumnHeaderCell(PdfPTable table,
                                                String header,
                                                iTextSharp.text.Font font,
                                                bool needLeftBorder = true,
                                                bool needRightBorder = true)
        {
            PdfPCell cell = GenerateColumnHeaderCell(header, font, needLeftBorder, needRightBorder);
            table.AddCell(cell);
        }
        #endregion

        #region 生成列标题单元格
        /// <summary>
        /// 生成列标题单元格
        /// </summary>
        /// <param name="header">标题</param>
        /// <param name="font">字段</param>
        /// <param name="needLeftBorder">是否需要左边框</param>
        /// <param name="needRightBorder">是否需要右边框</param>
        /// <returns></returns>
        private PdfPCell GenerateColumnHeaderCell(String header,
                                                        iTextSharp.text.Font font,
                                                        bool needLeftBorder = true,
                                                        bool needRightBorder = true)
        {
            PdfPCell cell = new PdfPCell();
            float border = 0.5f;
            cell.BorderWidthBottom = border;
            if (needLeftBorder)
            {
                cell.BorderWidthLeft = border;
            }
            else
            {
                cell.BorderWidthLeft = 0;
            }

            cell.BorderWidthTop = border;
            if (needRightBorder)
            {
                cell.BorderWidthRight = border;
            }
            else
            {
                cell.BorderWidthRight = 0;
            }

            cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
            cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_BASELINE;
            cell.PaddingBottom = 4;
            cell.Phrase = new Phrase(header, font);
            return cell;
        }
        #endregion

        #endregion

    }//Class_end
}

 调用导出PDF示例:

  //导出对应的所有交接班信息PDF文件
  Export_ChangeShifts_PDF.GetInstance().ExportPDF("C:\");

生成的PDF文件效果如下所示:

 

参考内容:https://download.csdn.net/download/xxdddail/8943371

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/xiaochenXIHUA/article/details/88421322

智能推荐

启动项目报错org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadT...-程序员宅基地

文章浏览阅读526次。昨天电脑关机的时候,没有停止项目,直接关闭了MyEclipse,今天来打开之后项目都报错,提示 信息如下2018-7-19 13:56:54 org.apache.catalina.core.AprLifecycleListener init信息: Loaded APR based Apache Tomcat Native library 1.1..._error creating bean with name 'loadtask' defined in servletcontext resource

websocket web聊天室的多页面跨面问题-程序员宅基地

文章浏览阅读1.4k次。为什么80%的码农都做不了架构师?>>> ..._web版聊天窗口如何跨浏览器

一种软件网络验证方式的实现 + 网络验证转本地验证的一种实现(附VC源码)...-程序员宅基地

文章浏览阅读5.6k次。目前很多软件都是通过网络验证来实现的,一种比较流行的方式便是把服务器端(如验证网页)放在服务器上,软件为客户端,当软件注册或启动时通过网络与服务器端进行数据交换,重新实现验证的目的。 个人觉得网络验证将是一种趋势,做得好的网络验证方式将是对软件的一种极大保护,如把软件的关键数据或关键代码放在服务器端,当认证通过后再发回到软件,且在传输过程中都用比较成熟的大型算法加密,从而达到一种防破解的..._网络验证转本地

笔记本出厂预装Win8改装Win7的操作步骤及常见问题-程序员宅基地

文章浏览阅读255次。故障现象:修改前的注意事项:若您确定要将您笔记本预装的Windows 8系统改装为Windows 7系统,请注意如下重要事项:1. 由于您笔记本预装的Windows 8系统需要使用BIOS中的UEFI功能及GPT分区表,所以在您将系统改装为Windows 7系统时,需要将随机Windows 8系统的所有分区全部删除(包括Windows 8引导分区、Windows 8系统修复分..._出厂win8换win7注意事项

(原)一次揪心的乱码排查过程-程序员宅基地

文章浏览阅读107次。序)很多时候其实问题很简单,问题在于自己懂得过于肤浅  项目中需要用到一个功能,机器人模拟和人类聊天,玩家说出一句话之后,机器人本能的和他开始聊天,这破B玩意儿我觉得只要有强大的词库和拆分算法,就那么点东西,但是要自己做还真是压力满满的。于是果断的在网上搜索,轻松的找到了这个东西:    这玩意儿给我的第一感觉就是实在,可以,完全能够满足需求,不过貌似它没有提供接口,这不是事儿,..._乱码 年 显示 骞

转】用Maven构建Hadoop项目-程序员宅基地

文章浏览阅读73次。  原博文出自于:  http://blog.fens.me/hadoop-maven-eclipse/      感谢! 用Maven构建Hadoop项目Hadoop家族系列文章,主要介绍Hadoop家族产品,常用的项目包括Hadoop, Hive, Pig, HBase, Sqoop, Mahout, Zookeeper, Avro, Ambari, Ch...

随便推点

2007 合成孔径雷达成像算法与实现 各figure的matlab实现(第三章 - 图3.13 )_合成孔径雷达成像算法与实现 matlab-程序员宅基地

文章浏览阅读728次。说明:(1)本程序信号开始时间为-T/2,得到的结果与设置的时延t0是一致的,方式2和方式3都能够定位到同一个时刻(2)与书本的结果不同;所以书本应该添加或者减少一个线性相位;不过这些不要紧,只要理解时域匹配滤波器和频域匹配滤波器就行matlab程序代码如下:% initial matlab workspace% figure 3.13; page 63clcclearclose all%% 参数设置% LFM脉冲宽度T 和 调频斜率KT = 7.2e-6;K = 4.1e12;_合成孔径雷达成像算法与实现 matlab

php mysql 手册_(十二)php参考手册---MySQLi函数(php操作MySQL)(仅学习)-程序员宅基地

文章浏览阅读161次。一、php数据库操作1.连接到指定数据库header('Content-Type:text/html; charset=utf-8');// 第一步连接到数据库(@是不显示错误,一般调试时不加要@)$con= @mysql_connect('localhost','root','');//连接到指定的数据库mysql_select_db('db_name',$con)?>注意:(配置都正确的..._var_dump($ress);

【Axure原型图】—— 2. SHOW HIDDEN WIDGET(显示隐藏组件)-程序员宅基地

文章浏览阅读579次。在点击某个部件,让其或者另外一个部件隐藏或显示Step0: 下载练习文件在这里下载AxureTraining.rp文件,并用Axure RP打开Step1: SETUP练习文档中打开"Show hidden widget" 页面,选择“语音气泡”图标通过单击检查器中得“样式工具栏“或者“样式选择框”中得“隐藏”复选框,来隐藏该部件。Step2: ADD ONCLICK INT..._axure shown

Android Fragment使用(四) Toolbar使用及Fragment中的Toolbar处理-程序员宅基地

文章浏览阅读683次。Toolbar作为ActionBar使用介绍本文介绍了在Android中将Toolbar作为ActionBar使用的方法.并且介绍了在Fragment和嵌套Fragment中使用Toolbar作为ActionBar使用时需要注意的事项.使用support library的ToolbarAndroid的ActionBar每个版本都会做一些改变, 所以原生的ActionBar在不同的系统上看..._android开发 fragment中使用toolbar

仿冒美团红包木马分析报告-程序员宅基地

文章浏览阅读147次。2015年05月18日 11:362705阿里移动安全实验室截获了一款仿冒美团应用的”美团红包”木马。用户安装木马后根据不同的参数,向服务器投递对应的数据,并上报用户敏感信息,包括:手机号,手机硬件及配置信息,用户的银行卡号,身份证号,姓名等各种敏感信息。美团应用安装量和使用频率非常高,而该仿冒木马应用迷惑性又极强,用户极其容易被诱骗安装受...

CVE-2021-4034:pkexec本地提权_phexec提权-程序员宅基地

文章浏览阅读3k次。影响范围Polkit Pkexec漏洞类型本地权限提升利用条件影响范围应用漏洞概述Polkit是一个应用程序级别的工具集,通过定义和审核权限规则,实现不同优先级进程间的通讯,控制决策集中在统一的框架之中,决定低优先级进程是否有权访问高优先级进程Polkit在系统层级进行权限控制,提供了一个低优先级进程和高优先级进程进行通讯的系统,它和sudo等程序不同,Polkit并没有赋予进程完全的root权限,而是通过一个集中的策略系统进行更精细的授权,这个漏洞是本地触发,只有在获得有限_phexec提权