Well, I found a way to add images without losing quality.
Actually, so that the image is not blurry, I let the PDFBox resize the image, giving it the desired size. Like the code below:
PDXObjectImage ximage = new PDJpeg(doc, new FileInputStream(new File("/usr/gyo/my_large_image.jpg")), 1.0f); PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false); Dimension scaledDim = getScaledDimension(new Dimension(ximage.getWidth(), ximage.getHeight()), page.getMediaBox().createDimension()); contentStream.drawXObject(ximage, 1, 1, scaledDim.width, scaledDim.height); contentStream.close();
Thanks,
Ge
Gyowanny pessatto queiroz
source share