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


C# PdfStamper.PartialFormFlattening方法代碼示例

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


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

示例1: ExportToSinglePDF

        /// <summary>
        /// Combines all the students into a single PDF with each page a seperate report.
        /// </summary>\
        void ExportToSinglePDF()
        {
            string savePath = System.IO.Path.Combine(System.IO.Path.GetFullPath(textSavePath.Text), string.Format("{0}.pdf", textFileName.Text));
            string templatePath = System.IO.Path.GetFullPath(textTempLocation.Text);

            int finishedReports = 0;

            using (Document doc = new Document())
            {
                using (PdfSmartCopy copy = new PdfSmartCopy(doc, new FileStream(savePath, FileMode.Create)))
                {
                    doc.Open();

                    foreach (var student in StudentList)
                    {
                        PdfReader reader = new PdfReader(templatePath);

                        using (MemoryStream ms = new MemoryStream())
                        {
                            using (PdfStamper stamper = new PdfStamper(reader, ms))
                            {
                                var form = stamper.AcroFields;

                                //Setting the text of the template to the stored info
                                form.SetField("Street", student.Address);
                                form.SetField("CityZipState", student.CityZipState);
                                form.SetField("ClassName", student.ClassName);
                                form.SetField("Comments", student.Comments);
                                form.SetField("Grade", student.Grade.ToString());
                                form.SetField("Critique", student.Critique);
                                form.SetField("HighSchool", student.HighSchool);
                                form.SetField("Session", student.Session);
                                form.SetField("Absences", student.SemesterTotalAbs.ToString());
                                form.SetField("Tardies", student.SemesterTotalTdy.ToString());
                                form.SetField("NetAbsences", student.SemesterNetAbs.ToString());
                                form.SetField("StuNameReversed", student.NameReversed);

                                form.SetField("Date", DateTime.Now.ToShortDateString());

                                form.RenameField("Comments", string.Format("Comments{0}", finishedReports));
                                form.RenameField("Date", string.Format("Date{0}", finishedReports));

                                //Flatten the fields that we do not want editable

                                stamper.FormFlattening = true;

                                stamper.PartialFormFlattening("StuNameReversed");
                                stamper.PartialFormFlattening("Street");
                                stamper.PartialFormFlattening("CityZipState");
                                stamper.PartialFormFlattening("HighSchool");
                                stamper.PartialFormFlattening("ClassName");
                                stamper.PartialFormFlattening("Session");
                                stamper.PartialFormFlattening("Absences");
                                stamper.PartialFormFlattening("Tardies");
                                stamper.PartialFormFlattening("NetAbsences");
                                stamper.PartialFormFlattening("Grade");
                                stamper.PartialFormFlattening("Critique");
                                stamper.PartialFormFlattening("Date");
                            }

                            reader = new PdfReader(ms.ToArray());
                            //Adds page to the output pdf
                            copy.AddPage(copy.GetImportedPage(reader, 1));

                            //Report progress to update status text
                            bgProgressThread.ReportProgress(++finishedReports);
                        }
                    }// Student Foreach end
                }
            }
        }
開發者ID:JRDuenow,項目名稱:ProgressBuilder,代碼行數:74,代碼來源:Export.cs

示例2: ManipulatePdf

// ---------------------------------------------------------------------------
    public byte[] ManipulatePdf(byte[] src, Dictionary<string, TextField> cache,
        string name, string login) 
    {
      using (MemoryStream ms = new MemoryStream()) {
        PdfReader reader = new PdfReader(src);
        using (PdfStamper stamper = new PdfStamper(reader, ms)) {
          AcroFields form = stamper.AcroFields;
          form.FieldCache = cache;
          form.SetExtraMargin(2, 0);
          form.RemoveField("personal.password");
          form.SetField("personal.name", name);        
          form.SetField("personal.loginname", login);
          form.RenameField("personal.reason", "personal.motivation");
          form.SetFieldProperty(
            "personal.loginname", "setfflags", TextField.READ_ONLY, null
          );        
          stamper.FormFlattening = true;
          stamper.PartialFormFlattening("personal.name");
        }
        return ms.ToArray();
      }
    }
開發者ID:,項目名稱:,代碼行數:23,代碼來源:

