Hi Team,
I’m trying to detect and extract the background image of a word document (docx), created with Ms Office 2016 but I’m failing to do so.
Background image.docx (1.6 MB)
Here is the code:
using System;
using Aspose.Words;
using Aspose.Words.Drawing;
namespace WordImagery
{
class Program
{
static void Main(string[] args)
{
Aspose.Words.License wordslic = new Aspose.Words.License();
wordslic.SetLicense("<licence file>");
string fileName = "Background image.docx";
Document wordsDocument = new Document(fileName);
int shapeNr = 0;
NodeCollection shapes = wordsDocument.GetChildNodes(NodeType.Shape, true);
foreach (var node in shapes)
{
var shape = (Shape)node;
if (shape.HasImage)
{
++shapeNr;
}
}
Console.WriteLine("{0} has {1} image shapes\n", fileName, shapeNr);
if (wordsDocument.BackgroundShape != null)
{
Console.WriteLine("{0} has background shape", fileName);
if (wordsDocument.BackgroundShape.HasImage)
{
Console.WriteLine("wordsDocument.BackgroundShape.HasImage is TRUE");
}
else if (wordsDocument.BackgroundShape.ImageData.HasImage)
{
Console.WriteLine("wordsDocument.BackgroundShape.ImageData.HasImage is TRUE");
}
else
{
Console.WriteLine("{0} has no background image", fileName);
}
}
}
}
}
This is giving me the following output on windows:
Background image.docx has 0 image shapes
Background image.docx has background shape
Background image.docx has no background image
Please advise if this is a bug or if I am doing something wrong here.