Using aspose 25 version, when trying to access paragraph->GetRect();
, it throws exception:
System::NullReferenceException: Object reference not set to an instance of an object.
Attached ppt:
Test1.pptx.zip (255.3 KB)
code snippet:
auto textFrame = shape->get_TextFrame();
std::string textFrameString = textString.ToUtf8String();
if (textFrameString.size())
{
// Iterate through all the paragraphs in the text frame
for (const auto& paragraph : textFrame->get_Paragraphs()) {
if(paragraph){
auto rect = paragraph->GetRect();
}
}
@pankajku
The exception you’re encountering, “System::NullReferenceException: Object reference not set to an instance of an object,” typically indicates that you’re trying to access a method or property on an object that hasn’t been properly initialized. In your case, it seems to occur when you call paragraph->GetRect()
.
Here are a few things you can check to troubleshoot this issue:
-
Check if textFrame
is null: Ensure that the textFrame
object is not null before iterating through its paragraphs. If textFrame
is null, it means that the shape does not contain any text.
auto textFrame = shape->get_TextFrame();
if (!textFrame) {
// Handle the case where textFrame is null
return;
}
-
Check if paragraphs are null: When iterating through the paragraphs, verify that each paragraph
is not null before calling GetRect()
.
for (const auto& paragraph : textFrame->get_Paragraphs()) {
if (paragraph) {
auto rect = paragraph->GetRect();
// Use rect as needed
}
}
-
Ensure the shape has text: Make sure that the shape you are working with actually contains text. If the shape is empty or does not have a text frame, you will encounter issues when trying to access its paragraphs.
-
Check for empty paragraphs: If a paragraph is empty, ensure that it is handled appropriately. You might want to skip processing for empty paragraphs.
If you’ve checked all these points and the issue persists, consider providing more details about the specific shape and its contents, or check if there are any known issues with the version of Aspose.Slides you are using.
For additional reference on how to get the rectangular coordinates of a paragraph, you can refer to the Aspose documentation on paragraph handling here.
If you need further assistance, feel free to ask!
paragraph is not null. textFrameString has special chars,
auto rect = paragraph->GetRect();
this call is directly crashing for equations.
Only fix can be try-catch.
Can we not determine from before rather than iterating through the paragraph and then the portion for a MathPortion?
@pankajku,
We are sorry that you encountered this problem. I need some time to check the issue. I will get back to you as soon as possible.
@pankajku,
Thank you for your patience. With Aspose.Slides for C++ 25.5, I used the following code example:
auto presentation = MakeObject<Presentation>(u"Test1.pptx");
try {
for (auto&& slide : presentation->get_Slides()) {
for (auto&& shape : slide->get_Shapes()) {
if (ObjectExt::Is<IAutoShape>(shape)) {
auto autoShape = ExplicitCast<IAutoShape>(shape);
auto textFrame = autoShape->get_TextFrame();
for (const auto& paragraph : textFrame->get_Paragraphs()) {
auto rect = paragraph->GetRect();
}
}
}
}
}
catch (const Exception& e) {
Console::WriteLine(e->get_Message());
}
presentation->Dispose();
No exceptions are thrown on my end. We recommend using the latest version of Aspose.Slides for C++.
We are using 25.4 version and we are too close to release to update the aspose version now. Can you please confirm if this issue is specific to 25.4 version?
@pankajku,
Thank you for specifying the version of Aspose.Slides you’re using. Unfortunately, I was still unable to reproduce the exception with version 25.4. Could you please review the issue again, isolate the problem, and specify the OS version where the error occurs, along with any other environment details, so we can reproduce the exception on our end?
test1 (1) 2 copy.pptx.zip (601.7 KB)
@andrey.potapov Please find attached the concerned ppt with equations. the equation part comes as null.
@pankajku,
Thank you for the sample presentation file. Unfortunately, I was still unable to reproduce the exception you described. Please try to isolate the problem and provide more details about the environment in which the error occurs.
@andrey.potapov
auto pptImage = System::SmartPtr<IShape> srcShape->GetImage();
this returns "System::NullReferenceException: Object reference not set to an instance of an object.
For math equations, we want to take out an image of it. Can you check this?
This api works for tables, it returns the image, but for math equations it returns the above exception.
@pankajku,
The code line you provided is not compilable. With both presentation files you shared, I used the following code line:
auto pptImage = shape->GetImage();
but I still unable to reproduce the error you described.
@andrey.potapov What do you mean bynot compilable? Can you suggest an API to get the thumbnail image out from a certain shape?
thumbnailPPT.pptx.zip (596.4 KB)
Please check this PPT, the first slide has a table which we can as valid thumbnail from shape->GetImage
for the next slide which has an equation, shape->GetImage() fails.
@pankajku,
With the PowerPoint presentation file you provided and Aspose.Slides for C++ 25.4, I used the following code example:
auto presentation = MakeObject<Presentation>(u"thumbnailPPT.pptx");
try {
for (auto&& slide : presentation->get_Slides()) {
for (auto&& shape : slide->get_Shapes()) {
auto image = shape->GetImage();
}
}
}
catch (const Exception& e) {
Console::WriteLine(e->get_Message());
}
presentation->Dispose();
No exceptions appear on my end.
@andrey.potapov We are using 25.6 version of aspose. Can you check in that version once?
@pankajku,
The IShape::GetImage
and IParagraph::GetRect
methods don’t throw exceptions with the all presentation files on my end with version 25.6 either.
@andrey.potapov Hi, for the shared ppt, do you get the thumbnail image? also, what is the shape->get_Name() ?
For us GetImage() and GetThumbnail() are both failing for equations.
@pankajku,
@andrey.potapov will provide the thumbnail image(s) and relevant details for your requirements. In the meantime, could you please share a standalone sample VS.NET project along with the presentation file(s) to help us reproduce the issue on our end? We will review it soon.
Can you please share the the thumbnail image for the shared ppt on priority?
@pankajku,
We apologize, but @andrey.potapov is currently on holidays. He will return and join by this weekend. After that, he will update you and share the image.