Esempio n. 1
0
        public virtual void RemoveFieldFromIndirectFieldsArrayTest()
        {
            String      outputFile = "removeFieldFromIndirectFieldsArrayTest.pdf";
            PdfDocument outputDoc  = new PdfDocument(new PdfReader(INPUT_FILE_WITH_INDIRECT_FIELDS_ARRAY), new PdfWriter
                                                         (DESTINATION_DIR + outputFile), new StampingProperties().UseAppendMode());

            PdfAcroForm.GetAcroForm(outputDoc, true).RemoveField("textfield2");
            outputDoc.Close();
            CompareWithCmp(outputFile);
        }
Esempio n. 2
0
        public virtual void FindFieldNameWithoutDataSet()
        {
            String      inFileName  = sourceFolder + "TextField1_empty.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfReader(inFileName));
            PdfAcroForm acroForm    = PdfAcroForm.GetAcroForm(pdfDocument, true);
            XfaForm     xfaForm     = acroForm.GetXfaForm();
            String      name        = xfaForm.FindFieldName("TextField1");

            NUnit.Framework.Assert.IsNull(name);
        }
Esempio n. 3
0
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.attach.impl.layout.form.renderer.AbstractFormFieldRenderer#applyAcroField(com.itextpdf.layout.renderer.DrawContext)
         */
        protected internal override void ApplyAcroField(DrawContext drawContext)
        {
            String             name     = GetModelId();
            PdfDocument        doc      = drawContext.GetDocument();
            Rectangle          area     = flatRenderer.GetOccupiedArea().GetBBox().Clone();
            PdfPage            page     = doc.GetPage(occupiedArea.GetPageNumber());
            PdfButtonFormField checkBox = PdfFormField.CreateCheckBox(doc, area, name, IsBoxChecked() ? "Yes" : "Off");

            PdfAcroForm.GetAcroForm(doc, true).AddField(checkBox, page);
        }
        public virtual void EncryptedDocumentWithFormFields()
        {
            PdfReader reader = new PdfReader(sourceFolder + "encryptedDocumentWithFormFields.pdf", new ReaderProperties
                                                 ().SetPassword("12345".GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1)));
            PdfDocument pdfDocument = new PdfDocument(reader);
            PdfAcroForm acroForm    = PdfAcroForm.GetAcroForm(pdfDocument, false);

            acroForm.GetField("personal.name").GetPdfObject();
            pdfDocument.Close();
        }
        public async Task <IActionResult> GenerateReporteLegal(int id)
        {
            Contrato contrato = await _context.Contratos.SingleOrDefaultAsync(x => x.IdContrato == id);

            MemoryStream stream = new MemoryStream();
            string       src    = "";

            if (contrato.id_compania.Equals(Constants.GuuidElectro))
            {
                switch (contrato.marca_exclusiva_bien)
                {
                case "YAMAHA":
                    src = _hostingEnvironment.WebRootPath + "/pdf/" + Constants.ReporteLegalKia;
                    break;

                default:
                    src = _hostingEnvironment.WebRootPath + "/pdf/" + Constants.ReporteLegalKia;
                    break;
                }
            }
            else
            {
                switch (contrato.marca_exclusiva_bien)
                {
                case "KIA":
                    src = _hostingEnvironment.WebRootPath + "/pdf/" + Constants.ReporteLegalKia;
                    break;

                case "VOLKSWAGEN":
                    src = _hostingEnvironment.WebRootPath + "/pdf/" + Constants.ReporteLegalKia;
                    break;

                default:
                    src = _hostingEnvironment.WebRootPath + "/pdf/" + Constants.ReporteLegalKia;
                    break;
                }
            }
            PdfWriter   pdfWriter = new PdfWriter(stream);
            PdfDocument pdf       = new PdfDocument(new PdfReader(src), pdfWriter);

            pdfWriter.SetCloseStream(false);

            PdfAcroForm pdfForm = PdfAcroForm.GetAcroForm(pdf, true);
            IDictionary <String, PdfFormField> fields = pdfForm.GetFormFields();

            _utilities.FillReporteLegal(fields, contrato);

            pdfForm.FlattenFields();
            pdf.Close();
            stream.Flush();
            stream.Position = 0;


            return(File(stream, "application/pdf", "[Qurii] " + DateTime.Now.ToString("yyyy-MM-dd-") + Constants.ReporteLegalPDF + ".pdf"));
        }
