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

Free Support Forum - aspose.com

Font color problem with HTML table

Hello Team,


We are using aspose 7.1.0.0 to generate documents.
We are facing problem with HTML table and the font color applied to it.

We are using InsertHTML() method to render text strings.
Before inserting the text we provide font color as “Red” or “Blue”, but in the output entire string does not take that color, rather just the first table is in the specified color and rest of the text is in black

Attached are the document output for your reference with the HTML string we are using.

Regards,
Dwarika

Hello

<?xml:namespace prefix = o />

Thanks for your inquiry. I think, as a workaround, in your case you can try using the technique as described in the following forum thread to change font color:

http://www.aspose.com/community/forums/225803/fw-changing-the-font-while-saving-the-html-file/showthread.aspx

Best regards,

Hello,

Thanks for your reply.
I tried opening the link you have provided but I think the link is broken.
Attached is the error we are getting when we try to open the link.
Regards,
Dwarika

Hi Dwarika,

Follow this link below to see the page Andrey is talking about.

http://www.aspose.com/community/forums/225803/fw-changing-the-font-while-saving-the-html-file/showthread.aspx

It was just a small error at the end of the URL causing the wrong page to be loaded.

Thanks,

Hello,

I have gone through the link you have provided. Link gives information about saving and re-loading the document in HTML format. Then using the font changer, however this is not the case with the problem we are facing which is related to color of the text.
Also it is not possible for us to save/reload the document as the documents are generated at runtime depending upon the settings.
Kindly suggest what can be done in this regards.

Thanks,
Dwarika

Hello

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

Thank you for additional information. In your case, you insert HTML in to the document and then using FontChanger you can easily change font color for whole document. All that you need is modifying FontChanger in order to change font color.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

string html = File.ReadAllText("yourHTML.html");

builder.InsertHtml(html);

// Create an object that inherits from the DocumentVisitor class.

FontChanger changer = new FontChanger(Color.Red);

//Get the model to accept a visitor.

// The model will iterate through itself by calling the corresponding methods

// on the visitor object (this is called visiting).

doc.Accept(changer);

//Save output document

doc.Save("out.doc");

Best regards,

Hello,

Does this mean we have to use FontChanger irrespective of having HTML contents in the input string?

As string html may contain

html = “This is test text”;

or

html = “
Test
Test
”;

Also we do not have specific .html file. for the Text to be printed on report we simply call InsertHTML() method of documentbuilder.

Please suggest,
Regards,
Dwarika

Hello

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

Thanks for your request. You can use InsertHtml method to insert an HTML fragment or whole HTML document. You should use FontChanger after inserting HTML into the document. It does not matter which way of inserting HTML you are using. You can read HTML from a file or inset as a string.

Best regards,

Hello,


Is it necessary to set and use fontchanger after the InsertHTML methos?
As in our application, we have custom objects which are used to format the paragraph, set the font etc and finally we call InsertHTML method.

Therefore we do not get font related info when we are in the method where InsertHTML method is used.

Regards,
Dwarika

Hello,


Is it necessary to set and use fontchanger after the InsertHTML method?
As in our application, we have custom objects which are used to format the paragraph, set the font etc and finally we call InsertHTML method.

Therefore we do not get font related info when we are in the method where InsertHTML method is used.

Regards,
Dwarika

Hi Dwarika,

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

Thanks for your request. Yes, you need to accept FontChanger after inserting HTML. Please take a look on the code example Andrey provided.

Best regards.

Hello,

I could not find the Class FontChanger in Aspose.Words.

Could you please elaborate more on DocumentVisitor and FontChanger Class?

Also if possible send us the code sample for same.

Regards,

Dwarika

Hello

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

Thanks for your request. FontChanger class is attached.

The code example you can found here:

http://www.aspose.com/community/forums/225803/fw-changing-the-font-while-saving-the-html-file/showthread.aspx

Best regards,

Hello,

Thanks for the code file, i have still one more doubt as follows,

If we use this font changer, this will chnage the colour of the entire document? or the selected string ?

Regards,

Dwarila

Hi there,

Thanks for your inquiry.

Yes, the visitor will change the font of all content visited during the enumeration. In this case, since the sample above is run on the document (doc.Accept) this will visit all nodes in the document and change the font for all appropriate nodes.

You can try running the class on just the particlar node or nodes that are inserted by the InsertHtml method but this may be hard if there are many nodes inserted. Instead you may want to take a look at the method used in this post here which may be easier.

Thanks,