I want to convert a chart in docx to png. I can save the docx to png by ImageSaveOptions(SaveFormat::Png). But the saved png is the entired area of the page including the chart and other objects. Can I save the png with only the chart area by specifying, for example, the start position and width, height? Just like crop only the chart image from the png. It appears that there’s no such options in ImageSaveOptions.
You can use ShapeRenderer class to save Chart in Word document to PNG image. Sample C# code of Aspose.Words for .NET API is as follows:
Shape shape = (Shape)doc.GetChildNodes(NodeType.Shape, true)[0];
if (shape.HasChart)
{
ShapeRenderer renderer = shape.GetShapeRenderer();
renderer.Save("D:\\Temp\\chart.png", new ImageSaveOptions(SaveFormat.Png));
}
Dear awais.hafeez,
Exllent! Although I’m using Aspose.Words for C++, I followed your steps, and it works. Thank you very much!
It is great that you were able to find what you were looking for by using Aspose.Words for C++ API. Please let us know any time you may have any further queries in future.
@awais.hafeez,
In my previous work, I downloaded the package of Aspose.Words and it appears that it contains Aspose IDE. So I simply modified some example code in the package and it easily worked.
Now I’m trying to port Aspose to my project. Simply executed Install-Package Aspose.Words.Cpp
from Package Manager Console in Visual Studio to fetch the NuGet package then restarted Visual Studio. And then I simply wrote below code:
System::SharedPtr doc = System::MakeObject(u"template.doc");
However, this “System” symbol cannot be recognised in my project, show below tip in my code:
“The name followed by “::” must be the class name or namespace name”
I already saw “packages\CodePorting.Native.Cs2Cpp.API.20.9.0” dir created under my project.
So I’m not sure if Imissed something for the project environment?
It seems that I also need to add both “packages\CodePorting.Native.Cs2Cpp.API.20.9.0” and “packages\Aspose.Words.Cpp.20.9.0” into AdditionalIncludeDirectories of my vcxproj, then the problem gone.
It is great that you were able to resolve this issue on your end. Please let us know any time you may have any further queries in future. You may also want to check following sections of documentation:
@awais.hafeez,
I have a further question about ID of the Shape object in How to get Shape property wp:docPr id=“...” using .NET.
Not sure if you could have any idea…
We have logged your requirement in our issue tracking system. Your ticket number is WORDSNET-21294. We will further look into the details of this requirement and will keep you updated on the status in your other thread. Please follow your other thread for any further proceedings.