HTML to PDF radio button issues and Javascript: "Object.create" error

Couple of issue with Aspose HTML

  1. converting HTML to PDF using aspose.html, unable to get radio button value. And if you generate PDF using apose.pdf the way it generate radio buttons is differernt. It doesn’t populate radio button groupname using “name” attribute.

  2. When we import external Javascript into PDF as external javascript, PDF not able to recognize “Object.create” funtions used by .js file

@dotnet14,

Thanks for contacting support.

Can you please share the input files and code snippet which you are using, so that we can test the scenarios in our environment. We are sorry for this inconvenience.

You can use below code … if you render this HTML using Aspose.Html or Aspose.PDF, both render differerent elementIds. can you explain why?

    <div class="card">
	<div class="card-header">
       <h2 class="sectionTitle">Test Panel</h2>                           
    </div>
	<div class="card-block">
		<div class="form-group">
		<table style="width:100%">
		<tr>
		<td class="col-md-3 control-label">			
			Test left panel				
		</td>
		<td class="col-md-9 control-input">			
			sample text			
		</td>
		</tr>
		</table>			
		</div>
	</div>
    </div>
	<div class="card">
	<div class="card-header">
       <h2 class="sectionTitle">Test Radio</h2>                           
    </div>
	<div class="card-block">
		<div class="form-group">
		<table style="width:100%">
		<tr>
			<td class="col-md-3 control-label">			
				Sample Radio Buttons				
			</td>
			<td class="col-md-9 control-input">			
					<input type="radio" name="testradioName0" id="Yes123" class="col-md-3" value="1" />
					<span>
					Yes
					</span>
					<input type="radio" name="testradioName0" id="No123" class="col-md-3" value="2" />
					<span>
					No
					</span>		
			</td>
		</tr>
		<tr>
			<td class="col-md-3 control-label">			
				Comments - If "No" was selected for any of the above, please explain				
			</td>
			<td class="col-md-9 control-input">			
				 <textarea id="textAreaId" name="textAreaIdName" rows="6" class="textareacss">Enter comments here
				 </textarea>		
			</td>
		</tr>
		</table>			
		</div>
	</div>
    </div>
	<div class="card">
	<div class="card-header">
       <h2 class="sectionTitle">Test Radio</h2>                           
    </div>
	<div class="card-block">
		<div class="form-group">
		<table style="width:100%">
		<tr>
			<td class="col-md-3 control-label">			
				Another set of Radio Buttons				
			</td>
			<td class="col-md-9 control-input">			
					<input type="radio" name="testradioName1" id="Yes456" class="col-md-3" value="3" />
					<span>
					Yes
					</span>
					<input type="radio" name="testradioName1" id="No456" class="col-md-3" value="4" />
					<span>
					No
					</span>		
			</td>
		</tr>			
		</table>			
		</div>
	</div>
    </div>

@dotnet14,

Thanks for sharing the details. I have tested the scenario using Aspose.Pdf for .NET 10.7 and I am unable to notice any issue.

