Page 1 of 1

How to position image in a document

PostPosted: Mon Apr 15, 2013 1:57 pm
by lazywednesday
I have seen mr Jason Harrop's code regarding image adding in a document. incase you havent seen it. here's the link:
http://www.docx4java.org/trac/docx4j/browser/trunk/docx4j/src/main/java/org/docx4j/samples/AddImage.java
and it works fine. but my question is. how do i position the image? or how do i place the image at the right side of the document. I think there might be a code where i can put spaces before the image to place it at the right side of the document. but adding a paragraph and adding the image will just put the image below the text so it will still be at the left side. i just need to put the image to the right side of the document. I am new to docx4j so I am not that knowledgeable about the properties to be used. thanks in advance

Re: How to position image in a document

PostPosted: Tue Apr 16, 2013 5:11 pm
by lazywednesday
ok i figured out some ways to position the image. Hope this helps other users as well. the first thing i've tried to do was to create a table and set as many columns before the column where you can put the image. so the image will be at the rightmost part of the document.
and another way is to put the image in a paragraph and set the Justification of the paragraph to right.
Here's the link on creating a table
http://blog.iprofs.nl/2012/09/06/creati ... th-docx4j/

and Here's the link on using Jc(Justification)
http://grepcode.com/file/repo1.maven.or ... ation.java

Re: How to position image in a document

PostPosted: Tue Apr 16, 2013 10:41 pm
by jason
Cool. Thank you for taking the time to post your findings.

There is another way. In Word, you can right click on your image to position it.

Here is an example of the results (there are various different settings possible):

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
        <w:drawing>
          <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251658240" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1">
            <wp:simplePos x="0" y="0"/>
            <wp:positionH relativeFrom="rightMargin">
              <wp:posOffset>-1819275</wp:posOffset>
            </wp:positionH>
            <wp:positionV relativeFrom="paragraph">
              <wp:posOffset>4445</wp:posOffset>
            </wp:positionV>
            <wp:extent cx="1590675" cy="1224915"/>
            <wp:effectExtent l="0" t="0" r="9525" b="0"/>
            <wp:wrapSquare wrapText="bothSides"/>
            <wp:docPr id="1" name="Picture 1"/>
            <wp:cNvGraphicFramePr>
              <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/>
            </wp:cNvGraphicFramePr>
            <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
              <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
                <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
etc
 
Parsed in 0.003 seconds, using GeSHi 1.0.8.4