Page 1 of 1

Picture content control size

PostPosted: Thu Feb 24, 2011 3:08 am
by antoine
Hi,

Is it possible to set the size of a picture content control?
I have defined a picture control using the word developer ribbon, and bound it to an xpath in the customXml using the OpenDoPE AddIn. When I inject the base 64 encoded picture in the customXml, the control fits to the page width and does not keep it's original size.
I have tried various hacks, including inserting the picture control into a fixed-size table cell, but it didn't help.

Thanks for any help.
Antoine

Re: Picture content control size

PostPosted: Thu Feb 24, 2011 6:46 pm
by jason
What if (in addition to the current approach of being silent about the size of the image) docx4j allowed you to specify either the width of the image:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<yourxml><picture cx="1905000">iVBORw0KGgo...
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


in which the height would scale to maintain the aspect ratio, or both width and height:


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<yourxml><picture cx="1905000"  cy="1130394">iVBORw0KGgo...
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


The units ought to be EMU, since this is the unit used in DrawingML.

Re: Picture content control size

PostPosted: Thu Feb 24, 2011 7:57 pm
by antoine
Hi Jason,

Thanks for your reply. Actually, I'd prefer specifying the size of the picture in the content control and not in the customXml (since the template might be modified be someone who has no access to the injected customXml).
I'm wondering what the <wp:extent cx="1903095" cy="1903095" /> line represents in the following extract of my document.xml? Is there no way to get the size of the control there?

Code: Select all
<w:sdt>
                  <w:sdtPr>
                     <w:tag w:val="od:xpath=xProjectPicture" />
                     <w:id w:val="603392056" />
                     <w:showingPlcHdr />
                     <w:dataBinding w:xpath="/project/picture" w:storeItemID="{9ED2078C-B0D6-422A-A3AB-334DD4A53BF7}" />
                     <w:picture />
                  </w:sdtPr>
                  <w:sdtEndPr />
                  <w:sdtContent>
                     <w:p w:rsidR="000F3362" w:rsidRDefault="000F3362" w:rsidP="000F3362">
                        <w:r>
                           <w:rPr>
                              <w:noProof />
                              <w:lang w:eastAsia="fr-FR" />
                           </w:rPr>
                           <w:drawing>
                              <wp:inline distT="0" distB="0" distL="0" distR="0" wp14:anchorId="5FD63D2B" wp14:editId="38F57882">
                                 <wp:extent cx="1903095" cy="1903095" />
                                 <wp:effectExtent l="0" t="0" r="1905" b="1905" />
                                 <wp:docPr id="2" name="Image 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">
                                          <pic:nvPicPr>
                                             <pic:cNvPr id="0" name="Picture 1" />
                                             <pic:cNvPicPr>
                                                <a:picLocks noChangeAspect="1" noChangeArrowheads="1" />
                                             </pic:cNvPicPr>
                                          </pic:nvPicPr>
                                          <pic:blipFill>
                                             <a:blip r:embed="rId11">
                                                <a:extLst>
                                                   <a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">
                                                      <a14:useLocalDpi xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" val="0" />
                                                   </a:ext>
                                                </a:extLst>
                                             </a:blip>
                                             <a:srcRect />
                                             <a:stretch>
                                                <a:fillRect />
                                             </a:stretch>
                                          </pic:blipFill>
                                          <pic:spPr bwMode="auto">
                                             <a:xfrm>
                                                <a:off x="0" y="0" />
                                                <a:ext cx="1903095" cy="1903095" />
                                             </a:xfrm>
                                             <a:prstGeom prst="rect">
                                                <a:avLst />
                                             </a:prstGeom>
                                             <a:noFill />
                                             <a:ln>
                                                <a:noFill />
                                             </a:ln>
                                          </pic:spPr>
                                       </pic:pic>
                                    </a:graphicData>
                                 </a:graphic>
                              </wp:inline>
                           </w:drawing>
                        </w:r>
                     </w:p>
                  </w:sdtContent>
               </w:sdt>

Re: Picture content control size

PostPosted: Thu Feb 24, 2011 11:44 pm
by jason
Right, that element does specify the size of the picture.

If any picture in your xml is always to be that size, we can use that value.

This assumes the binding is set up the way you did it (ie in Word, where you were able to manually size the picture to taste in the Word UI).

I wonder whether other people wish to be able to dynamically specify the size of the image? If anyone wants this, please speak up!

The current behaviour is to just let it be whatever its natural size is (at a given dpi), unless that is greater than page width, in which case it is scaled down.

Re: Picture content control size

PostPosted: Fri Feb 25, 2011 12:52 am
by antoine
Yes, that's exactly what I'd need: I define a picture control using Word and specify its size using the handles of the control. And then I expect my injected picture content to be resized (respecting its aspect ratio) to the control size.
Thanks for your help.

Re: Picture content control size

PostPosted: Fri Feb 25, 2011 11:35 am
by jason
http://dev.plutext.org/trac/docx4j/changeset/1441 uses the size of the control to specify the image size.

This is now the default behaviour (as opposed to using the image's actual size - if anyone wants this, we'll need to add a switch to provide for it).

It doesn't attempt to respect the aspect ratio though - that's a small job for another day.

Note to self: we're currently replacing the entire w:drawing. If the user had applied any other special effects which are reflected in the existing w:drawing, these would get lost. Consider instead keeping the existing w:drawing, and just changing the relevant bits.

Re: Picture content control size

PostPosted: Fri Feb 25, 2011 9:59 pm
by antoine
Thank you, that was quick!
It's working fine, and it looks like Word does respect the aspect ratio. I did not check the pdf export however.

Re: Picture content control size

PostPosted: Thu Jul 28, 2011 8:03 pm
by antoine
Hi again,

Actually, the respect of the ratio is still useful, for example if you open the document with Open Office or if you remove all STDs. So I made a few changes to BindingHandler to fix this; the patch is attached to this post.

I am not too familiar with docx4j code, so feedback is welcome about this patch. Maybe it's better to do the scaling in BinaryPartAbstractImage?

Re: Picture content control size

PostPosted: Tue Aug 02, 2011 12:55 am
by jason