I have seen code to extract the images based on image DPI using PDFBox like below
PDDocument document = PDDocument.load(path);
PDFImageWriter writer = new PDFImageWriter();
boolean success = writer.writeImage(document, "jpg", "", 1, 1,
"C:\\Image Quality\\150", BufferedImage.TYPE_INT_RGB, 150);
return document;
In above code I can specify the image resolution(150) while extracting the image from pdf. With higher resolution I get larger image in return.
Now I want reverse of it means to specify the resolution/dpi of image while writing image to PDF, but following code is not providing such options to specify DPI ? Can anyone guide me where I am missing
PDPageContentStream contentStream = null;
contentStream = new PDPageContentStream(document, userPage);
contentStream.drawImage(img, 60, 60);
contentStream.close();
Please guide me where I can pass the parameter of resolution/DPI (as image is larger than pdf page size) while writing image to PDF ?
Thanks,
drawImage
embeds the downsampled image.drawXObject
on the other hand embeds the original image and scales it. Thus, at high resolution print-out the former only supplies the downsampled, less resolved image while the latter allows the higher resolved image to be output. – mkl