npoi-examples icon indicating copy to clipboard operation
npoi-examples copied to clipboard

How to set picture layout type in XWPF?

Open dulre159 opened this issue 3 years ago • 5 comments

Hi i would like to know how i can set the picture layout type after adding it with addPicture(). Thanks.

dulre159 avatar Dec 02 '21 10:12 dulre159

What does 'picture layout type' exactly mean?

tonyqus avatar Dec 03 '21 05:12 tonyqus

What does 'picture layout type' exactly mean?

Hi i want the set the anchor of the picture to wrapSquare. Something like what they did here: https://stackoverflow.com/questions/47673133/change-image-layout-or-wrap-in-docx-with-apache-poi

But i want to achieve something like this: Example

I want to create a column of pictures where each is separated by some text. Pictures must be one after the other without overlapping or being in the same row. Each picture must have a Square layout. All pictures have the same size.

thedulre159 avatar Dec 03 '21 10:12 thedulre159

Inline open xml in document.xml

          <wp:inline distT="0" distB="0" distL="0" distR="0" wp14:anchorId="64379659" wp14:editId="59692A46">
            <wp:extent cx="5267325" cy="3867150"/>
            <wp:effectExtent l="0" t="0" r="9525" b="0"/>

Text Wrapping - Square

          <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251658240" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1" wp14:anchorId="64379659" wp14:editId="5AEE703F">
            <wp:simplePos x="0" y="0"/>
            <wp:positionH relativeFrom="column">
              <wp:posOffset>0</wp:posOffset>
            </wp:positionH>
            <wp:positionV relativeFrom="paragraph">
              <wp:posOffset>47625</wp:posOffset>
            </wp:positionV>
            <wp:extent cx="5267325" cy="3867150"/>
            <wp:effectExtent l="0" t="0" r="9525" b="0"/>
            <wp:wrapSquare wrapText="bothSides"/>

Text Wrapping - Tight

          <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251658240" behindDoc="1" locked="0" layoutInCell="1" allowOverlap="1" wp14:anchorId="64379659" wp14:editId="21EC34FE">
            <wp:simplePos x="0" y="0"/>
            <wp:positionH relativeFrom="column">
              <wp:posOffset>0</wp:posOffset>
            </wp:positionH>
            <wp:positionV relativeFrom="paragraph">
              <wp:posOffset>47625</wp:posOffset>
            </wp:positionV>
            <wp:extent cx="5267325" cy="3867150"/>
            <wp:effectExtent l="0" t="0" r="9525" b="0"/>
            <wp:wrapTight wrapText="bothSides">
              <wp:wrapPolygon edited="0">
                <wp:start x="0" y="0"/>
                <wp:lineTo x="0" y="21494"/>
                <wp:lineTo x="21561" y="21494"/>
                <wp:lineTo x="21561" y="0"/>
                <wp:lineTo x="0" y="0"/>
              </wp:wrapPolygon>
            </wp:wrapTight>

Text Wrapping - Through

          <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251658240" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1" wp14:anchorId="64379659" wp14:editId="31E731D6">
            <wp:simplePos x="0" y="0"/>
            <wp:positionH relativeFrom="column">
              <wp:posOffset>0</wp:posOffset>
            </wp:positionH>
            <wp:positionV relativeFrom="paragraph">
              <wp:posOffset>47625</wp:posOffset>
            </wp:positionV>
            <wp:extent cx="5267325" cy="3867150"/>
            <wp:effectExtent l="0" t="0" r="9525" b="0"/>
            <wp:wrapThrough wrapText="bothSides">
              <wp:wrapPolygon edited="0">
                <wp:start x="0" y="0"/>
                <wp:lineTo x="0" y="21494"/>
                <wp:lineTo x="21561" y="21494"/>
                <wp:lineTo x="21561" y="0"/>
                <wp:lineTo x="0" y="0"/>
              </wp:wrapPolygon>
            </wp:wrapThrough>

Openxml document about Wrapping - http://officeopenxml.com/drwPicFloating-textWrap.php

tonyqus avatar May 28 '22 22:05 tonyqus

The major difficulty here is how to calculate WrapPolygon coordinates

https://stackoverflow.com/questions/7213133/openxml-and-word-how-to-calculate-wrappolygon-coordinates

tonyqus avatar May 28 '22 22:05 tonyqus

Hi, thank you for your solution I will test it out as soon as possible. This might also help others facing the same problem.

dulre159 avatar Jun 06 '22 09:06 dulre159