I'd like to programmatically add a caption to an image that is also inserted using docx4j.
So far I am using an example based on the code given in http://vixmemon.blogspot.com/2013/04/do ... -with.html.
It works fine to add the image in the document.
Now I want to customize the image, first I am setting the size of the image by adding the following lines in the private "P addInlineImageToParagraph(Inline inline, P paragraph)" method (the size values are just for testing..):
- Code: Select all
CTPositiveSize2D ctPositiveSize2D = new CTPositiveSize2D();
ctPositiveSize2D.setCx(4300*1000);
ctPositiveSize2D.setCy(inline.getExtent().getCy());
inline.setExtent(ctPositiveSize2D);
So now I would like to add a caption to this image. I was expecting a similar solution, but could not find any documentation or example to do so.
I found that there is an CTCaption object which I created using:
- Code: Select all
CTCaption caption = factory.createCTCaption();
caption.setName("Test");
But I could not find the way to link/insert this caption (in)to the image.
Does someone have any clues that could guide me?
From testing around I saw that the XML data of a caption of a figure looks like this:
- Code: Select all
<w:p w:rsidR="005E10CD" w:rsidRPr="005E10CD" w:rsidRDefault="008C679D" w:rsidP="002F3885"><w:pPr><w:pStyle w:val="Caption"/><w:jc w:val="center"/></w:pPr><w:r><w:t xml:space="preserve">Figure </w:t></w:r><w:fldSimple w:instr=" SEQ Figure \* ARABIC "><w:r w:rsidR="005E10CD"><w:rPr><w:noProof/></w:rPr><w:t>1</w:t></w:r></w:fldSimple><w:r><w:t xml:space="preserve"> </w:t></w:r><w:r w:rsidR="005E10CD"><w:t>–</w:t></w:r><w:r><w:t xml:space="preserve"> My Caption</w:t></w:r>
<w:bookmarkStart w:id="0" w:name="_GoBack"/><w:bookmarkEnd w:id="0"/></w:p>