Esempio n. 6
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);

            // If no fields have been explicitly included, then all fields are flattened.
            // Otherwise only the included fields are flattened.
            form.FlattenFields();

            pdfDoc.Close();
        }
Esempio n. 7
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);

            // Set the visibility flag of the form field annotation.
            // Options are: HIDDEN, HIDDEN_BUT_PRINTABLE, VISIBLE, VISIBLE_BUT_DOES_NOT_PRINT
            form.GetField("Test").SetVisibility(PdfFormField.HIDDEN);

            pdfDoc.Close();
        }
        private static void CreateInputFile()
        {
            PdfDocument document = new PdfDocument(new PdfWriter(inputFile));

            document.AddNewPage();
            PdfAcroForm.GetAcroForm(document, true).AddField(PdfFormField.CreateText(document, new Rectangle(20, 160,
                                                                                                             100, 20), "textfield1", "text1"));
            PdfAcroForm.GetAcroForm(document, true).AddField(PdfFormField.CreateText(document, new Rectangle(20, 130,
                                                                                                             100, 20), "textfield2", "text2"));
            document.Close();
        }
Esempio n. 9
0
        public void FillOut(String src, String dest, String name, String value)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(src), new PdfWriter(dest),
                                                 new StampingProperties().UseAppendMode());

            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);

            form.GetField(name).SetValue(value);

            pdfDoc.Close();
        }
 private void WriteInPdf(string s89, S89Xlsx delegation, string destFolder, string description)
 {
     using (FileStream fs = new FileStream(Constant.FILE_FOLDER + "//" + s89, FileMode.Open))
     {
         PdfDocument pdfDoc = new PdfDocument(new PdfReader(fs), new PdfWriter(PdfUtil.FileNameExistAddR(destFolder + "//" + description + delegation.Name + Constant.PDF_FILE_NAME_EXTENSION)));
         PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);
         IDictionary <string, PdfFormField> fields = form.GetFormFields();
         SetPdfField(fields, delegation, pdfDoc);
         pdfDoc.Close();
     }
 }
 public virtual void FormFieldTaggingTest04() {
     String outFileName = destinationFolder + "taggedPdfWithForms04.pdf";
     String cmpFileName = sourceFolder + "cmp_taggedPdfWithForms04.pdf";
     PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "cmp_taggedPdfWithForms01.pdf"), new PdfWriter
         (outFileName));
     PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDoc, false);
     acroForm.RemoveField("TestCheck");
     acroForm.RemoveField("push");
     pdfDoc.Close();
     CompareOutput(outFileName, cmpFileName);
 }
Esempio n. 12
0
 public void WriteInDelegation(List <DelegationModel> delegationList)
 {
     foreach (DelegationModel delegationModel in delegationList)
     {
         PdfDocument pdfDoc = new PdfDocument(new PdfReader(WhichS89(delegationModel)), new PdfWriter(GetPdfFileName(delegationModel.Name)));
         PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);
         IDictionary <string, PdfFormField> fields = form.GetFormFields();
         SetPdfField(fields, delegationModel, pdfDoc);
         pdfDoc.Close();
     }
 }
Esempio n. 13
0
        public virtual void UnicodeFormFieldTest()
        {
            String      filename = sourceFolder + "unicodeFormFieldFile.pdf";
            PdfDocument pdfDoc   = new PdfDocument(new PdfReader(filename));
            PdfAcroForm form     = PdfAcroForm.GetAcroForm(pdfDoc, true);
            IDictionary <String, PdfFormField> formFields = form.GetFormFields();
            String fieldName = "\u5E10\u53F71";

            // 帐号1: account number 1
            NUnit.Framework.Assert.AreEqual(fieldName, formFields.Keys.ToArray(new String[1])[0]);
        }
