Grayscale Docx

Hi Team,

Can you suggest me a way to grayscale the docx document…not only images but also colored fonts should be turned into black and white.

@kotharib2

Thanks for your inquiry. Are you using Aspose.Words for .NET or Aspose.Words for Java? Please ZIP and attach the following resources here:

  • Your input Document

  • Your expected Word document showing the correct output. You can create expected document by using MS Word.

As soon as you get these pieces of information ready then we will be able to provide you more information. Thanks for your cooperation.

hi @mannanfazil

I am using Aspose.Words for .NET

my requirement is I want to graysacle or black and white whole word document.

using
Aspose.Words.Saving.OoxmlSaveOptions options = new Aspose.Words.Saving.OoxmlSaveOptions();
options.ColorMode= Aspose.Words.Saving.ColorMode.Grayscale;

is makinhg no difference

so can you please suggest me correct way to acheive this

@kotharib2

Thanks for your inquiry. The SaveOptions.ColorMode property is useful when saving the document to fixed page formats such as .pdf, .xps, images. If you want to save document in .pdf format then use this sample code to achieve results.

Document doc = new Document(MyDir + "input.docx");
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.ColorMode = ColorMode.Grayscale;
doc.Save(MyDir + "output.pdf", pdfSaveOptions);

If you want to save document in .docx format then please use the following code:

        Document doc = new Document(MyDir + "input.docx");
        NodeCollection runs = doc.GetChildNodes(NodeType.Run, true);
        // Set color of text in each run.
        foreach (Run run in runs)
        {
            run.Font.Color = Color.Black;
        }

        foreach (Words.Drawing.Shape shape in doc.GetChildNodes(NodeType.Shape, true))
        {
            if (shape.HasImage)
            {
                shape.ImageData.GrayScale = true;
            }

        }

        doc.Save(MyDir + "output.docx");     

Hope, this helps.