當前位置: 首頁>>代碼示例>>C#>>正文


C# PdfStamper.AddFileAttachment方法代碼示例

本文整理匯總了C#中iTextSharp.text.pdf.PdfStamper.AddFileAttachment方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfStamper.AddFileAttachment方法的具體用法?C# PdfStamper.AddFileAttachment怎麽用?C# PdfStamper.AddFileAttachment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在iTextSharp.text.pdf.PdfStamper的用法示例。


在下文中一共展示了PdfStamper.AddFileAttachment方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GeneratePdf


//.........這裏部分代碼省略.........
                return;
            }

            try
            {
                stamper.AcroFields.AddSubstitutionFont(baseFont);

                SetFieldValue(stamper, "pageHead", reportTitle);
                SetFieldValue(stamper, "Head", reportTitle);
                stamper.AcroFields.SetFieldProperty("Head", "textsize", 20.0f, null);

                SetHeadFieldValue(stamper, "ver", string.Format("{0} Build:{1}", version.Ver, version.Build));
                SetHeadFieldValue(stamper, "data", tr.Key + ".trs");
                SetHeadFieldValue(stamper, "gDate", Util.FormateDateTime2(DateTime.Now));

                SetFieldValue(stamper, "tester", tr.Tester);
                SetFieldValue(stamper, "startTime", Util.FormateDateTime(tr.StartTime));
                SetFieldValue(stamper, "SN", tr.GetSN());
                SetFieldValue(stamper, "runningTime", Util.FormateDurationSecondsMaxHour(tr.RunningTime));
                if (tr.IsPass())
                {
                    SetFieldValue(stamper, "IsPass", "PASS");
                    stamper.AcroFields.SetFieldProperty("IsPass", "textsize", 38.0f, null);
                    stamper.AcroFields.SetFieldProperty("IsPass", "textcolor", BaseColor.BLUE, null);
                }
                else
                {
                    SetFieldValue(stamper, "IsPass", "FAIL");
                    stamper.AcroFields.SetFieldProperty("IsPass", "textsize", 38.0f, null);
                    stamper.AcroFields.SetFieldProperty("IsPass", "textcolor", BaseColor.RED, null);
                }
                string testType = "";
                string boardName = "";
                string isBoardPass = "";
                foreach (Rack r in tr.Racks)
                {
                    if(r.IsTested)
                    {
                        testType += r.Name + "\n";
                        foreach (Board b in r.Boards)
                        {
                            if (!b.IsTested)
                                continue;
                            boardName += b.Name + "\n";
                            isBoardPass += b.IsPassed ? "PASS\n" : "FAIL\n";
                        }
                    }

                }

                testType += endString;
                boardName += endString;
                isBoardPass += endString;
                SetFieldValue(stamper, "testType", testType);
                SetFieldValue(stamper, "boardName", boardName);
                SetFieldValue(stamper, "isBoardPass", isBoardPass);

                if (File.Exists(logFile))
                {
                    stamper.AddFileAttachment("Diagnostics logs", null, logFile, "log.txt");
                }

                stamper.FormFlattening = true;//不允許編輯
            }
            catch (Exception ee)
            {
                LogHelper.GetLogger<Report>().Error(ee.Message);
                LogHelper.GetLogger<Report>().Error(ee.StackTrace);
            }

            try
            {
                stamper.Close();
            }
            catch (Exception ee)
            {
                LogHelper.GetLogger<Report>().Error(ee.Message);
                LogHelper.GetLogger<Report>().Error(ee.StackTrace);
            }

            try
            {
                rdr.Close();
            }
            catch (Exception ee)
            {
                LogHelper.GetLogger<Report>().Error(ee.Message);
                LogHelper.GetLogger<Report>().Error(ee.StackTrace);
            }

            try
            {
                System.Diagnostics.Process.Start(pdfFile);
            }
            catch (Exception ee)
            {
                LogHelper.GetLogger<Report>().Error(ee.Message);
                LogHelper.GetLogger<Report>().Error(ee.StackTrace);
            }
        }
開發者ID:marlonnn,項目名稱:TSP_FCT,代碼行數:101,代碼來源:Report.cs


注:本文中的iTextSharp.text.pdf.PdfStamper.AddFileAttachment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。