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?