[C#]

string dataDir = @"C:\pdftest\";
// Open the source PDF document
Document pdfDocument = new Document(dataDir + "newfile.html", new HtmlLoadOptions());
// Save the file into MS document format
pdfDocument.Save(dataDir + "ResultantFile.pdf");

For your reference, I have also attached the output generated over my end.ResultantFile.pdf (516.2 KB)

in your generated PDF if you look at Radio group Tools->Prepare Form(im using Acrobat DC Pro). Ideally with this HTML it should generate name as “testradioName0” but it generates it as “radio”.

Another question:
Why this below doesn’t work:

– PDF_Template_PDF_HTML gernated PDF by using above HTML or you can use your PDF
Aspose.Pdf.Facades.Form form1 = new Aspose.Pdf.Facades.Form(PDF_Template_PDF_HTML);
foreach (var item in form1.FieldNames)
{

            Dictionary<string, string> radioOptions = form1.GetButtonOptionValues(item);
            if (item.Contains("testradioName"))
            {
                RadioButtonField field0 = PDF_Template_PDF_HTML.Form[item] as RadioButtonField;
                RadioButtonOptionField fieldoption = new RadioButtonOptionField();
                fieldoption.OptionName = "Yes";
                fieldoption.PartialName = "Yesname";
                //fieldoption.Width = 12;
                //fieldoption.Height = 12;
                //fieldoption.IsInLineParagraph = true;
                //fieldoption.Border = new Border(fieldoption);
                //fieldoption.Border.Width = 1;
                //fieldoption.Characteristics.Border = System.Drawing.Color.Black; // throws error
                ////fieldoption.Style = BoxStyle.Circle; // throws error
                //fieldoption.Rect = field0[1].Rect;
                //field0.Add(fieldoption);

                field0.DeleteOption("item1");//throws error
                

                PDF_Template_PDF_HTML.Save();
            }
           
        }

Nothing works with this Aspose. Simple requirement: I have a PDF with radio button elements, all I want is to mainupate options either to delete a option or add a new option. if you have any working sample can you send me.

@dotnet14,

Thanks for contacting support.

I have tested the scenario and have managed to reproduce the same issue. For the sake of correction, I have logged it as PDFNET-43591 in our issue tracking system.

I have also tested the scenario and I am able to reproduce the same issue that RadioButtonField option is not being deleted. It has been logged as PDFNET-43592 in our issue tracking system. We will further look into the details of these problems and will keep you updated on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Thank you for logging the issues.
Noticed some other issues, I’m trying to add “Caption” to “RadioButtonOptionField”, but it is unable to cast option to “RadioButtonOptionField”

RadioButtonField field0 = item.Parent as RadioButtonField; // PDF_Template_PDF_HTML.Form[item] as RadioButtonField;
RadioButtonOptionField option = item as RadioButtonOptionField;
option.Caption = new TextFragment(“test123”);

And also if you try to set below propertiers for RadioButtonOptionField, it throws Error.
//// fieldoption.Border = new Border(fieldoption);
//// fieldoption.Border.Width = 1;
//// fieldoption.Border.Style = BorderStyle.Solid;
//// fieldoption.Characteristics.Border = System.Drawing.Color.Black;
you can use attached PDF.

Let me know even if this an issue.

           <a class="attachment" href="/uploads/default/7951">UDS2017Submission-051900Version1 (25).pdf</a> (140.8 KB)

@dotnet14,

Thanks for sharing the details. I have tested the scenario and have managed to replicate the same issue. For the sake of correction, it has been logged as PDFNET-43597 in our issue tracking system.

I have also managed to reproduce the same issue. For the sake of correction, I have separately logged it as PDFNET-43598 in our issue tracking system. We will further look into the details of these problems and will keep you updated on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

@dotnet14

Thanks for your patience.

The product team has completed their investigation for earlier logged issue. Please use following code snippet with latest version of the API (i.e Aspose.Pdf for .NET 17.12), in order to add caption to the Radio Button field:

string inputFile = GetInputPath("RadioButtonField.pdf");
string outputFile = GetOutputPath("RadioButtonField_out.pdf");

Aspose.Pdf.Facades.Form form1 = new Aspose.Pdf.Facades.Form(inputFile);
Document PDF_Template_PDF_HTML = new Document(inputFile);
foreach (var item in form1.FieldNames)
{
 Console.WriteLine(item.ToString());
 Dictionary<string, string> radioOptions = form1.GetButtonOptionValues(item);
 if (item.Contains("radio1"))
 {
  Aspose.Pdf.Forms.RadioButtonField field0 = PDF_Template_PDF_HTML.Form[item] as Aspose.Pdf.Forms.RadioButtonField;
  Aspose.Pdf.Forms.RadioButtonOptionField fieldoption = new Aspose.Pdf.Forms.RadioButtonOptionField();
  fieldoption.OptionName = "Yes";
  fieldoption.PartialName = "Yesname";

  var updatedFragment = new Aspose.Pdf.Text.TextFragment("test123");
  updatedFragment.TextState.Font = FontRepository.FindFont("Arial");
  updatedFragment.TextState.FontSize = 10;
  updatedFragment.TextState.LineSpacing = 6.32f;
                    
  //create TextParagraph object
  TextParagraph par = new TextParagraph();

  //set paragraph position
  par.Position = new Position(field0.Rect.LLX, field0.Rect.LLY + updatedFragment.TextState.FontSize);
  // Specify word wraping mode
  par.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords;

  //add new TextFragment to paragraph
  par.AppendLine(updatedFragment);
                    
  //add the TextParagraph using TextBuilder
  TextBuilder textBuilder = new TextBuilder(PDF_Template_PDF_HTML.Pages[1]);
  textBuilder.AppendParagraph(par);

  field0.DeleteOption("item1");//throws error

 }
}
PDF_Template_PDF_HTML.Save(outputFile);

Now concerning to the other logged issue(s), we will let you know once we make some significant progress towards their resolution. Please spare us little time.

We are sorry for the inconvenience.

@dotnet14

Thanks for your patience.

Please use following code snippet with latest version Aspose.Pdf for .NET 17.12, in order to achieve correct output. In case you still face any issue, please feel free to let us know.

Aspose.Pdf.Facades.Form form1 = new Aspose.Pdf.Facades.Form(inputPdfFile);
Document PDF_Template_PDF_HTML = new Document(inputPdfFile);
foreach (var item in form1.FieldNames)
{
  Console.WriteLine(item.ToString());
  Dictionary<string, string> radioOptions = form1.GetButtonOptionValues(item);
  if (item.Contains("radio1"))
  {
    Aspose.Pdf.Forms.RadioButtonField field0 = PDF_Template_PDF_HTML.Form[item] as Aspose.Pdf.Forms.RadioButtonField;
    Aspose.Pdf.Forms.RadioButtonOptionField fieldoption = new Aspose.Pdf.Forms.RadioButtonOptionField();
    fieldoption.OptionName = "Yes";
    fieldoption.PartialName = "Yesname";
    fieldoption.PartialName = "Yesname";
    fieldoption.Caption = new Aspose.Pdf.Text.TextFragment("test123");

    fieldoption.Width = 15;
    fieldoption.Height = 15;
    field0.Add(fieldoption);

    fieldoption.Border = new Border(fieldoption);
    fieldoption.Border.Width = 1;
    fieldoption.Border.Style = Aspose.Pdf.Annotations.BorderStyle.Solid;
    fieldoption.Characteristics.Border = System.Drawing.Color.Black;
    field0.DeleteOption("item1");
  }
}
PDF_Template_PDF_HTML.Save(outputFile);

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan