Example #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);
            }
        }
Example #2
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);

            PdfTextFormField field = PdfFormField.CreateText(pdfDoc,
                                                             new Rectangle(36, 788, 523, 18), "myfile", "");

            // If true is passed, then the text entered in the field will represent the pathname of a file
            // whose contents are to be submitted as the value of the field.
            field.SetFileSelect(true);

            // When the mouse is released inside the annotation's area (that's what PdfName.U stands for),
            // then the focus will be set on the "mytitle" field.
            field.SetAdditionalAction(PdfName.U, PdfAction.CreateJavaScript(
                                          "this.getField('myfile').browseForFileToSubmit();"
                                          + "this.getField('mytitle').setFocus();"));
            form.AddField(field);

            PdfTextFormField title = PdfFormField.CreateText(pdfDoc,
                                                             new Rectangle(36, 752, 523, 18), "mytitle", "");

            form.AddField(title);

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

            Document doc = new Document(pdfDoc);

            doc.Add(new Paragraph("This is a paragraph.\nForm field will be inserted after it"));

            float fieldHeight = 20;
            float fieldWidth  = 100;

            // 1st method: calculate position and create form field, using document's root layout area
            Rectangle        freeBBox = doc.GetRenderer().GetCurrentArea().GetBBox();
            float            top      = freeBBox.GetTop();
            PdfTextFormField field    = PdfFormField.CreateText(pdfDoc,
                                                                new Rectangle(freeBBox.GetLeft(), top - fieldHeight, fieldWidth, fieldHeight), "myField", "Value");

            form.AddField(field);

            doc.Add(new AreaBreak());

            // 2nd method: create field using custom renderer
            doc.Add(new Paragraph("This is another paragraph.\nForm field will be inserted right after it."));
            doc.Add(new TextFieldLayoutElement().SetWidth(fieldWidth).SetHeight(fieldHeight));
            doc.Add(new Paragraph("This paragraph follows the form field"));

            pdfDoc.Close();
        }
Example #4
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)
        {
            font.SetSubset(false);
            String    value    = GetDefaultValue();
            String    name     = GetModelId();
            UnitValue fontSize = (UnitValue)this.GetPropertyAsUnitValue(Property.FONT_SIZE);

            if (!fontSize.IsPointValue())
            {
                ILog logger = LogManager.GetLogger(typeof(iText.Html2pdf.Attach.Impl.Layout.Form.Renderer.TextAreaRenderer
                                                          ));
                logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property
                                                      .FONT_SIZE));
            }
            PdfDocument  doc        = drawContext.GetDocument();
            Rectangle    area       = flatRenderer.GetOccupiedArea().GetBBox().Clone();
            PdfPage      page       = doc.GetPage(occupiedArea.GetPageNumber());
            PdfFormField inputField = PdfFormField.CreateText(doc, area, name, value, font, fontSize.GetValue());

            inputField.SetFieldFlag(PdfFormField.FF_MULTILINE, true);
            inputField.SetDefaultValue(new PdfString(GetDefaultValue()));
            ApplyDefaultFieldProperties(inputField);
            PdfAcroForm.GetAcroForm(doc, true).AddField(inputField, page);
            WriteAcroFormFieldLangAttribute(doc);
        }
Example #5
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                PdfFormField field = PdfFormField.CreateText(drawContext.GetDocument(),
                                                             GetOccupiedAreaBBox(), name);

                PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true).AddField(field);
            }
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);

                PdfAcroForm      form  = PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true);
                PdfTextFormField field = PdfFormField.CreateText(drawContext.GetDocument(),
                                                                 occupiedArea.GetBBox(), "myField2", "Another Value");

                form.AddField(field);
            }
        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();
        }
        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);
        }
Example #9
0
        public virtual void ReplaceFieldTest()
        {
            String      outputFile = "replaceFieldTest.pdf";
            PdfDocument outputDoc  = new PdfDocument(new PdfReader(INPUT_FILE_WITH_TWO_FORM_FIELDS), new PdfWriter(DESTINATION_DIR
                                                                                                                   + 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);
        }
        private static void CreateInputFileWithIndirectFieldsArray()
        {
            PdfDocument document = new PdfDocument(new PdfWriter(inputFileWithIndirectFieldsArray));

            document.AddNewPage();
            PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(document, true);

            acroForm.GetFields().MakeIndirect(document);
            acroForm.AddField(PdfFormField.CreateText(document, new Rectangle(20, 160, 100, 20), "textfield1", "text1"
                                                      ));
            acroForm.AddField(PdfFormField.CreateText(document, new Rectangle(20, 130, 100, 20), "textfield2", "text2"
                                                      ));
            document.Close();
        }
Example #11
0
            override public void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                iText.Kernel.Geom.Rectangle cuadro = GetOccupiedAreaBBox();
                cuadro.MoveUp(margenExterior).MoveRight(margenExterior);
                cuadro.SetHeight(cuadro.GetHeight() - (margenExterior * 2));
                cuadro.SetWidth(cuadro.GetWidth() - (margenExterior * 2));
                PdfTextFormField field = PdfFormField.CreateText(drawContext.GetDocument(), cuadro, fieldName, valor);

                field.SetJustification(justificacion);
                field.SetVisibility(PdfFormField.VISIBLE);
                field.SetFontSize(fontSize);
                PdfAcroForm form = PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true);

                form.AddField(field);
            }