Esempio n. 14
0
        public virtual void FormFieldTest01()
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "formFieldFile.pdf"));
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, false);
            IDictionary <String, PdfFormField> fields = form.GetFormFields();
            PdfFormField field = fields.Get("Text1");

            NUnit.Framework.Assert.IsTrue(fields.Count == 6);
            NUnit.Framework.Assert.IsTrue(field.GetFieldName().ToUnicodeString().Equals("Text1"));
            NUnit.Framework.Assert.IsTrue(field.GetValue().ToString().Equals("TestField"));
        }
Esempio n. 15
0
        public virtual void FlatteningFormFieldNoSubtypeInAPTest()
        {
            String      src  = sourceFolder + "formFieldNoSubtypeInAPTest.pdf";
            String      dest = destinationFolder + "flatteningFormFieldNoSubtypeInAPTest.pdf";
            String      cmp  = sourceFolder + "cmp_flatteningFormFieldNoSubtypeInAPTest.pdf";
            PdfDocument doc  = new PdfDocument(new PdfReader(src), new PdfWriter(dest));

            PdfAcroForm.GetAcroForm(doc, false).FlattenFields();
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(dest, cmp, destinationFolder, "diff_"));
        }
Esempio n. 16
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                PdfFormField field = PdfFormField.CreateSignature(drawContext.GetDocument(),
                                                                  GetOccupiedAreaBBox());

                field.SetFieldName(name);
                field.GetWidgets()[0].SetHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT);
                field.GetWidgets()[0].SetFlags(PdfAnnotation.PRINT);
                PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true).AddField(field);
            }
 public virtual void FormFieldTaggingTest01() {
     String outFileName = destinationFolder + "taggedPdfWithForms01.pdf";
     String cmpFileName = sourceFolder + "cmp_taggedPdfWithForms01.pdf";
     PdfWriter writer = new PdfWriter(outFileName);
     PdfDocument pdfDoc = new PdfDocument(writer);
     pdfDoc.SetTagged();
     PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
     AddFormFieldsToDocument(pdfDoc, form);
     pdfDoc.Close();
     CompareOutput(outFileName, cmpFileName);
 }
Esempio n. 18
0
        public virtual void FormFlatteningTest01()
        {
            String      srcFilename = sourceFolder + "formFlatteningSource.pdf";
            String      filename    = destinationFolder + "formFlatteningTest01.pdf";
            PdfDocument doc         = new PdfDocument(new PdfReader(srcFilename), new PdfWriter(filename));
            PdfAcroForm form        = PdfAcroForm.GetAcroForm(doc, true);

            form.FlattenFields();
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp_formFlatteningTest01.pdf"
                                                                             , destinationFolder, "diff_"));
        }
Esempio n. 19
0
        public virtual void FormFlatteningTestWithoutNEntry()
        {
            String      filename = "formFlatteningTestWithoutNEntry";
            String      src      = sourceFolder + filename + ".pdf";
            String      dest     = destinationFolder + filename + "_flattened.pdf";
            String      cmp      = sourceFolder + "cmp_" + filename + "_flattened.pdf";
            PdfDocument doc      = new PdfDocument(new PdfReader(src), new PdfWriter(dest));

            PdfAcroForm.GetAcroForm(doc, false).FlattenFields();
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(dest, cmp, destinationFolder, "diff_"));
        }
