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

Free Support Forum - aspose.com

Find Text Contents Formatted with a Particular Font in Entire Word Document & Change the Font Name of that Text using Java

Hi, Can you please let me know if there is a API to replace a specific font with other in entire document. Ex: Replace Times New Roman with Arial . Below code seems working but not sure if it is effieciant. Thank you.

for (Paragraph p : (Iterable) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
for (Run run : p.getRuns()) {
if(“Times New Roman”.equalsIgnoreCase(run.getFont().getName())){
run.getFont().setName(“Arial”);
}

@vijji,

You can change font name of text formatted with particular font by using the following code:

Document doc = new Document("E:\\Temp\\input.docx");

for (Run run : (Iterable<Run>) doc.getChildNodes(NodeType.RUN, true)) {
    if (run.getFont().getName().equals("Algerian"))
        run.getFont().setName("Arial");
}

doc.save("E:\\Temp\\awjava-20.2.docx");

Hope, this helps.

Yes, woking. Thank you.