Example #12
0
        public virtual byte[] CreateForm()
        {
            ByteArrayOutputStream baos   = new ByteArrayOutputStream();
            PdfDocument           pdfDoc = new PdfDocument(new PdfWriter(baos));
            Rectangle             rect   = new Rectangle(36, 720, 108, 86);

            PdfTextFormField textFormField = PdfFormField.CreateText(pdfDoc, rect, FIELD_NAME, "text");

            // Being set as true, the field can contain multiple lines of text;
            // if false, the field's text is restricted to a single line.
            textFormField.SetMultiline(true);
            PdfAcroForm.GetAcroForm(pdfDoc, true).AddField(textFormField);

            pdfDoc.Close();

            return(baos.ToArray());
        }
Example #13
0
        public virtual void AddFieldWithKidsTest()
        {
            PdfDocument  pdfDoc = new PdfDocument(new PdfWriter(new ByteArrayOutputStream()));
            PdfAcroForm  form   = PdfAcroForm.GetAcroForm(pdfDoc, true);
            PdfFormField root   = PdfFormField.CreateEmptyField(pdfDoc);

            root.SetFieldName("root");
            PdfFormField child = PdfFormField.CreateEmptyField(pdfDoc);

            child.SetFieldName("child");
            root.AddKid(child);
            PdfTextFormField text1 = PdfFormField.CreateText(pdfDoc, new Rectangle(100, 700, 200, 20), "text1", "test"
                                                             );

            child.AddKid(text1);
            form.AddField(root);
            NUnit.Framework.Assert.AreEqual(3, form.GetFormFields().Count);
        }
Example #14
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));

            PdfFormField personal = PdfFormField.CreateEmptyField(pdfDoc);

            personal.SetFieldName("personal");
            PdfTextFormField name = PdfFormField.CreateText(pdfDoc,
                                                            new Rectangle(36, 760, 108, 30), "name", "");

            personal.AddKid(name);
            PdfTextFormField password = PdfFormField.CreateText(pdfDoc,
                                                                new Rectangle(150, 760, 300, 30), "password", "");

            personal.AddKid(password);
            PdfAcroForm.GetAcroForm(pdfDoc, true).AddField(personal, pdfDoc.GetFirstPage());

            pdfDoc.Close();
        }
Example #15
0
        public virtual void FormFieldTest02()
        {
            String           filename = destinationFolder + "formFieldTest02.pdf";
            PdfDocument      pdfDoc   = new PdfDocument(new PdfWriter(filename));
            PdfAcroForm      form     = PdfAcroForm.GetAcroForm(pdfDoc, true);
            Rectangle        rect     = new Rectangle(210, 490, 150, 22);
            PdfTextFormField field    = PdfFormField.CreateText(pdfDoc, rect, "fieldName", "some value");

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

            if (errorMessage != null)
            {
                NUnit.Framework.Assert.Fail(errorMessage);
            }
        }
Example #16
0
        public byte[] CreateForm()
        {
            ByteArrayOutputStream baos   = new ByteArrayOutputStream();
            PdfDocument           pdfDoc = new PdfDocument(new PdfWriter(baos));
            PdfFont     font             = PdfFontFactory.CreateFont();
            PdfAcroForm form             = PdfAcroForm.GetAcroForm(pdfDoc, true);

            Rectangle        rect      = new Rectangle(36, 770, 104, 36);
            PdfTextFormField textField = PdfFormField.CreateText(pdfDoc, rect, "text",
                                                                 "text", font, 20f);

            // Being set as true, the field can contain multiple lines of text;
            // if false, the field's text is restricted to a single line.
            textField.SetMultiline(true);
            form.AddField(textField);

            pdfDoc.Close();

            return(baos.ToArray());
        }
        public virtual void PdfA1DocWithPdfA1TextFieldTest()
        {
            String  name         = "pdfA1DocWithPdfA1TextField";
            String  fileName     = destinationFolder + name + ".pdf";
            String  cmp          = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1TextField.pdf";
            PdfFont fontFreeSans = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", true);

            fontFreeSans.SetSubset(false);
            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);

            form.AddField(PdfFormField.CreateText(pdfDoc, new Rectangle(36, 466, 90, 20), "text", "textField", fontFreeSans
                                                  , 12, false, conformanceLevel).SetValue("iText"));
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, destinationFolder));
            NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName));
        }
