Beispiel #1
0
        public virtual void EncryptAes256Pdf2PermissionsTest01()
        {
            String filename    = "encryptAes256Pdf2PermissionsTest01.pdf";
            int    permissions = EncryptionConstants.ALLOW_FILL_IN | EncryptionConstants.ALLOW_SCREENREADERS | EncryptionConstants
                                 .ALLOW_DEGRADED_PRINTING;
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + filename, new WriterProperties().SetPdfVersion
                                                                   (PdfVersion.PDF_2_0).SetStandardEncryption(USER, OWNER, permissions, EncryptionConstants.ENCRYPTION_AES_256
                                                                                                              )));

            pdfDoc.GetDocumentInfo().SetMoreInfo(customInfoEntryKey, customInfoEntryValue);
            PdfAcroForm      form       = PdfAcroForm.GetAcroForm(pdfDoc, true);
            PdfTextFormField textField1 = PdfFormField.CreateText(pdfDoc, new Rectangle(100, 600, 200, 30), "Name", "Enter your name"
                                                                  );

            form.AddField(textField1);
            PdfTextFormField textField2 = PdfFormField.CreateText(pdfDoc, new Rectangle(100, 550, 200, 30), "Surname",
                                                                  "Enter your surname");

            form.AddField(textField2);
            PdfButtonFormField group = PdfFormField.CreateRadioGroup(pdfDoc, "Sex", "Male");

            PdfFormField.CreateRadioButton(pdfDoc, new Rectangle(100, 530, 10, 10), group, "Male");
            PdfFormField.CreateRadioButton(pdfDoc, new Rectangle(120, 530, 10, 10), group, "Female");
            form.AddField(group);
            pdfDoc.Close();
            CompareTool compareTool  = new CompareTool();
            String      errorMessage = compareTool.CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename
                                                                    , destinationFolder, "diff_", USER, USER);

            if (errorMessage != null)
            {
                NUnit.Framework.Assert.Fail(errorMessage);
            }
        }
Beispiel #2
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);
            PdfFont     font   = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);
            Rectangle   rect   = new Rectangle(40, 788, 20, 18);
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);

            // Radio buttons will be added to this radio group
            PdfButtonFormField radioGroup = PdfFormField.CreateRadioGroup(pdfDoc, "Language", "");

            for (int page = 1; page <= LANGUAGES.Length; page++)
            {
                pdfDoc.AddNewPage();

                // Create a radio button that is added to a radio group.
                PdfFormField field = PdfFormField.CreateRadioButton(pdfDoc, rect, radioGroup, LANGUAGES[page - 1]);
                field.SetBorderWidth(1);
                field.SetBorderColor(ColorConstants.BLACK);

                // Method specifies on which page the form field's widget must be shown.
                field.SetPage(page);
                doc.ShowTextAligned(new Paragraph(LANGUAGES[page - 1]).SetFont(font).SetFontSize(18),
                                    70, 786, page, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0);
            }

            form.AddField(radioGroup);

            doc.Close();
        }
        public virtual void ButtonFieldTest01()
        {
            String             filename = destinationFolder + "buttonFieldTest01.pdf";
            PdfWriter          writer   = new PdfWriter(new FileStream(filename, FileMode.Create));
            PdfDocument        pdfDoc   = new PdfDocument(writer);
            PdfAcroForm        form     = PdfAcroForm.GetAcroForm(pdfDoc, true);
            Rectangle          rect     = new Rectangle(36, 700, 20, 20);
            Rectangle          rect1    = new Rectangle(36, 680, 20, 20);
            PdfButtonFormField group    = PdfFormField.CreateRadioGroup(pdfDoc, "TestGroup", "1");

            PdfFormField.CreateRadioButton(pdfDoc, rect, group, "1");
            PdfFormField.CreateRadioButton(pdfDoc, rect1, group, "2");
            form.AddField(group);
            PdfButtonFormField pushButton = PdfFormField.CreatePushButton(pdfDoc, new Rectangle(36, 650, 40, 20), "push"
                                                                          , "Capcha");
            PdfButtonFormField checkBox = PdfFormField.CreateCheckBox(pdfDoc, new Rectangle(36, 560, 20, 20), "TestCheck"
                                                                      , "1");

            form.AddField(pushButton);
            form.AddField(checkBox);
            pdfDoc.Close();
            CompareTool compareTool  = new CompareTool();
            String      errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_buttonFieldTest01.pdf", destinationFolder
                                                                    , "diff_");

            if (errorMessage != null)
            {
                NUnit.Framework.Assert.Fail(errorMessage);
            }
        }
