コード例 #1
0
        public static void Exp_SY7()
        {
            Paragraph Title;
            String    tempname = getfilename();

            if (tempname == "")
            {
                return;
            }
            Document  document = new Document();
            PdfWriter writer   = PdfWriter.GetInstance(document, new FileStream(tempname, FileMode.Create));

            document.Open();
            table = new PdfPTable(2);//  设计试验7的表格总共有6列
            table.WidthPercentage = 100;
            if (MainFrom.comBoxData_Form == "HBK-II/1")
            {
                Title = new Paragraph("7. 滑板控制装置连续收板(程控20次)试验记录", fonttitle);
            }
            else
            {
                Title = new Paragraph("8. 滑板控制装置连续收板(程控20次)试验记录", fonttitle);
            }
            Title.SetAlignment("center");
            document.Add(Title);
            nullb         = new Paragraph(" ", fonttitle2);
            nullb.Leading = 10;  //此数值用于调整空白大小0
            document.Add(nullb);
            int       flag   = 1;
            PdfPTable table1 = new PdfPTable(6);
            PdfPTable table2 = new PdfPTable(6);

            dtb    = Export_All_SY.DBQuery("SY7_Lxsb_Ck");
            table1 = Export_Table_Design.SY7_Table1(table1, ref flag, dtb); //表格7设计单独做一个函数
            table2 = Export_Table_Design.SY7_Table2(table2, ref flag, dtb); //表格7设计单独做一个函数
            Export_All_SY.DBDel("SY7_Lxsb_Ck");
            cell1         = new PdfPCell(table1);
            cell1.Padding = 0;
            table.AddCell(cell1);
            cell1         = new PdfPCell(table2);
            cell1.Padding = 0.5f;
            table.AddCell(cell1);
            document.Add(table); //將table放到pdf文件中
            Title = new Paragraph("  注:试验中“√”表示动作正常,“×”表示动作异常", fonttitle3);
            document.Add(Title); //将标题段加入PDF文档中
            document.Close();
        }
コード例 #2
0
        /// <summary>
        /// 设计项目试验7的打印报表
        /// </summary>
        /// <param name="filepath"></param>
        public static void Exp_PDF2(string filepath, int status)
        {
            PdfReader       pdfReader = null;
            PdfImportedPage pageTemplate = null;
            int             i, j, k;
            Document        document = null;
            Paragraph       Title;
            //============================================加载模板并在模板后添加新表格==================================================
            string tempPath = Path.GetDirectoryName(filepath) + Path.GetFileNameWithoutExtension(filepath) + "_temp.pdf";

            try
            {
                pdfReader = new PdfReader(filepath);
                Rectangle pageSize = pdfReader.GetPageSize(1);
                document = new Document(pageSize);
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(tempPath, FileMode.Create));
                document.Open();
                int            total   = pdfReader.NumberOfPages + 1;
                PdfContentByte cbUnder = writer.DirectContentUnder;
                for (i = 1; i < total; i++)
                {
                    pageTemplate = writer.GetImportedPage(pdfReader, i);
                    cbUnder.AddTemplate(pageTemplate, 0, 0);
                    document.NewPage();
                }
                //============================================设计试验7的表格==================================================
                table = new PdfPTable(2);//  设计试验7的表格总共有6列
                table.WidthPercentage = 100;
                if (MainFrom.comBoxData_Form == "HBK-II/1")
                {
                    Title = new Paragraph("7. 滑板控制装置连续收板(程控20次)试验记录", fonttitle);
                }
                else
                {
                    Title = new Paragraph("8. 滑板控制装置连续收板(程控20次)试验记录", fonttitle);
                }
                Title.SetAlignment("center");
                document.Add(Title);
                nullb         = new Paragraph(" ", fonttitle2);
                nullb.Leading = 10;  //此数值用于调整空白大小0
                document.Add(nullb);
                int       flag   = 1;
                PdfPTable table1 = new PdfPTable(6);
                PdfPTable table2 = new PdfPTable(6);
                if (status == 0)
                {
                    dtb = SY7_DB();
                }
                else
                {
                    dtb = History.Final_Pdf("SY7_Lxsb_Ck_Final");
                }
                table1        = Export_Table_Design.SY7_Table1(table1, ref flag, dtb); //表格7设计单独做一个函数
                table2        = Export_Table_Design.SY7_Table2(table2, ref flag, dtb); //表格7设计单独做一个函数
                cell1         = new PdfPCell(table1);
                cell1.Padding = 0;
                table.AddCell(cell1);
                cell1         = new PdfPCell(table2);
                cell1.Padding = 0.5f;
                table.AddCell(cell1);
                document.Add(table); //將table放到pdf文件中
                Title = new Paragraph("  注:试验中“√”表示动作正常,“×”表示动作异常", fonttitle3);
                document.Add(Title); //将标题段加入PDF文档中
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                document.Close();
                if (pdfReader != null)
                {
                    pdfReader.Close();
                }
                File.Copy(tempPath, filepath, true);
                File.Delete(tempPath);
            }
        }