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

Free Support Forum - aspose.com

How to avoid font check for default hyperlink text in word document?

how to check font for hyperlinks in word document content...actually when i gave any hyperlink in word document content..by default it is taking hyperlink as text in another line...how to avoid font check for tht default hyperlink..see my example given below

HYPERLINK "https://www.livemet.com/" --by default it is taking this line how to avoid font check for this line?

https://www.livemet.com/--which i gave in word document..by default it is taking above line too......

how to avoid font check for this one HYPERLINK "https://www.livemet.com/" see my below code...

Document doc = new Document(@"C:\wordtemplate.docx");

// Select all runs in the document.

NodeCollection runs = doc.GetChildNodes(NodeType.Run, true, false);

foreach (Run run in runs)

{

if (!run.Text.Trim().Equals(""))

{

if (run.Font.Name != "Courier New" || run.Font.Size != 11 || (run.Font.Color.ToArgb() != Color.Black.ToArgb() && run.Font.Color.ToArgb() != Automatic.ToArgb()))

{

throw new ArgumentException("Formatting found in the document is not allowed");

}

}

}

}

Hi there,


Thanks for your inquiry.

Could you please attach your input template which demonstrates this issue? We will take a closer look into this for you.

Thanks,

pls debug my code by keeping this word template...u will come to know..by default hyperlink text line is coming other than the which i gave in word document..i have to avoid font check for tht hyperlink text which is coming default...see my below code and check in document content once..

Document doc = new Document(@"C:\fontrestrict.docx");

string doccontent = doc.Range.Text ;

// Select all runs in the document.

NodeCollection runs = doc.GetChildNodes(NodeType.Run, true, false);

foreach (Run run in runs)

{

if (!run.Text.Trim().Equals(""))

{

if (run.Font.Name != "Courier New" || run.Font.Size != 11 || (run.Font.Color.ToArgb() != Color.Black.ToArgb() && run.Font.Color.ToArgb() != Automatic.ToArgb()))

{

throw new ArgumentException("Formatting found in the document is not allowed");

}

}

}

Hi

Thanks for your request. Usually, formation of hyperlinks in MS Word documents is applied using Hyperlink character style. So it is expected that what you check direct formation of hyperlink runs you get the default formatting. In your case, code should look like this:

Document doc = new Document(@"Test001\fontrestrict.docx");

// Select all runs in the document.

NodeCollection runs = doc.GetChildNodes(NodeType.Run, true, false);

foreach (Run run in runs)

{

if (run.Font.StyleIdentifier == StyleIdentifier.Hyperlink)

{

Console.WriteLine("This run is hyperlink");

Console.WriteLine(run.Text);

// Here you can check fornt of the style.

// ................................

}

}

Also, you should note that styles can inherit formation from their base styles.

Best regards,

Thanks for ur code it works fine for only hyperlink...

if i have a text along with hyperlink..in tht case how to check font for both text and hyperlink?

for hyperlink it is clear wht abt text?

Hi

Thanks for your inquiry. Formatting of text in MS Word documents can be defined on few different levels:

1. Paragraph style defined for the particular paragraph;

2. Character style defined for the particular run;

3. Explicit formatting specified for a particular run.

For more information, please see the following link:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/object-model-overview.html

Hope this helps. Please let me know if you need more assistance.

Best regards,