我使用iText 1.3将图像文件(gif,png,jpg,bmp)成功转换为pdf。 我无法更改版本,因为我们不能在专业环境中明显更改jar版本。使用iText和Java将图像转换为pdf
我遇到的问题是PDF中图像的大小比图像本身大。我不是在谈论文件大小,而是在原始图像文件和PDF上的缩放设置为100%时图像的大小。 pdf显示比原始图像大20%到30%的图像。
我在做什么错?
public void convertOtherImages2pdf(byte[] in, OutputStream out, String title, String author) throws IOException {
Image image = Image.getInstance(in);
Rectangle imageSize = new Rectangle(image.width() + 1f, image.height() + 1f);
image.scaleAbsolute(image.width(), image.height());
com.lowagie.text.Document document = new com.lowagie.text.Document(imageSize, 0, 0, 0, 0);
PdfWriter writer = PdfWriter.getInstance(document, out);
document.open();
document.add(image);
document.close();
writer.close();
}
两者都是100%。如果我把它们放在一起,你可以清楚地看到不同之处(或通过alt + tab)。 –