Beispiel #4
0
        public virtual void PdfA1aRadioFieldOffAppearanceTest()
        {
            String          name         = "pdfA1a_radioFieldOffAppearance";
            String          outPath      = destinationFolder + name + ".pdf";
            String          cmpPath      = cmpFolder + "cmp_" + name + ".pdf";
            String          diff         = "diff_" + name + "_";
            PdfWriter       writer       = new PdfWriter(outPath);
            Stream          @is          = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
                                                               , @is);
            PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);

            doc.SetTagged();
            doc.GetCatalog().SetLang(new PdfString("en-US"));
            doc.AddNewPage();
            PdfAcroForm        form  = PdfAcroForm.GetAcroForm(doc, true);
            PdfButtonFormField group = PdfFormField.CreateRadioGroup(doc, "group", "1", PdfAConformanceLevel.PDF_A_1B);

            group.SetReadOnly(true);
            Rectangle rect1 = new Rectangle(36, 700, 20, 20);
            Rectangle rect2 = new Rectangle(36, 680, 20, 20);

            PdfFormField.CreateRadioButton(doc, rect1, group, "1", PdfAConformanceLevel.PDF_A_1B).SetBorderWidth(2).SetBorderColor
                (ColorConstants.RED).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetVisibility(PdfFormField.VISIBLE);
            PdfFormField.CreateRadioButton(doc, rect2, group, "2", PdfAConformanceLevel.PDF_A_1B).SetBorderWidth(2).SetBorderColor
                (ColorConstants.RED).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetVisibility(PdfFormField.VISIBLE);
            form.AddField(group);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
                                                                             ));
        }
Beispiel #5
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)
        {
            PdfDocument        doc        = drawContext.GetDocument();
            PdfAcroForm        form       = PdfAcroForm.GetAcroForm(doc, true);
            Rectangle          area       = flatRenderer.GetOccupiedArea().GetBBox().Clone();
            PdfPage            page       = doc.GetPage(occupiedArea.GetPageNumber());
            String             groupName  = this.GetProperty <String>(Html2PdfProperty.FORM_FIELD_VALUE);
            PdfButtonFormField radioGroup = (PdfButtonFormField)form.GetField(groupName);
            bool addNew = false;

            if (null == radioGroup)
            {
                radioGroup = PdfFormField.CreateRadioGroup(doc, groupName, "on");
                addNew     = true;
            }
            if (IsBoxChecked())
            {
                radioGroup.SetValue(GetModelId());
            }
            PdfFormField radio = PdfFormField.CreateRadioButton(doc, area, radioGroup, GetModelId());

            radio.SetCheckType(PdfFormField.TYPE_CIRCLE);
            if (addNew)
            {
                form.AddField(radioGroup, page);
            }
            else
            {
                form.ReplaceField(GetModelId(), radioGroup);
            }
            WriteAcroFormFieldLangAttribute(doc);
        }
