我有一个大图像,我想在我的 PDF 文档中打印它,我正在编写以下内容:
InputStream in = new FileInputStream(new File("C:/mylargeimage.jpg"));
PDJpeg img = new PDJpeg(doc, in);
img.setHeight(100);
img.setWidth(100);
contentStream.drawImage(img,50,pageYaxis);
我正在打印图像,但图像变得模糊,无法将完整图像放入其中。我需要将图像调整为 100X100。我怎样才能克服这个?请大家帮帮我??我引用了很多,但没有什么是清楚的。
最佳答案
你试过这样做吗?
InputStream in = new FileInputStream(new File("C:/mylargeimage.jpg"));
PDJpeg img = new PDJpeg(doc, in);
contentStream.drawXObject(img, 50, pageYaxis, 100, 100);
drawImage
的 Javadoc 说它将以图像的默认大小绘制。 drawXObject
的 Javadoc 说:
Draw an xobject(form or image) at the x,y coordinates and a certain width and height.
我相信,对图像本身调用 setWidth
和 setHeight
只会改变 PDFBox 认为是图像的实际大小 - 所以它只需要 100x100 像素图像作为来源。
关于java - 调整大小的PDF图像变得模糊只在pdfbox中变得部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26174551/