We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Problem with inserting Input tags

Hi,

I am inserting the following HTML into document using InsertHTML() method, but i am not able to view input tags in document.

Date:

This HTML is comming from DB, as per my knowledge with Aspose.Words, we should not insert the INPUT tags into document.

So is there any alternative is there to overcome this, at least should insert the word fields into the document.. how should i do??

Could pls suggest me the sample code for replacing the INPUT tags with word fields while using InsertHTML() method...

Regards,

Srinu Dhulipalla

Hi Srinu,

Aspose.Words does not support import of the INPUT tags from HTML at the moment. We have this as a feature request already, reference #981.

There is a document that provides some detail about what HTML is supported and what not in Aspose.Words available here http://www.aspose.com/community/files/51/file-format-components/aspose.words-for-.net-and-java/category1242.aspx

We plan to support import of INPUT tags some time in 2009, but no fixed date at this stage.

Let me also note that although Aspose.Words will support importing of INPUT tags, we are not likely to ever support attributes such as onkeydown, onblur, tabIndex and so on. Aspose.Words design is based around Microsoft Word documents and these HTML attributes have no place in our model. Aspose.Words will always lose these attributes during import.

Hello Srinu!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for your patience.

I’m revising issue #981. That’s a good idea to import everything from HTML document to our document model. But I’d like to consult with your regarding the details.

If a source HTML document contains one or more input fields, this implies you might want to handle them in the document model. As Roman wrote, we won’t import script-related attributes since they don’t have place in our model. The only possibility is to handle them programmatically using Aspose.Words API. Is this what you expect?

In Microsoft Word 2007 there are several kinds of document items that introduce similar functionality. For instance, text input can be represented by text form control, ActiveX component or Web form control. We can import input elements as simple form fields assigning them given name to make them distinguishable. Other objects are quite tricky; they require dependencies and Microsoft Office “magic” in output HTML that most customers don’t like.

Using the described approach text input fields will be imported not the same way as Microsoft Word does. We also should think about roundtrip: export after import with semantically equal results. This is definitely a complex task but maybe not so important since you need only import. Anyway your ideas would be appreciated.

You can see what I’m suggesting in our documentation on form fields:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/work-with-form-fields.html

As a workaround you also can find input elements in the source and insert form fields programmatically in appropriate places.

Regards,

Hi,

when we are trying to insert an HTML content into document some of the contents are not appearing into the document, as i found that HTML contains Input tags, So Aspose.Words doesn't insert input tags.

Is there any other way to workarround this.

Please suggest me sample code for inseting HTML containing input tags. My HTML content is:

Date: 


Risk Control

Regards,

Srinu Dhulipalla

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. As I can see you already asked the same question earlier in the forum, but you did not answer the question our developer asked. So, I would to concatenate these two forum thread. Please answer the question our developer responsible to HTML module asked. Your answers could help us to fix the issue.

Best regards.

Hi Roman,

Thanks you for responding..

It is just enough to support Importing of INPUT tags, no need of supporting attributes such as onkeydown, onblur, etc..

Let me know how to insert Form Fields if the HTML content having INPUT tags, It is enough to replace the Form Field in the place of INPUT tags.

please help me out on this, we need to release the Import module here..

Regards,

Srinu Dhulipalla

Hi Klepus,

Thanks you for responding.

Yes you are right.. even source HTML document contains one or more input fields, we don't want to handle them in the document model. Just we need to show the fields to our customers, its enoutgh.

So can you pls help me out in this, replacing Form Fields in the place INPUT tags.

Regards,

Srinu Dhulipalla

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I created simple code for you that replaces INPUT tags with placeholders and then replaces placeholders with formfields in a Word document.

public void Test131()

