Ejemplo n.º 1
0
        public virtual void CreatePDF(String dest)
        {
            // Create a new pdf based on the resource one
            PdfDocument pdfDocument = new PdfDocument(new PdfReader(RESOURCE_FOLDER + INPUT_FILE),
                                                      new PdfWriter(dest));

            PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "NotoNaskhArabic-Regular.ttf",
                                                     PdfEncodings.IDENTITY_H);

            // Embed entire font without any subsetting. Please note that without subset it's impossible to edit a form field
            // with the predefined font
            font.SetSubset(false);

            // في القيام بنشاط
            String text = "\u0641\u064A\u0020\u0627\u0644\u0642\u064A\u0627\u0645\u0020\u0628\u0646\u0634\u0627\u0637";

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

            // Set needAppearance value to false in order to hide the text of the form fields
            form.SetNeedAppearances(false);

            // Update the value and some other properties of all the pdf document's form fields
            foreach (KeyValuePair <String, PdfFormField> entry in form.GetFormFields())
            {
                PdfFormField field = entry.Value;
                field.SetValue(text);
                field.SetFont(font).SetJustification(2);
            }

            pdfDocument.Close();
        }
Ejemplo n.º 2
0
        protected void ManipulatePdf(String dest)
        {
            // CreateForm() method creates a temporary document in the memory,
            // which then will be used as a source while writing to a real document
            byte[] content             = CreateForm();
            IRandomAccessSource source = new RandomAccessSourceFactory().CreateSource(content);
            PdfDocument         pdfDoc = new PdfDocument(new PdfReader(source, new ReaderProperties()), new PdfWriter(dest));
            PdfAcroForm         form   = PdfAcroForm.GetAcroForm(pdfDoc, true);

            //  Set a flag specifying whether to construct appearance streams and appearance dictionaries
            //  for all widget annotations in the document.
            form.SetNeedAppearances(true);

            form.GetField("text1")

            // Method sets the flag, specifying whether or not the field can be changed.
            .SetReadOnly(true)
            .SetValue("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z");

            form.GetField("text2")
            .SetReadOnly(true)
            .SetValue("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z");

            form.GetField("text3")
            .SetReadOnly(true)
            .SetValue("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z");

            form.GetField("text4")
            .SetReadOnly(true)
            .SetValue("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z");

            pdfDoc.Close();
        }
Ejemplo n.º 3
0
        public virtual void SetNeedAppearancesTest()
        {
            PdfDocument outputDoc = CreateDocument();
            PdfAcroForm acroForm  = PdfAcroForm.GetAcroForm(outputDoc, true);

            acroForm.SetNeedAppearances(false);
            bool      isModified         = acroForm.GetPdfObject().IsModified();
            bool      isReleaseForbidden = acroForm.GetPdfObject().IsReleaseForbidden();
            PdfObject needAppearance     = acroForm.GetPdfObject().Get(PdfName.NeedAppearances);

            outputDoc.Close();
            NUnit.Framework.Assert.AreEqual(new PdfBoolean(false), needAppearance);
            NUnit.Framework.Assert.IsTrue(isModified);
            NUnit.Framework.Assert.IsTrue(isReleaseForbidden);
        }
Ejemplo n.º 4
0
        public virtual void RegenerateAppearance2()
        {
            String      input    = "regenerateAppearance2.pdf";
            String      output   = "regenerateAppearance2.pdf";
            PdfDocument document = new PdfDocument(new PdfReader(sourceFolder + input), new PdfWriter(destinationFolder
                                                                                                      + output), new StampingProperties().UseAppendMode());
            PdfAcroForm acro = PdfAcroForm.GetAcroForm(document, false);

            acro.SetNeedAppearances(true);
            PdfFormField field = acro.GetField("number");

            field.SetValue("20150044DR");
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + output, sourceFolder
                                                                             + "cmp_" + output, destinationFolder, "diff"));
        }
Ejemplo n.º 5
0
        public virtual void SetNeedAppearancesInPdf2Test()
        {
            PdfDocument outputDoc = new PdfDocument(new PdfWriter(new ByteArrayOutputStream(), new WriterProperties().
                                                                  SetPdfVersion(PdfVersion.PDF_2_0)));

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

            acroForm.SetNeedAppearances(false);
            bool      isModified         = acroForm.GetPdfObject().IsModified();
            bool      isReleaseForbidden = acroForm.GetPdfObject().IsReleaseForbidden();
            PdfObject needAppearance     = acroForm.GetPdfObject().Get(PdfName.NeedAppearances);

            outputDoc.Close();
            NUnit.Framework.Assert.IsNull(needAppearance);
            NUnit.Framework.Assert.IsTrue(isModified);
            NUnit.Framework.Assert.IsTrue(isReleaseForbidden);
        }