1
votes

I developed an Editable PDF using iTextSharp

My Code is:

//Creating a document
        Document document = new Document(PageSize.A4, 50, 50, 25, 25);

        FileStream pdfFileStream = new FileStream("D:\\new.pdf", FileMode.Create);

//Writing to PDF
        using (PdfWriter pdfWriter = PdfWriter.GetInstance(document, pdfFileStream))
        {
            //Opening the document for writing
            document.Open();
            PdfContentByte cb = pdfWriter.DirectContent;

            Paragraph para = new Paragraph("Name");
            document.Add(para);

            //Creating the text box starts here --->
            TextField _text = new TextField(pdfWriter, new Rectangle(100, 806, 170, 790), "Name");
            _text.BackgroundColor = BaseColor.LIGHT_GRAY;
            _text.Alignment = Element.ALIGN_CENTER;
            //_text.Options = TextField.MULTILINE;
            _text.Text = "";
            pdfWriter.AddAnnotation(_text.GetTextField());
            cb = pdfWriter.DirectContent;

            //Creating the text box ends here ---<

            //Creating the RadioButton group starts here ---->

            PdfFormField _radioGroup = PdfFormField.CreateRadioButton(pdfWriter, true);
            _radioGroup.FieldName = "Gender";

            string[] genders = { "Male", "Female" };

            RadioCheckField genderRadioCheckField;
            PdfFormField radioGField;

            for (int i = 0; i < genders.Length; i++)
            {
                genderRadioCheckField = new RadioCheckField(pdfWriter, new Rectangle(40, 806 - i * 40, 60, 788 - i * 40), null, genders[i]);

                genderRadioCheckField.BackgroundColor = BaseColor.LIGHT_GRAY;
                genderRadioCheckField.CheckType = RadioCheckField.TYPE_CIRCLE;

                radioGField = genderRadioCheckField.RadioField;
                ColumnText.ShowTextAligned(cb, Element.ALIGN_LEFT, new Phrase(genders[i], new Font(Font.FontFamily.HELVETICA, 12)), 70, 790 - i * 40, 0);
                _radioGroup.AddKid(radioGField);

            }

            pdfWriter.AddAnnotation(_radioGroup);
            cb = pdfWriter.DirectContent;
            //Creating the RadioButton group ends here ----<



            //Closing the document for writing
            document.Close();

            Console.WriteLine("Completed");
            Console.ReadLine();

        }

Now, the code generates the Editable PDF with the Text Field and a Radio Button.

Problem is:

I opened the generated PDF File using Adobe Reader and entered some text in the Text Field and Tried to save it.

I don't find any save option under File menu, but I also tried using Save As--> PDF, it shows message as:

"This document does not allow you to save any changes you have made to it unless you are using Adobe Acrobat X standard,Adobe Acrobat X pro,Adobe Acrobat X knowledge worker suite. You will be only saving the copy of the document. Do you want to continue?"

How to enable save option in Adobe PDF Reader?. Is there any problem with my C# code?

3
Have you tried a more current Adobe Reader version? If i remember correctly Adobe now allows saving filled forms by default.mkl
Works fine!! But I have downloaded one file and in that file I edited and saved the document. I dont know how it worked for that and not for this. Anyway, thanksVikash
To support mkl, update your Adobe Reader to a current version. From the error message you get, it looks as if you have Adobe Reader X, which is now a good 5 years old, and reaches end of life soon. Reader XI and newer allow saving filled forms without Extended Rights.Max Wyss

3 Answers

3
votes

You want to Reader enable your PDF. Reader enabling involves adding a digital signature using a private key owned by Adobe. When Adobe Reader detects that signature and when the signature is valid, Adobe Reader unlocks functionality that is otherwise only available in Adobe Acrobat (depending on the usage rights you defined when signing the document).

There is no problem with your C#. The main problem is that you are asking for functionality that requires access to a private key owned by Adobe. No third party product is granted access to that key. You can only reader enable a PDF document using Adobe software. It would be illegal for iText, iTextSharp, or any other software other than an Adobe product to Reader enable a document.

Summarized: you are asking for functionality that is only available when using Adobe software. No third party vendor is allowed to provide that functionality (unless they have a license to do so from Adobe).

2
votes

Solution:

I used Adobe Reader X which is not supporting the save option if we use iTextSharp.dll. And finally, I downloaded the Adobe Reader DC the latest version and it works fine. Now, I can edit and save my document. Thanks for all the other responses.

-1
votes

Try using BullZIP PDF Printer which prints to disk