使用Itext的图像质量 [英] Image Quality using Itext

查看:153
本文介绍了使用Itext的图像质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用Itext生成PDF文档,其中包含分辨率为150 dpi的imgages。

Is possible to generate a PDF document using Itext which contains imgages with a resolution of 150 dpi.

(似乎Itext正在将图像质量降低到72 dpi。)

(Seems to be that Itext is reducing the quality of images to 72 dpi.)

谢谢

推荐答案

请参阅主题,特别是这篇文章解释了PDF没有DPI的概念。 此主题也是一本很好的读物。

See this thread, specifically this post which explains that PDFs don't have a concept of DPI. This thread is a good read, too.

默认情况下,基本上(这在技术上并不准确但足够接近),当您使用iText放置图像时,假定每72个像素使用1英寸的打印空间。如果要更改此规则,则需要更改图像的矩阵。您可以直接执行此操作(这很难)或使用缩放方法(更容易),例如 scaleAbsolute() scaleAbsoluteWidth() scaleAbsoluteHeight() scalePercentage()
scaleToFit()

Essentially (and this isn't technically accurate but close enough) by default, when you place an image using iText assume for every 72 pixels that 1 inch of printed space will be used. If you want to change this rule then you need to change the image's matrix. You can either do this directly (which is hard) or use the scaling methods (much easier) such as scaleAbsolute(), scaleAbsoluteWidth(), scaleAbsoluteHeight(), scalePercentage() and scaleToFit().

更改矩阵 更改任何图像它只会(基本上)改变多少像素的定义到一英寸,当打印时你会调用DPI。 (您实际上是在改变图像像素与文档用户单位之间的关系,但实际上您并不需要知道这一点。)因此默认情况下,iText放置的200x200像素图像应打印出来大约2 3/4。如果你打电话给 scaleAbsolute(100,100),它会将这200个像素塞进100个用户单位,给你一个有效的DPI为144,打印到大约1 3/8。

Changing the matrix does not change the image in any way, it only (essentially) changes the definition of how many pixels to cram into an inch, which when printed you would call DPI. (You're actually changing the relationship between image pixels and the document's user units but you don't really need to know that.) So by default, a 200x200 pixel image placed by iText should print out at about 2 3/4". If you call scaleAbsolute(100,100) it will cram those 200 pixels into 100 "user units" giving you an effective DPI of 144 and print at about 1 3/8".

所有这些都会让你的头部受到伤害,特别是如果你习惯于像Adobe Photoshop这样的程序可以让你设置一个某些图像类型的分辨率。不幸的是,这更像是一个打印提示,并没有真正改变文件。 72DPI时的100x100像素图像与300DPI时的100x100像素完全相同,除非打印时。 iText完全忽略了这个打印提示,要么是因为它是全部,要么是因为并非所有图像格式都支持它。 (没有直接相关,但一个常见的误解是Save for Web使图像72DPI在现实时它完全剥离了文件中的分辨率信息。)

All of this can really make your head hurt, especially if you're used to imaging programs such as Adobe Photoshop that allow you to set a "resolution" for some image types. Unfortunately this is more of a "printing hint" and doesn't really change the file that much. A 100x100 pixel image at 72DPI is the exact same as 100x100 pixel at 300DPI, except when printed. iText completely ignores this printing hint, either because that's all it is or because not all image formats support it. (Not directly related, but one common myth is that "Save for Web" makes images 72DPI when reality it completely strips the resolution information from the file.)

忽略实际的内容发生,为了使图像成为您所能想到的150 DPI,以像素为单位获取源图像的​​宽度和高度,并按 0.48 (72除以150)和将这些新数字传递给 scaleAbsolute()

Ignoring what's actually happening, to get the image to be what you think of as 150 DPI, take the source image's width and height in pixels and multiple those by 0.48 (72 divided by 150) and pass those new numbers to scaleAbsolute().

图片上有一个方法类名为 setDPI 但据我所知,它实际上对图像的位置没有任何影响,而且更像是一个信息事情。

There is a method on the Image class called setDPI but as far as I can tell it doesn't actually have any effect on the placement of the image and is more of an informational thing.

这篇关于使用Itext的图像质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