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

Free Support Forum - aspose.com

Bold-italic and Underline information

Hi,


We want the information for Bold, Italic and Underline in the docx file and need the index of the text where Bold, Italic and Underline are starting in the paragraph in java.

Can share me a example for this and i have shared the docx file which is having these three scenarios
in header, footer and body

Thanks,
Rajesh


Hi Rajesh,


Thanks for your inquiry. All text of the document is stored in “Runs” of text. Each Run has “Font” property. You can check if a text is Bold, Italic and Underline using Font.Bold, Font.Italic and Font.Underline properties respectively. e.g.
Document doc = new Document(getMyDir() + “Sample_input.docx”);
doc.joinRunsWithSameFormatting();

for (Run run : (Iterable<Run>) doc.getChildNodes(NodeType.RUN, true)){
if (run.getFont().getBold())
System.out.println(“BOLD =>” + run.getText());
if (run.getFont().getItalic())
System.out.println(“ITALIC =>” + run.getText());
if (run.getFont().getUnderline() == Underline.SINGLE)
System.out.println(“UNDERLINE =>” + run.getText());
}

Hope, this helps.

Best regards,

how can we use this in aspose words .net

I try this one in .net and can’t check run is Bold, Italic,…

Hi Minh,


Aspose.Words for .NET code of above Java code is as follows:

Document doc = new Document(MyDir + @“Sample_input.docx”);

doc.JoinRunsWithSameFormatting();

foreach (Run run in doc.GetChildNodes(NodeType.Run, true))

{

if (run.Font.Bold)

Console.WriteLine("BOLD =>" + run.Text);

if (run.Font.Italic)

Console.WriteLine("ITALIC =>" + run.Text);

if (run.Font.Underline == Underline.Single)

Console.WriteLine("UNDERLINE =>" + run.Text);

}


Best regards,