Using Microsoft Office 2004 on Mac OS X I tried this test code:

        private static void generateRtf( File pictureFile ) throws  
IOException, DocumentException {
                Document doc = new Document( PageSize.LETTER.rotate() );
                RtfWriter2.getInstance( doc, new 
FileOutputStream("/tmp/test.rtf") );
                try {
                        doc.open();
                        Image img = new Jpeg( pictureFile.toURL() );
                        img.scalePercent( 25f ); //This always seems to be 
ignored
                        doc.add( img );
                } finally {
                        doc.close();
                }
        }


The RTF images are always displayed at full size. It seems like the  
RtfImage class is setting the 'picwgoal' and 'pichgoal' attributes,  
but not the 'picscalex' and 'picscaley' attributes. I modified the  
source code to add these attributes, and now the images display  
correctly with the scaling in Word. Here is the patch for my change:

--Jesse Barnum, President, 360Works
http://www.360works.com
(770) 234-9293


Index: RtfImage.java
===================================================================
RCS file: /cvsroot/itext/src/com/lowagie/text/rtf/graphic/ 
RtfImage.java,v
retrieving revision 1.23
diff -r1.23 RtfImage.java
117d116
<
118a118,126
 >      * Constant for the picture width scale percentage
 >      */
 >     private static final byte[] PICTURE_SCALED_WIDTH_PERCENT = "\ 
\picscalex".getBytes();
 >     /**
 >      * Constant for the picture height scale percentage
 >      */
 >     private static final byte[] PICTURE_SCALED_HEIGHT_PERCENT = "\ 
\picscaley".getBytes();
 >
 >       /**
266a275,276
 >                 result.write(PICTURE_SCALED_WIDTH_PERCENT);
 >                 result.write( intToByteArray( (int)(100 *  
plainWidth / width ) ) );
270a281,282
 >                 result.write(PICTURE_SCALED_HEIGHT_PERCENT);
 >                 result.write( intToByteArray( (int)(100 *  
plainHeight / height ) ) );

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to