Esempio n. 20
0
        private static byte[] fillFormSF3101(SF3101 rec, string templatePdfFile)
        {
            using (var memoryStream = new MemoryStream())
            {
                PdfReader   reader = new PdfReader(templatePdfFile); //Iput
                PdfWriter   writer = new PdfWriter(memoryStream);    //output
                PdfDocument pdfDoc = new PdfDocument(reader, writer);
                PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);
                var         fields = form.GetFormFields();

                form.RemoveField("SAVE");  //remove save button
                form.RemoveField("PRINT"); //remove print button
                form.RemoveField("RESET"); //remove reset button
                //form.GetField("Reason").SetVisibility(3);

                //Since we control the template, we can directly set all the fields
                fields["SSN"].SetValue(rec.SSN);
                fields["Name"].SetValue(rec.Name);
                fields["DOB"].SetValue(rec.DOB);
                fields["Agency"].SetValue(rec.Agency);
                fields["Payroll Office No"].SetValue(rec.PayrollOfficeNo);
                if (!String.IsNullOrEmpty(rec.Location))
                {
                    fields["Location"].SetValue(rec.Location);
                }
                if (!String.IsNullOrEmpty(rec.Reason))
                {
                    fields["Reason"].SetValue(rec.Reason);
                }
                fields["Data on SF 3100"].SetValue(rec.DataOnSF3100);
                fields["Total culmulative"].SetValue(rec.TotalCulmulative);
                fields["Corrected Data"].SetValue(rec.CorrectedData);
                fields["Overstatement"].SetValue(rec.Overstatement);
                fields["Total culmulative deductions"].SetValue(rec.TotalCulmulativeDeductions);
                fields["SF 3100 Data 2"].SetValue(rec.SF3100Data2);
                fields["SF 3100 Corrected Data 2"].SetValue(rec.SF3100CorrectedData2);
                fields["SF 3100 Data"].SetValue(rec.SF3100Data);
                fields["SF 3100 Corrected Data"].SetValue(rec.SF3100CorrectedData);
                fields["SF 3100 Corrected Data 3"].SetValue(rec.SF3100CorrectedData3);
                fields["SF 2812 Number"].SetValue(rec.SF2812Number);
                fields["Register"].SetValue(rec.Register);
                fields["SF2812 - dated"].SetValue(rec.SF2812Dated);
                fields["SF 3100 Data 3"].SetValue(rec.SF3100Data3);
                fields["Title"].SetValue(rec.Title);
                fields["Telephone Number"].SetValue(rec.TelephoneNumber);
                fields["Register - dated"].SetValue(rec.RegisterDated);
                fields["Date signed"].SetValue(rec.DateSigned);

                form.FlattenFields();
                pdfDoc.Close();
                return(memoryStream.ToArray());
            }
        }
Esempio n. 21
0
        private static void createPocoFromPDF(string pdf)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(pdf));
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);
            var         fields = form.GetFormFields();
            var         lines  = fields.Select(kvp => kvp.Key); //Grab PDF Fields from document

            foreach (var l in lines)                            //Iterate through the fields to build the set value map
            {
                Console.WriteLine($"public string {l.Replace(" ",string.Empty).Replace(".",string.Empty)} {{ get; set; }}");
            }
        }
Esempio n. 22
0
        public static void Sign(string input, string output, ImageData stamper, ICipherParameters privateKey, X509Certificate[] chain, string flag)
        {
            PdfDocument document = new PdfDocument(new PdfReader(input));

            PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(document, false);
            bool        append   = (acroForm != null && acroForm.GetSignatureFlags() != 0);

            int pageNumber = document.GetNumberOfPages();

            RegexBasedLocationExtractionStrategy strategy = new RegexBasedLocationExtractionStrategy(flag);
            PdfDocumentContentParser             parser   = new PdfDocumentContentParser(document);

            parser.ProcessContent(pageNumber, strategy);
            var locations = new List <IPdfTextLocation>(strategy.GetResultantLocations());

            document.Close();

            StampingProperties properties = new StampingProperties();

            properties = append ? properties.UseAppendMode() : properties;

            PdfSigner signer = new PdfSigner(new PdfReader(input), new FileStream(output, FileMode.Create), properties);

            signer.SetCertificationLevel(PdfSigner.CERTIFIED_NO_CHANGES_ALLOWED);

            PdfSignatureAppearance appearance = signer.GetSignatureAppearance();

            appearance.SetPageNumber(pageNumber);

            int size = locations.Count;

            if (size != 0)
            {
                IPdfTextLocation location = locations[size - 1];

                float flagX = location.GetRectangle().GetX();
                float flagY = location.GetRectangle().GetY();

                float width  = stamper.GetWidth();
                float height = stamper.GetHeight();

                float x = flagX - width / 2;
                float y = flagY - height / 2;

                appearance.SetRenderingMode(PdfSignatureAppearance.RenderingMode.GRAPHIC);
                appearance.SetSignatureGraphic(stamper);
                appearance.SetPageRect(new Rectangle(x, y, width, height));
            }

            PrivateKeySignature signature = new PrivateKeySignature(privateKey, DigestAlgorithms.SHA256);

            signer.SignDetached(signature, chain, null, null, null, 0, PdfSigner.CryptoStandard.CADES);
        }