示例3: InitSignatureField

 /// <summary>
 /// Initialize the PDF signature field.
 /// </summary>
 private void InitSignatureField(PdfStamper stamper)
 {
     if (_acroFieldsWorker.HasSignatureField(SignatureFieldName))
     {
         _signatureAppearance.SetVisibleSignature(SignatureFieldName);
     }
     else
     {
         if (!string.IsNullOrWhiteSpace(SignatureFieldName)
             && _acroFieldsWorker.HasField(SignatureFieldName))
         {
             var textField = _acroFieldsWorker.FieldLocationByName(SignatureFieldName);
             _signatureAppearance.SetVisibleSignature(
                 textField.Rectangle, textField.Page,
                 _signatureAppearance.GetNewSigName()
             );
             stamper.FormFlattening = true;
             stamper.PartialFormFlattening(SignatureFieldName);
         }
         else if (SignatureBox != null)
         {
             _signatureAppearance.SetVisibleSignature(
                 SignatureBox,
                 // reader.NumberOfPages,
                 1,
                 _signatureAppearance.GetNewSigName()
             );
             stamper.FormFlattening = true;
             // stamper.PartialFormFlattening(SignatureFieldName);
         }
         else
         {
             throw new InvalidOperationException("field does not exist");
         }
     }
 }
開發者ID:kuujinbo,項目名稱:StackOverflow.iTextSharp.MVC.PdfSigner,代碼行數:39,代碼來源:WebSigner.cs

示例4: ExportToMultiplePDF

        void ExportToMultiplePDF(int index)
        {
            int finishedReports = 0;

            PdfStamper stamper = null;
            PdfReader reader = null;

                //Go through each student in the list

                foreach (var student in StudentList)
                {
                    string savePath = System.IO.Path.Combine(System.IO.Path.GetFullPath(textSavePath.Text),
                            string.Format("{0}.pdf",
                            index == 0
                            ? student.Name.Replace(' ', '_')
                            : student.NameReversed));

                    //Create FileStream for the template pdf
                    var templateStream = new FileStream(System.IO.Path.GetFullPath(textTempLocation.Text), FileMode.Open);

                    //Create FileStream for new student report pdf
                    var studentStream = new FileStream(savePath, FileMode.Create);

                    //Open existing pdf
                    reader = new PdfReader(templateStream);

                    //Create stamper to set the contents of the fields
                    stamper = new PdfStamper(reader, studentStream);

                    var form = stamper.AcroFields;

                    //Setting the text of the template to the stored info
                    form.SetField("Street", student.Address);
                    form.SetField("CityZipState", student.CityZipState);
                    form.SetField("ClassName", student.ClassName);
                    form.SetField("Comments", student.Comments);
                    form.SetField("Grade", student.Grade.ToString());
                    form.SetField("Critique", student.Critique);
                    form.SetField("HighSchool", student.HighSchool);
                    form.SetField("Session", student.Session);
                    form.SetField("Absences", student.SemesterTotalAbs.ToString());
                    form.SetField("Tardies", student.SemesterTotalTdy.ToString());
                    form.SetField("NetAbsences", student.SemesterNetAbs.ToString());
                    form.SetField("StuNameReversed", student.NameReversed);

                    form.SetField("Date", DateTime.Now.ToShortDateString());

                    //Flatten the fields that we do not want editable

                    stamper.FormFlattening = true;

                    stamper.PartialFormFlattening("StuNameReversed");
                    stamper.PartialFormFlattening("Street");
                    stamper.PartialFormFlattening("CityZipState");
                    stamper.PartialFormFlattening("HighSchool");
                    stamper.PartialFormFlattening("ClassName");
                    stamper.PartialFormFlattening("Session");
                    stamper.PartialFormFlattening("Absences");
                    stamper.PartialFormFlattening("Tardies");
                    stamper.PartialFormFlattening("NetAbsences");
                    stamper.PartialFormFlattening("Grade");
                    stamper.PartialFormFlattening("Critique");

                    stamper.Dispose();
                    reader.Dispose();

                    //reports progress to update status text on the bottom
                    bgProgressThread.ReportProgress(++finishedReports);

                }
        }
開發者ID:JRDuenow,項目名稱:ProgressBuilder,代碼行數:71,代碼來源:Export.cs


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