{

// Get HTML string.

string html = File.ReadAllText(@"Test131\test.html");

// We Should find and replace with placeholders all input tags in the HTML string.

// There are three types of FormFields in MS Word Documents - TextBox, Checkbox and ComboBox

// So we should also determine what type of formfield should be used.

// We will do this using Regular Expressions.

// INPUT tag can have type = button, checkbox, file, hidden, image, password, radio, reset, submit and text

// We will work only with INPUT tags with type of checkbox and text

Regex regex = new Regex("\\<INPUT.*?( type=[\"']?(?\\w*)[\"']?)?.*?\\>", RegexOptions.IgnoreCase);

// Replace input tags with placeholders

MatchCollection matches = regex.Matches(html);

foreach (Match m in matches)

{

string replacement = string.Empty;

string fieldType = m.Groups["type"].Value.ToLower();

// by default INPUT tag is textbox, so if type of it is not specified we sould insert textbox

if (string.IsNullOrEmpty(fieldType))

fieldType = "text";

// Placeholders will look like the following <%text%>,

// tags are needed that placeholders will be separate runs

if (fieldType == "text" || fieldType == "checkbox")

replacement = string.Format("<%{0}%>", fieldType);

html = html.Replace(m.Value, replacement);

}

// Create Docuemnt and docuemnt builder

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

// Insert HTML into the docuemnt

builder.InsertHtml(html);

// Replace placeholders with formfields

Regex placeholderRegex = new Regex("<%(?\\w*)%>", RegexOptions.IgnoreCase);

doc.Range.Replace(placeholderRegex, new ReplaceEvaluator(ReplaceEvaluatorinsertFormFields), false);

//Save output document

doc.Save(@"Test131\out.doc");

}

///

/// This method is called by the Aspose.Words find and replace engine for each match.

/// This method replace the match string with formfield.

///

private static ReplaceAction ReplaceEvaluatorinsertFormFields(object sender, ReplaceEvaluatorArgs e)

{

// This is a Run node that contains placeholder string

Node currentNode = e.MatchNode;

// Create DocumentBuilder

DocumentBuilder builder = new DocumentBuilder((Document)currentNode.Document);

// Move documentBuilder cursor to th ematched node and insert formfield

builder.MoveTo(currentNode);

// Every formfield in word docuemnt has bookmark asociated with the formfield

// There cannot be two bookmarks with the same name in the document

// So we should generate unique nema for each formfield

string name = Guid.NewGuid().ToString("N");

//Insert formfield

if (e.Match.Groups["type"].Value == "text")

builder.InsertTextInput(name, TextFormFieldType.RegularText, string.Empty, " ", 0);

else if (e.Match.Groups["type"].Value == "checkbox")

builder.InsertCheckBox(name, false, 10);

// Signal to the replace engine to do replace matshed text.

return ReplaceAction.Replace;

}

Hope this helps.

Best regards.

The issues you have found earlier (filed as 981) have been fixed in this update.

Can we embed HTML input elements like Textboxes, Radio Buttons, Dropdowns into the word document? We have a scenario wherein an online survey needs to be converted into its ms word counterpart. Can we programatically insert the HTML elements into the word file so that way we dont end up creating a word survey manually.


Thanks

Hi Varun,


Thanks for your inquiry.

In a word document form fields are exported to HTML as input, radio, drop down list tags etc. So you can insert these into your word document to achieve the same effect. Please see the following article for details.

http://docs.aspose.com/display/wordsnet/Working+with+Form+Fields

Thanks,

Thanks for the earlier reply,


I am attaching a word document (2003 doc format) in which i have simple copy pasted HTML elements from a form. If you enable the macro after opening the document you will observe that you can interact with these pasted html form elements within word itself. This document has textboxes, radiobuttons and checkboxes. I understand from your earlier post that we can use MS word form elements however we have a huge 13 page html form (x 200 copies of the same with different form element structures on each) which we need to convert into word. So it would be easier to embed the already existent HTML rather than re-creating everthing in word.

Hi Varun,


Thanks for this additional information.

I apologise as I misunderstood your previous post. When you import an HTML document using Aspose.Words any input tags are converted to appropriate form fields in the document. This means you can simply just import your HTML as it is and have working form fields.

The type of inputs found in your attached documents are legacy ActiveX controls. Aspose.Words partially supports ActiveX in recent versions so if you require form fields from HTML being imported as these then we might be able to provide a work around for this. Please let us know if this is what you need.

Thanks,