in meantime i downloaded imageMagick's "identify.exe" and discovered the
following:
all images have a Resolution of 240x240. but the only image of the tested
group where iText shows correct resolution is a image WITHOUT an
exif:xresolution/exif:yresolution tag!
So all Programs show the resolution correctly (ImageMagick's identify i.e.
"Resolution: 300x300") including iText. But if there is an exif tag (with
exactly the same Resolution, output from imageMagick's identify:
"exif:ResolutionUnit: 2 exif:XResolution: 240/1 exif:YResolution: 240/1")
iText shows wrong Resolution 96dpi (no "96" found in identify.exe output for
this image) or 0 resolution.
I can hardly believe that i discovered a bug in iText so here is my code (i
am using slightly modified code from Toolbox tiff2pdf plugin):
"
private void addSingleImage(Image image, boolean originalSize){
if (image.getDpiX() > 0 && image.getDpiY() > 0) {
System.out.println(image.getDpiX());
System.out.println(image.getDpiY());
image.scalePercent(7200f / image.getDpiX(), 7200f /
image.getDpiY());
}
else {
System.out.println(image.getDpiX());
System.out.println(image.getDpiY());
}
if (originalSize) {
pdf.setPageSize(new
Rectangle(image.getScaledWidth(),image.getScaledHeight()));
} else {
if (image.getScaledWidth() > PageSize.A4.getWidth() ||
image.getScaledHeight() > PageSize.A4.getHeight()) {
//0 wird zurückgegeben falls dpi-Auflösung nicht verfügbar
if (image.getDpiX() > 0 && image.getDpiY() > 0)
{
float adjx = PageSize.A4.getWidth() /
image.getScaledWidth();
float adjy = PageSize.A4.getHeight() /
image.getScaledHeight();
float adj = Math.min(adjx, adjy);
image.scalePercent(7200f / image.getDpiX() * adj, 7200f
/ image.getDpiY() * adj);
}
else
image.scaleToFit(PageSize.A4.getWidth(),
PageSize.A4.getHeight());
}
pdf.setPageSize(PageSize.A4);
}
//image.scaleToFit(PageSize.A4.getWidth(),
PageSize.A4.getHeight());
//pdf.setPageSize(image);
pdf.newPage();
try {
pdf.add(image);
} catch (DocumentException e) {
// sollte nicht passieren, da nur geworfen falls
Dokument (pdf) nicht
geöffnet ("when a document isn't open yet, or has been closed").
throw new IllegalStateException(e);
}
}
"
--
View this message in context:
http://itext-general.2136553.n4.nabble.com/getDpiX-Y-returns-0-or-wrong-value-but-WinExplorer-and-Acrobate-get-Dpi-tp2237115p2237268.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/