详细内容
C#弹出PDF打印页面
发布日期:2012-02-22     点击:3230     字体:[ ]

这里的PDF打印页面是通过一个DLL引用,itextsharp.dllitextsharp.rar实现的,具体页面:前台绑定数据,和弹出的PDF没有多大关系,目的是在弹出页面里可直接引用值,后台实现PDF内容。

先给出后台内容:

首先需添加引用:

using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;

        //生成PDF文档方法
        private void InitPdfTable()
        {
            float tableWidth = 95;
            // 1/5  创建一个 iTextSharp.text.Document对象的实例
            Document document = new Document(PageSize.A4, 30, 30, 36, 36);

            // 2/5  为该Document创建一个Writer实例
            PdfWriter.GetInstance(document, new FileStream(FilesFolderPath, FileMode.Create));

            // 3/5  打开当前Document
            document.Open();

            // 4/5  为当前Document添加内容
            PdfPCell cell;//单元格

            //字体格式
            BaseFont bfSun = BaseFont.CreateFont(@"C:\WINDOWS\fonts\MINGLIU.TTC,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            Font f12 = new Font(bfSun, 12);
            Font f12b = new Font(bfSun, 12, Font.BOLD);
            Font f16 = new Font(bfSun, 16, Font.BOLD);

            PdfPCell cellNoborder = new PdfPCell();
            cellNoborder.BorderWidth = 0;
            cellNoborder.PaddingBottom = 5;

            cellNoborder.VerticalAlignment = Element.ALIGN_MIDDLE;
            cellNoborder.HorizontalAlignment = Element.ALIGN_RIGHT;

            PdfPCell cellNoborderNoPadding = new PdfPCell();
            cellNoborderNoPadding.BorderWidth = 0;
            cellNoborderNoPadding.Padding = 0;
            cellNoborderNoPadding.VerticalAlignment = Element.ALIGN_TOP;

            cellNoborderNoPadding.VerticalAlignment = Element.ALIGN_MIDDLE;
            cellNoborderNoPadding.HorizontalAlignment = Element.ALIGN_RIGHT;

            PdfPCell cellBorder = new PdfPCell();
            cellBorder.BorderWidth = 1;
            cellBorder.PaddingBottom = 5;
            cellBorder.VerticalAlignment = Element.ALIGN_MIDDLE;

            PdfPCell cellBorderNoPadding = new PdfPCell();
            cellBorderNoPadding.BorderWidth = 1;
            cellBorderNoPadding.Padding = 0;
            cellBorderNoPadding.VerticalAlignment = Element.ALIGN_MIDDLE;

            PdfPTable tableContent = new PdfPTable(1);
            tableContent.WidthPercentage = tableWidth;

            #region 标题:國外出差旅費報支表
            PdfPTable tableTitle = new PdfPTable(1);
            tableTitle.WidthPercentage = tableWidth;

            cell = new PdfPCell(cellNoborder);
            cell.Phrase = new Phrase("國外出差旅費報支表", f16);
            cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            tableTitle.AddCell(cell);

            //添加一空行
            cell = new PdfPCell(cellNoborder);
            cell.Phrase = new Phrase("", f16);
            tableTitle.AddCell(cell);

            //将该表(标题)加入上部分表中
            //cell = new PdfPCell(cellNoborder);
            //cell.AddElement(tableTitle);
            //tableContent.AddCell(cell);
            #endregion

            #region 表单基本信息:申请人、表单号、申请日期、填单人
            PdfPTable tableBasic = new PdfPTable(3);
            tableBasic.WidthPercentage = tableWidth;
            //申请单号
            cell = new PdfPCell(cellNoborder);
            cell.Phrase = new Phrase("申請單號:" + this.Label_FormNo.Text, f12);
            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
            tableBasic.AddCell(cell);

            //申请日期
            cell = new PdfPCell(cellNoborder);
         &nbs

用户评论
昵称 
内容  *
验证码   
   
Copyright © 2010 zdbase.com All Rights Reserved. 苏ICP备15039389号 可人软件设计