Free Support Forum - aspose.com

Find Color Pages (with Colorful Text Font or Shapes Images) in Word DOCX Document using C# .NET

Hello Support,
I want to know which page is color page in one word, Is there any API or way to do that with .Net?

Thanks

@JasonMei,

Please try Document.PageColor property that can be used to get or set the page color of the document. In case you observe any problems, please ZIP and upload your input Word document here for testing. We will then investigate the issue on our end and provide you more information.

Thanks for your reply.
I try to use Document.PageColor, but i can not find color page number. There is a color pic or color font in the word, i would like to get color page number.
I attach test word, in this word, page 1(color font) and page 3(color pic) are color pages, how to use API to get color page number for word?
Thanks a lot.test color.zip (26.8 KB)

@JasonMei,

You can build logic on the following code to determine which Pages have colored Text or shapes:

Document doc = new Document("E:\\temp\\test color\\test color.docx");
LayoutCollector collector = new LayoutCollector(doc);

ArrayList listOfColoredPages = new ArrayList();
foreach (Run run in doc.GetChildNodes(NodeType.Run, true))
{
    if (run.Font.Color != Color.Empty)
    {
        int pageNumber = collector.GetStartPageIndex(run);
        if (!listOfColoredPages.Contains(pageNumber))
            listOfColoredPages.Add(pageNumber);
    }
}

foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
{
    int pageNumber = collector.GetStartPageIndex(shape);
    if (!listOfColoredPages.Contains(pageNumber))
        listOfColoredPages.Add(pageNumber);
}

foreach (int pageNumber in listOfColoredPages)
{
    Console.WriteLine(pageNumber);
}

Hope, this helps.