Beispiel #6
0
        public static PdfAcroForm AddAcroForm(Document doc)
        {
            Paragraph title = new Paragraph("Application for employment").SetTextAlignment(TextAlignment.CENTER).SetFontSize
                                  (16);

            doc.Add(title);
            doc.Add(new Paragraph("Full name:").SetFontSize(12));
            doc.Add(new Paragraph("Native language:      English         French       German        Russian        Spanish"
                                  ).SetFontSize(12));
            doc.Add(new Paragraph("Experience in:       cooking        driving           software development").SetFontSize
                        (12));
            doc.Add(new Paragraph("Preferred working shift:").SetFontSize(12));
            doc.Add(new Paragraph("Additional information:").SetFontSize(12));
            //Add acroform
            PdfAcroForm form = PdfAcroForm.GetAcroForm(doc.GetPdfDocument(), true);
            //Create text field
            PdfTextFormField nameField = PdfTextFormField.CreateText(doc.GetPdfDocument(), new Rectangle(99, 753, 425,
                                                                                                         15), "name", "");

            form.AddField(nameField);
            //Create radio buttons
            PdfButtonFormField group = PdfFormField.CreateRadioGroup(doc.GetPdfDocument(), "language", "");

            PdfFormField.CreateRadioButton(doc.GetPdfDocument(), new Rectangle(130, 728, 15, 15), group, "English");
            PdfFormField.CreateRadioButton(doc.GetPdfDocument(), new Rectangle(200, 728, 15, 15), group, "French");
            PdfFormField.CreateRadioButton(doc.GetPdfDocument(), new Rectangle(260, 728, 15, 15), group, "German");
            PdfFormField.CreateRadioButton(doc.GetPdfDocument(), new Rectangle(330, 728, 15, 15), group, "Russian");
            PdfFormField.CreateRadioButton(doc.GetPdfDocument(), new Rectangle(400, 728, 15, 15), group, "Spanish");
            form.AddField(group);
            //Create checkboxes
            for (int i = 0; i < 3; i++)
            {
                PdfButtonFormField checkField = PdfFormField.CreateCheckBox(doc.GetPdfDocument(), new Rectangle(119 + i *
                                                                                                                69, 701, 15, 15), String.Concat("experience", (i + 1).ToString()), "Off", PdfFormField.TYPE_CHECK);
                form.AddField(checkField);
            }
            //Create combobox
            String[]           options     = new String[] { "Any", "6.30 am - 2.30 pm", "1.30 pm - 9.30 pm" };
            PdfChoiceFormField choiceField = PdfFormField.CreateComboBox(doc.GetPdfDocument(), new Rectangle(163, 676,
                                                                                                             115, 15), "shift", "Any", options);

            form.AddField(choiceField);
            //Create multiline text field
            PdfTextFormField infoField = PdfTextFormField.CreateMultilineText(doc.GetPdfDocument(), new Rectangle(158,
                                                                                                                  625, 366, 40), "info", "");

            form.AddField(infoField);
            //Create push button field
            PdfButtonFormField button = PdfFormField.CreatePushButton(doc.GetPdfDocument(), new Rectangle(479, 594, 45
                                                                                                          , 15), "reset", "RESET");

            button.SetAction(PdfAction.CreateResetForm(new String[] { "name", "language", "experience1", "experience2"
                                                                      , "experience3", "shift", "info" }, 0));
            form.AddField(button);
            return(form);
        }
 private void AddFormFieldsToDocument(PdfDocument pdfDoc, PdfAcroForm acroForm) {
     Rectangle rect = new Rectangle(36, 700, 20, 20);
     Rectangle rect1 = new Rectangle(36, 680, 20, 20);
     PdfButtonFormField group = PdfFormField.CreateRadioGroup(pdfDoc, "TestGroup", "1");
     PdfFormField.CreateRadioButton(pdfDoc, rect, group, "1");
     PdfFormField.CreateRadioButton(pdfDoc, rect1, group, "2");
     acroForm.AddField(group);
     PdfButtonFormField pushButton = PdfFormField.CreatePushButton(pdfDoc, new Rectangle(36, 650, 40, 20), "push"
         , "Capcha");
     PdfButtonFormField checkBox = PdfFormField.CreateCheckBox(pdfDoc, new Rectangle(36, 560, 20, 20), "TestCheck"
         , "1");
     acroForm.AddField(pushButton);
     acroForm.AddField(checkBox);
 }
        public virtual void PdfAButtonFieldTest()
        {
            PdfDocument pdf;
            Stream      @is      = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            String      file     = "pdfAButtonField.pdf";
            String      filename = destinationFolder + file;

            pdf = new PdfADocument(new PdfWriter(new FileStream(filename, FileMode.Create)), PdfAConformanceLevel.PDF_A_1B
                                   , new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB ICC preference", @is));
            PageSize pageSize = PageSize.LETTER;
            Document doc      = new Document(pdf, pageSize);

            PdfFontFactory.Register(sourceFolder + "FreeSans.ttf", sourceFolder + "FreeSans.ttf");
            PdfFont            font  = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", true);
            PdfButtonFormField group = PdfFormField.CreateRadioGroup(pdf, "group", "", PdfAConformanceLevel.PDF_A_1B);

            group.SetReadOnly(true);
            Paragraph p = new Paragraph();
            Text      t = new Text("supported");

            t.SetFont(font);
            p.Add(t);
            Image     ph = new Image(new PdfFormXObject(new Rectangle(10, 10)));
            Paragraph pc = new Paragraph().Add(ph);

            PdfAFormFieldTest.PdfAButtonFieldTestRenderer r = new PdfAFormFieldTest.PdfAButtonFieldTestRenderer(pc, group
                                                                                                                , "v1");
            pc.SetNextRenderer(r);
            p.Add(pc);
            Paragraph pc1 = new Paragraph().Add(ph);

            PdfAFormFieldTest.PdfAButtonFieldTestRenderer r1 = new PdfAFormFieldTest.PdfAButtonFieldTestRenderer(pc, group
                                                                                                                 , "v2");
            pc1.SetNextRenderer(r1);
            Paragraph p2 = new Paragraph();
            Text      t2 = new Text("supported 2");

            t2.SetFont(font);
            p2.Add(t2).Add(pc1);
            doc.Add(p);
            doc.Add(p2);
            //set generateAppearance param to false to retain custom appearance
            group.SetValue("v1", false);
            PdfAcroForm.GetAcroForm(pdf, true).AddField(group);
            pdf.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp/PdfAFormFieldTest/cmp_"
                                                                             + file, destinationFolder, "diff_"));
        }
