Radio Button Hidden Item

For each 2-state radio button I create (see below), it actually creates 3 fields. One that has no name, is hidden, has no export value defined and defaults to the On/Off Adobe standard. Is there anyway to not create the hidden field?

formEditor.RadioGap = 40;

newFieldName = string.Format("q{0}", fieldName);

formEditor.Items = new string[] { bool.TrueString, bool.FalseString };

formEditor.AddField(Aspose.Pdf.Kit.FieldType.Radio, newFieldName, pageNumber, x + 20, y - 3, x + 32 , y + 9);

formEditor.RemoveField(fullName);

This still and issue. We send these pdf's for electronic signature and return the form fields. We use www.EchoSign.com. They have informed us that the PDF we send is in an invalid format, but also the Radio Buttons appear to have 3 fields for each one created. This is what they wrote.

___________________________________________

It definitely seems like the software you're using creates very mal-formed PDFs. For each 2-state radio button you're creating, it actually creates 3 fields one of which has no name, is hidden and has no export value defined (and therefore defaults to the On/Off Adobe standard).

We verified this is the issue but trying the following workaround --- make a copy of the document in Acrobat without the fields (e.g. print to a PDF driver), and then copy over all the named form fields in the document (but not the ones without a name). I've attached an example PDF. (You can't delete the fields directly, however; that will make Acrobat crash.)
____________________________________________
Attached is a screen shot of what they sent me. We have a client waiting this to be completed can you provide any help to us. We also just renewed our licenses with Aspose as well.
Thanks

Hi Chris,

Please share the input PDF file along with the complete code snippet you’re using at your end, so we could test and reproduce the issue at our end. You’ll be updated with the results accordingly.

We’re sorry for the inconvenience.
Regards,

Here is the code in question starting at ProcessPdfFields and attached is a pdf we are trying to add fields too. Let me know if you need anything else.

public void ProcessPdfFields(string pdfPath)

