Mark Hall wrote:
> On Friday 11 May 2007, Thomas Bickel wrote:
>> I need to add some images to a rtf document, some of those images can be
>> quite large so I added some code that is supposed to scale down images that
>> are larger than a page. The problem is that some images that would fit on a
>> page actually get enlarged with the following code:
> I can't see any obvious errors, I'll have a look where the problem lies over 
> the weekend.
> 
> Which version of iText are you using and what program are you using to view 
> the RTF file?

iText 2.0.2, Word 2003, OO 2.2 Writer

It looks like the rtf image resolution is 33% higher than the iText page 
resolution. I.e. I can add images up to approx 697 pixels wide to a rtf (A4) 
without having to scale. 96 vs 72 dpi maybe?

Taking that into account I changed my code to this:

if((itImg.width() > docWidth*1.33f) || (itImg.height() > docHeight*1.33f)) {
        itImg.scaleToFit(docWidth, docHeight);
}

This does what I intended to do but was confusing at first because as you can 
see I do not pass the adjusted sizes to the scaleToFit() method so 
plainWidth/Height are still in "page units". So why is the scaled size still 
always correct?
It turns out that the twips value you use to write the scaled sizes just 
cancels out the error introduced in the scaleToFit() method so the images show 
up scaled to full page width.
i.e. the twips value is 33% to hight and should be 15 and not 20 IMHO. (found 
out through trial and error by manually editing a rtf).


Regards,
Thomas




-------------------------------------------------------------------------
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