Hi Team,
How do find where the image caption is located(Above the figure or below the figure)?
Above: CaptionAbove.docx (1.1 MB)
Below: CaptionBelow.docx (1010.2 KB)
Regards,
Mahi
Hi Team,
How do find where the image caption is located(Above the figure or below the figure)?
Above: CaptionAbove.docx (1.1 MB)
Below: CaptionBelow.docx (1010.2 KB)
Regards,
Mahi
hi @ Mahesh39.
I will work on this issue but please give us sometime to come up with a solution.
Meanwhile, can you share the version of Aspose.Words that you are using?
Hi @mlyra,
Thanks for your reply. I’m currently using Aspose.Words.22.7 version.
Please update the query asap.
Hi @Mahesh39.
Please check out this code. It will tell if the caption is in the bottom of the image.
Document doc = new Document(MyDir + "Doc1.docx");
for (Paragraph paragraph : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true))
{
if(paragraph.toString(SaveFormat.TEXT).trim().startsWith("Fig"))
{
Node previousPara = paragraph.getPreviousSibling();
if (previousPara != null
&& previousPara.getNodeType() == NodeType.PARAGRAPH
&& previousPara.toString(SaveFormat.TEXT).trim().length() == 0
&& ((Paragraph)previousPara).getChildNodes(NodeType.SHAPE, true).getCount() >= 0)
{
System.out.println("Fig caption is at the bottom of image.");
break;
}
}
}
Let me know if that helps.
Thanks, @mlyra.
I’ve included a file. Although it is a caption above the document, the code treats it as one below. Please find a solution.
Document: Doc3.docx (1.1 MB)
@Mahesh39 I have already answered a similar question asked by your colleague here:
https://forum.aspose.com/t/need-to-find-figure-caption-placement/251362
You can inspect node structure of your document using DocumentBuilder
, as I have suggested in another thread, and adjust the code appropriately.
FYI @mlyra
Thanks @alexey.noskov for your help.
@Mahesh39 - I was trying to come up with a code solution that can scan the document in order to determine caption´s position. However, I saw that your document has no pattern for captions. For example: in the figure one, the caption comes before the shapes but in figure 2 it is not true: There is another paragraph between the caption and the shapes.
If there is no pattern to rule the position of the shape and its caption, there will be no code that can handle this problem (unless you use ML). So, I recommend that you define a pattern and then develop a code that can identify such pattern.