{

Aspose.Pdf.Kit.License lic = new Aspose.Pdf.Kit.License();

lic.SetLicense(Licensing.AsposePDFKitLicense);

string copyFieldsFromPdf = pdfPath;

string outputPdf = Path.Combine(Path.GetDirectoryName(pdfPath), string.Format("{0}.pdf", Path.GetFileNameWithoutExtension(Path.GetRandomFileName())));

Kit.PdfFileInfo orriginalPdfFileInfo = new Kit.PdfFileInfo(copyFieldsFromPdf);

int orriginalNumberOfPages = orriginalPdfFileInfo.NumberofPages;

Kit.PdfFileInfo emptyPdfFileInfo = new Kit.PdfFileInfo(copyFieldsFromPdf);

int emptyNumberOfPages = emptyPdfFileInfo.NumberofPages;

Kit.PdfFileEditor pdfFileEditor = new Kit.PdfFileEditor();

MemoryStream[] orriginalPdfPageStreams = pdfFileEditor.SplitToPages(copyFieldsFromPdf);

Kit.FormEditor formEditor = new Kit.FormEditor(copyFieldsFromPdf, outputPdf);

List<PdfFieldInfo> positions = new List<PdfFieldInfo>();

List<string> requiredFields = new List<string>();

float standardHeight = 15;

List<string> controlsAdded = new List<string>();

for (int i = 0; i < orriginalNumberOfPages && i < emptyNumberOfPages; i++)

{

Aspose.Pdf.Kit.Form pdfForm = new Aspose.Pdf.Kit.Form(orriginalPdfPageStreams[i]);

foreach (string fieldName in pdfForm.FieldsNames)

{

string fullName = pdfForm.GetFullFieldName(fieldName);

Kit.FormFieldFacade facade = pdfForm.GetFieldFacade(fullName);

float x = facade.Box.Left;

float y = facade.Box.Top;

int pageNumber = i + 1;

string newFieldName = string.Empty;

formEditor.Items = null;

if (fieldName.StartsWith(DataMerge.RadioBtnPrefix))

{

//formEditor.RadioGap = 40;

newFieldName = fieldName.Contains(".") ? string.Format("q{0}", fieldName.Split('.')[0]) : fieldName; // string.Format("q{0}", fieldName);

//string[] items = new string[] { bool.TrueString, bool.FalseString };

//formEditor.Items = items;

formEditor.RemoveField(fullName);

//formEditor.AddField(Aspose.Pdf.Kit.FieldType.Radio, newFieldName, pageNumber, x + 20, y - 3, x + 32 , y + 9);

positions.Add(new PdfFieldInfo(x + 20, y - 3, pageNumber, PdfFieldInfo.FieldTypes.YesNoRadio, newFieldName));

requiredFields.Add(newFieldName);

}

else if (fieldName.StartsWith(DataMerge.SignatureFieldPrefix))

{

newFieldName = pdfForm.GetField(fullName);

newFieldName = newFieldName.Replace("{", "").Replace("}", "");

formEditor.AddField(Kit.FieldType.Text, newFieldName, pageNumber, x, y, x + 100, y + 12);

formEditor.RemoveField(fullName);

newFieldName = string.Empty; // signatures can be entered with the same name multiple times

}

else if (fieldName.StartsWith(DataMerge.TextBoxPrefix))

{

string value = pdfForm.GetField(fullName);

PdfControlInfo info = new PdfControlInfo(fieldName);

newFieldName = info.Name;

if (info.Width == 0) info.Width = 50;

formEditor.AddField(Kit.FieldType.MultiLineText, newFieldName, pageNumber, x, y - info.Height, x + info.Width, y + standardHeight);

if (info.Required) requiredFields.Add(newFieldName);

formEditor.RemoveField(fullName);

}

else if (fieldName.StartsWith(DataMerge.NumericTextBoxPrefix))

{

string value = pdfForm.GetField(fullName);

PdfControlInfo info = new PdfControlInfo(fieldName);

newFieldName = info.Name;

if (info.Width == 0) info.Width = 50;

formEditor.AddField(Kit.FieldType.Text, newFieldName, "0", pageNumber, x, y - info.Height, x + info.Width, y + standardHeight);

if (info.Required) requiredFields.Add(newFieldName);

formEditor.RemoveField(fullName);

}

if (controlsAdded.Contains(newFieldName) && !string.IsNullOrEmpty(newFieldName)) throw new Exception(string.Format("Control '{0}' has already been added to the document", newFieldName));

if (!string.IsNullOrEmpty(newFieldName)) controlsAdded.Add(newFieldName);

}

}

formEditor.Save();

Kit.PdfFileMend mend = new Kit.PdfFileMend(outputPdf, outputPdf);

foreach (PdfFieldInfo position in positions)

{

if (position.FieldType == PdfFieldInfo.FieldTypes.YesNoRadio)

{

mend.AddText(new Aspose.Pdf.Kit.FormattedText("Yes"), position.PageNumber, position.LeftX - 26, position.LeftY);

mend.AddText(new Aspose.Pdf.Kit.FormattedText("No"), position.PageNumber, position.LeftX + 18, position.LeftY);

}

}

mend.Close();

File.Copy(outputPdf, copyFieldsFromPdf, true);

File.Delete(outputPdf);

AddRadioButtons(pdfPath, positions);

SetRequiredFields(pdfPath, requiredFields);

}

public void AddRadioButtons(string pdfPath, List<PdfFieldInfo> fields)

{

Aspose.Pdf.Kit.License lic = new Aspose.Pdf.Kit.License();

lic.SetLicense(Licensing.AsposePDFKitLicense);

if (fields == null) return;

if (fields.Count == 0) return;

string copyFieldsFromPdf = pdfPath;

string outputPdf = Path.Combine(Path.GetDirectoryName(pdfPath), string.Format("{0}.pdf", Path.GetFileNameWithoutExtension(Path.GetRandomFileName())));

Kit.PdfFileInfo orriginalPdfFileInfo = new Kit.PdfFileInfo(copyFieldsFromPdf);

int orriginalNumberOfPages = orriginalPdfFileInfo.NumberofPages;

Kit.PdfFileInfo emptyPdfFileInfo = new Kit.PdfFileInfo(copyFieldsFromPdf);

int emptyNumberOfPages = emptyPdfFileInfo.NumberofPages;

Kit.PdfFileEditor pdfFileEditor = new Kit.PdfFileEditor();

MemoryStream[] orriginalPdfPageStreams = pdfFileEditor.SplitToPages(copyFieldsFromPdf);

Kit.FormEditor formEditor = new Kit.FormEditor(copyFieldsFromPdf, outputPdf);

formEditor.RadioGap = 40;

foreach (PdfFieldInfo field in fields)

{

if (field.FieldType == PdfFieldInfo.FieldTypes.YesNoRadio)

{

formEditor.Items = new string[] { bool.TrueString, bool.FalseString };

formEditor.AddField(Aspose.Pdf.Kit.FieldType.Radio, field.Name, field.PageNumber, field.LeftX, field.LeftY, field.LeftX + 16, field.LeftY + 18);

}

}

formEditor.Save();

File.Copy(outputPdf, copyFieldsFromPdf, true);

File.Delete(outputPdf);

}