Example #18
0
        public virtual void AutoScaleFontSizeInFormFields()
        {
            String       outPdf = destinationFolder + "autoScaleFontSizeInFormFields.pdf";
            String       cmpPdf = sourceFolder + "cmp_autoScaleFontSizeInFormFields.pdf";
            PdfWriter    writer = new PdfWriter(outPdf);
            PdfDocument  pdfDoc = new PdfDocument(writer);
            PdfAcroForm  form   = PdfAcroForm.GetAcroForm(pdfDoc, true);
            PdfFormField field  = PdfFormField.CreateText(pdfDoc, new Rectangle(36, 786, 80, 20), "name", "TestValueAndALittleMore"
                                                          );

            form.AddField(field.SetFontSizeAutoScale());
            pdfDoc.Close();
            CompareTool compareTool  = new CompareTool();
            String      errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");

            if (errorMessage != null)
            {
                NUnit.Framework.Assert.Fail(errorMessage);
            }
        }
        public virtual void FormFieldTest03()
        {
            PdfReader        reader   = new PdfReader(sourceFolder + "formFieldFile.pdf");
            String           filename = destinationFolder + "formFieldTest03.pdf";
            PdfWriter        writer   = new PdfWriter(new FileStream(filename, FileMode.Create));
            PdfDocument      pdfDoc   = new PdfDocument(reader, writer);
            PdfAcroForm      form     = PdfAcroForm.GetAcroForm(pdfDoc, true);
            PdfPage          page     = pdfDoc.GetFirstPage();
            Rectangle        rect     = new Rectangle(210, 490, 150, 22);
            PdfTextFormField field    = PdfFormField.CreateText(pdfDoc, rect, "TestField", "some value");

            form.AddField(field, page);
            pdfDoc.Close();
            CompareTool compareTool  = new CompareTool();
            String      errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_formFieldTest03.pdf", destinationFolder
                                                                    , "diff_");

            if (errorMessage != null)
            {
                NUnit.Framework.Assert.Fail(errorMessage);
            }
        }
Example #20
0
        public virtual void FlushedPagesTest()
        {
            String      filename = destinationFolder + "flushedPagesTest.pdf";
            PdfDocument pdfDoc   = new PdfDocument(new PdfWriter(filename));

            pdfDoc.AddNewPage().Flush();
            pdfDoc.AddNewPage().Flush();
            pdfDoc.AddNewPage();
            PdfTextFormField field = PdfFormField.CreateText(pdfDoc, new Rectangle(100, 100, 300, 20), "name", "");
            PdfAcroForm      form  = PdfAcroForm.GetAcroForm(pdfDoc, true);

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

            if (errorMessage != null)
            {
                NUnit.Framework.Assert.Fail(errorMessage);
            }
        }
Example #21
0
        public virtual void FormFieldTest04()
        {
            String      filename = destinationFolder + "formFieldTest04.pdf";
            PdfDocument pdfDoc   = new PdfDocument(new PdfReader(sourceFolder + "formFieldFile.pdf"), new PdfWriter(filename
                                                                                                                    ));
            PdfAcroForm      form  = PdfAcroForm.GetAcroForm(pdfDoc, true);
            PdfPage          page  = pdfDoc.GetFirstPage();
            Rectangle        rect  = new Rectangle(210, 490, 150, 22);
            PdfTextFormField field = PdfFormField.CreateText(pdfDoc, rect, "TestField", "some value in courier font",
                                                             PdfFontFactory.CreateFont(StandardFonts.COURIER), 10);

            form.AddField(field, page);
            pdfDoc.Close();
            CompareTool compareTool  = new CompareTool();
            String      errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_formFieldTest04.pdf", destinationFolder
                                                                    , "diff_");

            if (errorMessage != null)
            {
                NUnit.Framework.Assert.Fail(errorMessage);
            }
        }