Esempio n. 23
0
        /// <summary>Gets a new signature field name that doesn't clash with any existing name.</summary>
        /// <returns>A new signature field name.</returns>
        public virtual String GetNewSigFieldName()
        {
            PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(document, true);
            String      name     = "Signature";
            int         step     = 1;

            while (acroForm.GetField(name + step) != null)
            {
                ++step;
            }
            return(name + step);
        }
        public virtual void ReplaceFieldTest()
        {
            String      outputFile = "replaceFieldTest.pdf";
            PdfDocument outputDoc  = new PdfDocument(new PdfReader(inputFile), new PdfWriter(destinationFolder + outputFile
                                                                                             ), new StampingProperties().UseAppendMode());
            PdfFormField newField = PdfFormField.CreateText(outputDoc, new Rectangle(20, 160, 100, 20), "newfield", "new field"
                                                            );

            PdfAcroForm.GetAcroForm(outputDoc, true).ReplaceField("textfield1", newField);
            outputDoc.Close();
            CompareWithCmp(outputFile);
        }
Esempio n. 25
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);

            // The second parameter sets how the field's value will be displayed in the resultant pdf.
            // If the second parameter is null, then actual value will be shown.
            form.GetField("Name").SetValue("1.0", "100%");
            form.GetField("Company").SetValue("1217000.000000", "$1,217,000");

            pdfDoc.Close();
        }
Esempio n. 26
0
        public virtual void NoWarningOnValueNotOfOptComboEditTest()
        {
            String      srcPdf      = sourceFolder + "noWarningOnValueNotOfOptComboEditTest.pdf";
            String      outPdf      = destinationFolder + "noWarningOnValueNotOfOptComboEditTest.pdf";
            String      cmpPdf      = sourceFolder + "cmp_noWarningOnValueNotOfOptComboEditTest.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfReader(srcPdf), new PdfWriter(outPdf));
            PdfAcroForm form        = PdfAcroForm.GetAcroForm(pdfDocument, false);

            form.GetField("First").SetValue("Value not of /Opt array");
            pdfDocument.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
        }
Esempio n. 27
0
        public virtual void FindFieldName()
        {
            String      inFileName  = sourceFolder + "TextField1.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfReader(inFileName));
            PdfAcroForm acroForm    = PdfAcroForm.GetAcroForm(pdfDocument, true);
            XfaForm     xfaForm     = acroForm.GetXfaForm();

            xfaForm.FindFieldName("TextField1");
            String secondRun = xfaForm.FindFieldName("TextField1");

            NUnit.Framework.Assert.IsNotNull(secondRun);
        }
Esempio n. 28
0
        private static void discoverPDFFields(string pdf)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(pdf));
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);
            var         fields = form.GetFormFields();
            var         lines  = fields.Select(kvp => kvp.Key); //Grab PDF Fields from document

            foreach (var l in lines)                            //Iterate through the fields to build the set value map
            {
                Console.WriteLine($"fields[\"{l}\"].SetValue();");
            }
        }
Esempio n. 29
0
 protected override void CheckForm(PdfWriter writer, int key, Object obj1)
 {
     if (obj1 is PdfAcroForm)
     {
         PdfAcroForm form            = (PdfAcroForm)obj1;
         PdfBoolean  needAppearances = form.GetAsBoolean(PdfName.NEEDAPPEARANCES);
         if (needAppearances != null && needAppearances.BooleanValue)
         {
             throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("needappearances.flag.of.the.interactive.form.dictionary.shall.either.not.be.present.or.shall.be.false"));
         }
     }
 }
        public virtual void AddFieldTest()
        {
            String      outputFile = "addFieldTest.pdf";
            PdfDocument outputDoc  = new PdfDocument(new PdfReader(inputFile), new PdfWriter(destinationFolder + outputFile
                                                                                             ), new StampingProperties().UseAppendMode());
            PdfFormField field = PdfFormField.CreateCheckBox(outputDoc, new Rectangle(10, 10, 24, 24), "checkboxname",
                                                             "On", PdfFormField.TYPE_CHECK);

            PdfAcroForm.GetAcroForm(outputDoc, true).AddField(field);
            outputDoc.Close();
            CompareWithCmp(outputFile);
        }