Mark Hall wrote:
On Saturday 12 May 2007, Thomas Bickel wrote:Mark Hall wrote: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 WriterOk. My tests are run with the current CVS version and Word XP / OO 2.2.Unfortunately I cannot confirm your problems. I've tried with images larger and smaller than the document width/height and larger images are scaled down, but smaller images are not scaled.I see two possible causes: a) Some problem with the images you are using. b) A viewer problem.
I'm pretty sure that my conclusion is correct. I also tried on a different
computer using OO 2.0 Writer and it's the same problem there.
Here is some code for you to test:
final com.lowagie.text.Document doc = new com.lowagie.text.Document();
RtfWriter2.getInstance(doc, new FileOutputStream("scaletest.rtf"));
doc.open();
final String format = "png";
final int docWidth = (int)(doc.getPageSize().width() - (doc.leftMargin() +
doc.rightMargin()));
final int docHeight = (int)(doc.getPageSize().height() - (doc.topMargin() +
doc.bottomMargin()));
final File imgFile = new File("test."+format).getAbsoluteFile();
final java.awt.Font font = new java.awt.Font("SansSerif", java.awt.Font.BOLD,
14);
doc.add(new Chunk("docWidth="+docWidth+";
pageWidth="+doc.getPageSize().width()+"\n\n"));
int imgWidth = docWidth - 89;
for(int k = 0; k < 14; k++, imgWidth += 30) {
{ BufferedImage bim = new BufferedImage(imgWidth, 24,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bim.createGraphics();
g2.setColor(imgWidth > docWidth ? ((imgWidth > docWidth*1.33f)
? Color.BLUE : Color.RED) : Color.GREEN);
g2.fillRect(0, 0, bim.getWidth(), bim.getHeight());
g2.setColor(Color.BLACK);
g2.setFont(font);
FontMetrics fm = g2.getFontMetrics();
g2.drawString(imgWidth+" / "+docWidth, 8,
((24-fm.getHeight())/2)+fm.getAscent());
g2.dispose();
ImageIO.write(bim, format, imgFile);
}
com.lowagie.text.Image itImg =
com.lowagie.text.Image.getInstance(imgFile.toURL());
if((itImg.width() > docWidth) || (itImg.height() > docHeight)) {
itImg.scaleToFit(docWidth, docHeight);
float scalePercent = itImg.plainWidth() / itImg.width();
System.out.println("scalePercent="+scalePercent);
}
Paragraph para = new Paragraph("");
para.add(itImg);
doc.add(para);
}
doc.close();
In the resulting rtf file (which is also attached) you can see that the red
images get enlarged, which they should not and they would fit on the page
without scaling.
Thanks,
Thomas
scaletest.rtf
Description: MS-Word document
------------------------------------------------------------------------- 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/