Beispiel #9
0
        public virtual void DefaultRadiobuttonFieldTest()
        {
            String             file     = "defaultRadiobuttonFieldTest.pdf";
            String             filename = destinationFolder + file;
            PdfDocument        pdfDoc   = new PdfDocument(new PdfWriter(filename));
            PdfAcroForm        form     = PdfAcroForm.GetAcroForm(pdfDoc, true);
            Rectangle          rect1    = new Rectangle(36, 700, 20, 20);
            Rectangle          rect2    = new Rectangle(36, 680, 20, 20);
            PdfButtonFormField group    = PdfFormField.CreateRadioGroup(pdfDoc, "TestGroup", "1");

            PdfFormField.CreateRadioButton(pdfDoc, rect1, group, "1");
            PdfFormField.CreateRadioButton(pdfDoc, rect2, group, "2");
            form.AddField(group);
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp_" + file, destinationFolder
                                                                             , "diff_"));
        }
Beispiel #10
0
        public virtual void CustomizedRadiobuttonFieldTest()
        {
            String             file     = "customizedRadiobuttonFieldTest.pdf";
            String             filename = destinationFolder + file;
            PdfDocument        pdfDoc   = new PdfDocument(new PdfWriter(filename));
            PdfAcroForm        form     = PdfAcroForm.GetAcroForm(pdfDoc, true);
            Rectangle          rect1    = new Rectangle(36, 700, 20, 20);
            Rectangle          rect2    = new Rectangle(36, 680, 20, 20);
            PdfButtonFormField group2   = PdfFormField.CreateRadioGroup(pdfDoc, "TestGroup2", "1");

            PdfFormField.CreateRadioButton(pdfDoc, rect1, group2, "1").SetBorderWidth(2).SetBorderColor(ColorConstants
                                                                                                        .RED).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetVisibility(PdfFormField.VISIBLE);
            PdfFormField.CreateRadioButton(pdfDoc, rect2, group2, "2").SetBorderWidth(2).SetBorderColor(ColorConstants
                                                                                                        .RED).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetVisibility(PdfFormField.VISIBLE);
            form.AddField(group2);
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp_" + file, destinationFolder
                                                                             , "diff_"));
        }
        public virtual void PdfA1DocWithPdfA1RadioButtonFieldTest()
        {
            String name     = "pdfA1DocWithPdfA1RadioButtonField";
            String fileName = destinationFolder + name + ".pdf";
            String cmp      = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1RadioButtonField.pdf";
            Stream @is      = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_1B;
            PdfADocument         pdfDoc           = new PdfADocument(new PdfWriter(fileName), conformanceLevel, new PdfOutputIntent("Custom"
                                                                                                                                    , "", "http://www.color.org", "sRGB IEC61966-2.1", @is));
            PdfAcroForm        form       = PdfAcroForm.GetAcroForm(pdfDoc, true);
            PdfButtonFormField radioGroup = PdfFormField.CreateRadioGroup(pdfDoc, "radio group", "", conformanceLevel);

            PdfFormField.CreateRadioButton(pdfDoc, new Rectangle(36, 496, 20, 20), radioGroup, "1", conformanceLevel).
            SetBorderWidth(2).SetBorderColor(ColorConstants.ORANGE);
            PdfFormField.CreateRadioButton(pdfDoc, new Rectangle(66, 496, 20, 20), radioGroup, "2", conformanceLevel).
            SetBorderWidth(2).SetBorderColor(ColorConstants.ORANGE);
            form.AddField(radioGroup);
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, destinationFolder));
            NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName));
        }
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);

            // Radio buttons will be added to this radio group
            PdfButtonFormField group = PdfFormField.CreateRadioGroup(pdfDoc, "Language", "");

            Table table = new Table(UnitValue.CreatePercentArray(2)).UseAllAvailableWidth();
            Cell  cell  = new Cell().Add(new Paragraph("English"));

            table.AddCell(cell);

            cell = new Cell();

            // The renderer creates radio button for the current radio group in the current cell
            cell.SetNextRenderer(new AddRadioButtonRenderer(cell, group, "english"));
            table.AddCell(cell);

            cell = new Cell().Add(new Paragraph("French"));
            table.AddCell(cell);

            cell = new Cell();
            cell.SetNextRenderer(new AddRadioButtonRenderer(cell, group, "french"));
            table.AddCell(cell);

            cell = new Cell().Add(new Paragraph("Dutch"));
            table.AddCell(cell);

            cell = new Cell();
            cell.SetNextRenderer(new AddRadioButtonRenderer(cell, group, "dutch"));
            table.AddCell(cell);

            doc.Add(table);

            form.AddField(group);

            doc.Close();
        }
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);

            // Radio buttons will be added to this radio group
            PdfButtonFormField radioGroup = PdfFormField.CreateRadioGroup(pdfDoc, "answer", "answer 1");

            Table table = new Table(UnitValue.CreatePercentArray(2)).UseAllAvailableWidth();

            for (int i = 0; i < 25; i++)
            {
                Cell cell = new Cell().Add(new Paragraph("Question " + i));
                table.AddCell(cell);

                cell = new Cell().Add(new Paragraph("Answer " + i));
                table.AddCell(cell);
            }

            for (int i = 0; i < 25; i++)
            {
                Cell cell = new Cell().Add(new Paragraph("Radio: " + i));
                table.AddCell(cell);

                cell = new Cell();

                // The renderer creates radio button for the current radio group in the current cell
                cell.SetNextRenderer(new AddRadioButtonRenderer(cell, radioGroup, "answer " + i));
                table.AddCell(cell);
            }

            doc.Add(table);

            form.AddField(radioGroup);

            pdfDoc.Close();
        }