Page 1 of 1

Creating Inline image scaled to fit page height and width

PostPosted: Thu Mar 05, 2015 4:43 am
by arimmer
I am successfully adding an image (gif) to a docx document using :

Code: Select all
BinaryPartAbstractImagePart.createImageInline( String, String, int, int, boolean)

but it is only scaled to fit the width, and is 'higher' than will fit on the page but does not 'flow over' onto the next page (when viewed in Office 2010 Print layout or Full Screen Reading [Looks fine in Web layout]).

The image I need to add to the document is variable in size but usually both too wide and too high for the (A4 landscape) page. Is there a recommended way of scaling it to fit onto the page height as well as width?

I switched debug on to try and see what was happening as the inline image was created which showed me the following (in case it helps):
Code: Select all
04-Mar-2015 16:46:35,974 DEBUG - BinaryPartAbstractImage             - created tmp file: C:\Program Files (x86)\apache-tomcat-6.0.39\temp\img5749293468049202075.img
04-Mar-2015 16:46:36,017 DEBUG - BinaryPartAbstractImage             - file:/C:/Program%20Files%20(x86)/apache-tomcat-6.0.39/temp/img5749293468049202075.img image/gif 1333x1333
04-Mar-2015 16:46:36,018 DEBUG - BinaryPartAbstractImage             - Resolution:96x96
04-Mar-2015 16:46:36,018 DEBUG - BinaryPartAbstractImage             - Print size: 14" x14"
04-Mar-2015 16:46:36,018 DEBUG - BinaryPartAbstractImage             - .. supported natively by Word
04-Mar-2015 16:46:36,019 DEBUG - Base                                -
Set contentType image/gif on part /word/media/document_image_rId5.gif

04-Mar-2015 16:46:36,020 DEBUG - BinaryPartAbstractImage             - created part with name /word/media/document_image_rId5.gif
04-Mar-2015 16:46:36,021 DEBUG - Part                                - reading input stream
04-Mar-2015 16:46:36,032 DEBUG - Part                                - .. done
04-Mar-2015 16:46:36,032 DEBUG - Part                                - closing binary input stream
04-Mar-2015 16:46:36,033 INFO  - Part                                - .. closed.
04-Mar-2015 16:46:36,033 INFO  - RelationshipsPart                   - adding part with proposed name: /word/media/document_image_rId5.gif
04-Mar-2015 16:46:36,033 DEBUG - RelationshipsPart                   - Relativising target /word/media/document_image_rId5.gif against source /word/document.xml
04-Mar-2015 16:46:36,034 DEBUG - RelationshipsPart                   - Result media/document_image_rId5.gif
04-Mar-2015 16:46:36,034 DEBUG - RelationshipsPart                   - Loading part /word/media/document_image_rId5.gif
04-Mar-2015 16:46:36,034 DEBUG - Part                                - setPackage called for
04-Mar-2015 16:46:36,604 DEBUG - BinaryPartAbstractImage             - .. deleted C:\Program Files (x86)\apache-tomcat-6.0.39\temp\img5749293468049202075.img
04-Mar-2015 16:46:36,629 DEBUG - BinaryPartAbstractImage             - writableWidthTwips: 15399.0
04-Mar-2015 16:46:36,629 DEBUG - BinaryPartAbstractImage             - imageWidthTwips: 19995.0
04-Mar-2015 16:46:36,630 DEBUG - BinaryPartAbstractImage             - Scaling image to fit page width
04-Mar-2015 16:46:36,632 DEBUG - BinaryPartAbstractImage             - cx=9778365; cy=9778365
04-Mar-2015 16:46:36,632 DEBUG - XmlUtils                            - Results of substitution: <wp:inline distT="0" distB="0" distL="0" distR="0" xmlns:w="" xmlns:r="" xmlns:wp=""><wp:extent cx="9778365" cy="9778365"/><wp:effectExtent l="0" t="0" r="0" b="0"/><wp:docPr id="0" name="with background image" descr="with background image"/><wp:cNvGraphicFramePr><a:graphicFrameLocks xmlns:a="" noChangeAspect="1"/></wp:cNvGraphicFramePr><a:graphic xmlns:a=""><a:graphicData uri=""><pic:pic xmlns:pic=""><pic:nvPicPr><pic:cNvPr id="0" name="with background image"/><pic:cNvPicPr/></pic:nvPicPr><pic:blipFill><a:blip r:embed="rId5"/><a:stretch><a:fillRect/></a:stretch></pic:blipFill><pic:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="9778365" cy="9778365"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic></wp:inline>
04-Mar-2015 16:46:36,632 DEBUG - XmlUtils                            - Unmarshalling '<wp:inline distT="0" distB="0" distL="0" distR="0" xmlns:w="

Re: Creating Inline image scaled to fit page height and widt

PostPosted: Thu Mar 05, 2015 6:57 pm
by jason
The signature:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
public Inline createImageInline(String filenameHint, String altText,
                        int id1, int id2, long cx, long cy, boolean link) throws Exception
Parsed in 0.014 seconds, using GeSHi

allows you to specify both width (cx) and height (cy).

See ... .java#L806