Example #22
0
        public static void GenerateForm(string filename, IEnumerable <FormField> formFields)
        {
            var pdfDocument = new PdfDocument(new PdfWriter(filename));
            var document    = new Document(pdfDocument);
            var form        = PdfAcroForm.GetAcroForm(pdfDocument, true);

            var xPosition          = 20;
            var yPosition          = 800;
            var fieldSpacingHeight = 20;

            foreach (var formField in formFields)
            {
                if (formField.FieldType == FormFieldType.TextBox)
                {
                    var width  = 100;
                    var height = 20;

                    var rectangle = new Rectangle(xPosition, yPosition, width, height);
                    var field     = PdfFormField.CreateText(document.GetPdfDocument(), rectangle, formField.FieldName, "");
                    form.AddField(field);

                    yPosition -= height;
                }
                if (formField.FieldType == FormFieldType.CheckBox)
                {
                    var width  = 20;
                    var height = 20;

                    var rectangle = new Rectangle(xPosition, yPosition, width, height);
                    var field     = PdfFormField.CreateCheckBox(document.GetPdfDocument(), rectangle, formField.FieldName, "");
                    form.AddField(field);

                    yPosition -= height;
                }
                yPosition -= fieldSpacingHeight;
            }
            document.Close();
        }
        public virtual void NotFittingByHeightTest()
        {
            String      filename = "notFittingByHeightTest.pdf";
            PdfDocument pdfDoc   = new PdfDocument(new PdfWriter(destinationFolder + filename));
            PdfAcroForm form     = PdfAcroForm.GetAcroForm(pdfDoc, true);

            for (int i = 15; i <= 50; i += 15)
            {
                PdfFormField[] fields = new PdfFormField[] { PdfFormField.CreateMultilineText(pdfDoc, new Rectangle(100, 800
                                                                                                                    - i * 4, 150, i), "multi " + i, "MULTI"), PdfFormField.CreateText(pdfDoc, new Rectangle(300, 800 - i
                                                                                                                                                                                                            * 4, 150, i), "single " + i, "SINGLE") };
                foreach (PdfFormField field in fields)
                {
                    field.SetFontSize(40);
                    field.SetBorderColor(ColorConstants.BLACK);
                    form.AddField(field);
                }
            }
            pdfDoc.Close();
            CompareTool compareTool  = new CompareTool();
            String      errorMessage = compareTool.CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename
                                                                    , destinationFolder, "diff_");

            if (errorMessage != null)
            {
                NUnit.Framework.Assert.Fail(errorMessage);
            }
        }