public void SetRequiredFields(string pdfPath, List<string> requiredFields)

{

Aspose.Pdf.Kit.License lic = new Aspose.Pdf.Kit.License();

lic.SetLicense(Licensing.AsposePDFKitLicense);

if (requiredFields == null) return;

if (requiredFields.Count == 0) return;

string copyFieldsFromPdf = pdfPath;

string outputPdf = Path.Combine(Path.GetDirectoryName(pdfPath), string.Format("{0}.pdf", Path.GetFileNameWithoutExtension(Path.GetRandomFileName())));

Kit.PdfFileInfo orriginalPdfFileInfo = new Kit.PdfFileInfo(copyFieldsFromPdf);

int orriginalNumberOfPages = orriginalPdfFileInfo.NumberofPages;

Kit.PdfFileInfo emptyPdfFileInfo = new Kit.PdfFileInfo(copyFieldsFromPdf);

int emptyNumberOfPages = emptyPdfFileInfo.NumberofPages;

Kit.PdfFileEditor pdfFileEditor = new Kit.PdfFileEditor();

MemoryStream[] orriginalPdfPageStreams = pdfFileEditor.SplitToPages(copyFieldsFromPdf);

Kit.FormEditor formEditor = new Kit.FormEditor(copyFieldsFromPdf, outputPdf);

for (int i = 0; i < orriginalNumberOfPages && i < emptyNumberOfPages; i++)

{

Aspose.Pdf.Kit.Form pdfForm = new Aspose.Pdf.Kit.Form(orriginalPdfPageStreams[i]);

foreach (string fieldName in pdfForm.FieldsNames)

{

string fullName = pdfForm.GetFullFieldName(fieldName);

if (requiredFields.Contains(fullName) || requiredFields.Contains(fieldName)) formEditor.SetFieldAttribute(fullName, Aspose.Pdf.Kit.PropertyFlag.Required);

}

}

formEditor.Save();

File.Copy(outputPdf, copyFieldsFromPdf, true);

File.Delete(outputPdf);

}

Is there an ETA on this?

Hi Chris,

We’re investigating this issue at our end; I’m afraid, we can’t share the ETA at the moment. Please spare us some time and you’ll be updated with the status accordingly.

We’re sorry for the inconvenience.
Regards,

Hi Chris,

I have further investigated this issue at my end and I’m unable to reproduce this issue by using either the file you shared or other files at my end.

I would like to share with you that it is very important for us to reproduce the issue at our end, so that our team would be able to analyze and then resolve it. I would really appreciate if you could share a small working sample application that can help us reproduce the exact output file you shared in the snapshot.

We’re sorry for the inconvenience and appreciate your cooperation.
Regards,

Attached is a zip file containing a solutiuon for a sample application. I have confirmed with EchoSign that the PDF it produces has the exact same issue. If you need any help please ask.

Hi Chris,

I have executed the sample project you shared by adding reference to the latest version and produced the attached output PDF file. I’m unable to see any extra/empty fields being added in the file. I have also attached a snapshot with this post.

Can you please see the attached PDF and share if you still find the problem with this one? If you think it is fine then please download the latest version and try to test the issue with that. Kindly remove any existing reference to the DLL, build the project without adding any reference and then add reference to the new DLL.

I hope this will resolve your issue. If this issue persists then please do let us know.

We’re sorry for the inconvenience.
Regards,

May I ask what software you are using to view the pdf and that created the snapshot?

I downloaded a free trial of Adobe Pro to view the document for myself. I can see the empty fields even in the PDF provided by Aspose from the last message. Attached is a screenshot of what I have found. I know it is these empty fields that is causing me trouble. Looks like every radio button has this issue. Again the screen shot is of the file created at Aspose. We really need this resolved or a work around soon. – Thanks

Hi Chris,

I have used Adobe Acrobat as well to view the PDF file. Nevertheless, we’ll further investigate this issue and update you accordingly.

We’re sorry for the inconvenience.
Regards,

Just as an update I did upgrade to the latest version of the Kit and compiled as instructed. I am still getting the extra item for each radio button. Attached is a screen shot from Adobe Acrobat Pro 9.0.

Hi Chris,

I have reproduced this issue at my end and logged it as PDFKITNET-18484 in our issue tracking system. Our team will investigate this issue and you’ll be updated via this forum thread once it is resolved.

We’re sorry for the inconvenience.
Regards,