Example #24
0
        public Task WriteAnnotatedPdfAsync(string pdfDocumentPath, IEnumerable <IAnnotation> annotations, string filePath)
        {
            using (var reader = new PdfReader(pdfDocumentPath))
                using (var outFile = File.Open(filePath, FileMode.Create))
                    using (var writer = new PdfWriter(outFile))
                        using (var doc = new PdfDocument(reader, writer))
                        {
                            var acroForm = PdfAcroForm.GetAcroForm(doc, true);
                            foreach (var ann in annotations)
                            {
                                var targets = ann.SelectedTargets;
                                if (targets == null || targets.Count < 1)
                                {
                                    targets = ann.Subject.Appearances ?? throw new ArgumentException($"The subject word {ann.Subject.Text} for a given annotation has no appearances.");
                                }
                                foreach (var trg in targets)
                                {
                                    var page = doc.GetPage(trg.Parent.Index + 1);

                                    var font       = PdfFontFactory.CreateRegisteredFont(iText.IO.Font.Constants.StandardFonts.HELVETICA);
                                    var coord      = trg.GetPdfCoords();
                                    var buttonRect = new Rectangle(coord.Llx, coord.Lly, coord.width, coord.height);
                                    var txRect     = GetAnnotationRect(buttonRect, font, ann, trg);

                                    var textFieldName = Guid.NewGuid().ToString("n");
                                    var textField     = PdfFormField.CreateText(doc, txRect, textFieldName);
                                    textField.SetValue(ann.Content, font, FontSize);
                                    textField.SetColor(ColorConstants.DARK_GRAY);
                                    textField.SetBackgroundColor(ColorConstants.LIGHT_GRAY);
                                    textField.SetReadOnly(true);
                                    textField.SetMultiline(true);
                                    textField.SetVisibility(PdfFormField.HIDDEN);
                                    textField.SetBorderColor(ColorConstants.LIGHT_GRAY);
                                    textField.SetFieldFlags(4097);

                                    acroForm.AddField(textField, page);

                                    var enter = PdfAction.CreateHide(textFieldName, false);
                                    var exit  = PdfAction.CreateHide(textFieldName, true);

                                    var btn = PdfFormField.CreatePushButton(doc, buttonRect, Guid.NewGuid().ToString("n"),
                                                                            string.Empty);
                                    btn.SetBackgroundColor(null);
                                    btn.SetBorderWidth(0);
                                    btn.SetAdditionalAction(PdfName.E, enter);
                                    btn.SetAdditionalAction(PdfName.X, exit);
                                    acroForm.AddField(btn, page);

                                    var underline = PdfTextMarkupAnnotation.CreateUnderline(new Rectangle(buttonRect.GetX(), buttonRect.GetY() - 2, buttonRect.GetWidth(), 3),
                                                                                            new float[]
                                    {
                                        buttonRect.GetX() + buttonRect.GetWidth(), buttonRect.GetY() + buttonRect.GetHeight(),
                                        buttonRect.GetX(), buttonRect.GetY() + buttonRect.GetHeight(),
                                        buttonRect.GetX() + buttonRect.GetWidth(), buttonRect.GetY() - 2,
                                        buttonRect.GetX(), buttonRect.GetY() - 2,
                                    });
                                    underline.SetColor(ColorConstants.YELLOW);
                                    page.AddAnnotation(underline);
                                }
                            }
                        }
            return(Task.CompletedTask);
        }
        // GET: Todos/Delete/5
        public ActionResult GetPDF(int?id)
        {
            Trace.WriteLine("GET /Todos/GetPDF/" + id);
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Todo todo = db.Todoes.Find(id);

            if (todo == null)
            {
                return(HttpNotFound());
            }

            //string filePath = HttpRuntime.AppDomainAppPath + "/PDF/NewEmployeeDetails.pdf";
            //string filePathFilled = HttpRuntime.AppDomainAppPath + "/PDF/NewEmployeeDetailsFilled.pdf";
            string filePath       = MapPath("~/PDF/NewEmployeeDetails.pdf");
            string filePathFilled = MapPath("~/PDF/NewEmployeeDetailsFilled.pdf");

            PdfDocument pdf  = new PdfDocument(new PdfReader(filePath), new PdfWriter(filePathFilled));
            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdf, true);

            PdfFont fontHELVETICA = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);

            string AsAboveAddressVaule = todo.AsAboveAddress ? "Yes" : ""; // empty string is false

            form.GetField("First Name").SetValue(todo.FirstName);
            form.GetField("Last Name").SetValue(todo.LastName);
            form.GetField("Full Address").SetValue(todo.FullAddress);
            if (todo.MailingAddress != null && AsAboveAddressVaule.Length <= 0)
            {
                PdfTextFormField mailingAddress = PdfFormField.CreateText(pdf, new Rectangle(227, 607, 310, 30), "mailingAddress", todo.MailingAddress, fontHELVETICA, 18);
                form.AddField(mailingAddress);
            }
            else
            {
                form.GetField("As Above").SetCheckType(PdfFormField.TYPE_CHECK).SetValue(AsAboveAddressVaule);
            }

            form.GetField("Email Address").SetValue(todo.EmailAddress).SetJustification(PdfFormField.ALIGN_LEFT);
            PdfTextFormField phoneNumber = PdfFormField.CreateText(pdf, new Rectangle(145, 538, 392, 30), "phoneNumber", "0" + todo.PhoneNumber.ToString(), fontHELVETICA, 18);

            form.AddField(phoneNumber);
            form.GetField("Citizenship Statas").SetValue(todo.CitizenStatus).SetJustification(PdfFormField.ALIGN_LEFT);
            form.GetField("Employment Start Date").SetValue(todo.EmploymentStartDate.ToString()).SetJustification(PdfFormField.ALIGN_LEFT);
            form.GetField("Employment Type").SetValue(todo.EmploymentType).SetJustification(PdfFormField.ALIGN_LEFT);
            form.GetField("Position Title").SetValue(todo.PositionTitle).SetJustification(PdfFormField.ALIGN_LEFT);
            form.GetField("Name").SetValue(todo.EmergencyContactName);
            form.GetField("Relationship").SetValue(todo.EmergencyContactRelationship);
            PdfTextFormField emergencyContactPhoneNumber = PdfFormField.CreateText(pdf, new Rectangle(145, 275, 392, 30), "emergencyPhoneNumber", "0" + todo.EmergencyContactPhoneNumber.ToString(), fontHELVETICA, 18);

            form.AddField(emergencyContactPhoneNumber);

            if (todo.EmployeeSignature != null)
            {
                ImageData imageData = ImageDataFactory.CreatePng(todo.EmployeeSignature);
                Image     image     = new Image(imageData).ScaleAbsolute(200, 50).SetFixedPosition(1, 190, 180);
                Document  document  = new Document(pdf);
                document.Add(image);
            }

            form.FlattenFields();
            pdf.Close();

            return(File(filePathFilled, "application/pdf"));;
        }