ank5
asked on
PDFBox - convert image to PDF, PDF resolution
I am using PDFBox v2 to convert jpg images to PDF. JPG image is already on the filesystem, so I just pick it up and convert it to PDF. Below is my code
This code does the conversion just fine. However, I have observed the following in converted PDFs
1. When I open a converted PDF, it opens very slowly (in Acrobat reader). It seems as it PDF is opening pixel by pixel. If I open any other PDF, it opens just fine.
2. The default size in acrobat reader is shown to a smaller value (like 15% or 24%, screenshot attached) for converted PDFs. Even though it covers 100% of the screen (15% sould have implied that I see a much smaller image, but that is not the case). When I change the size to 100%, I see a highly blurred image which is much larger than the actual image and I have to scroll left/right and top/down to see the complete image.
Both these observations make me feel that for some reason the PDF that is getting generated is a much higher resolution than it should have been. Would that be a fair statement? If so, how can I correct this?
PDFSize.PNG
public void convertImgToPDF(String imagePath, String fileName, String destDir) throws IOException {
PDDocument document = new PDDocument();
InputStream in = new FileInputStream(imagePath);
BufferedImage bimg = ImageIO.read(in);
float width = bimg.getWidth();
float height = bimg.getHeight();
PDPage page = new PDPage(new PDRectangle(width, height));
document.addPage(page);
PDImageXObject img = PDImageXObject.createFromFile(imagePath, document);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.drawImage(img, 0, 0);
contentStream.close();
in.close();
document.save(destDir + "/" + fileName + ".pdf");
document.close();
}
This code does the conversion just fine. However, I have observed the following in converted PDFs
1. When I open a converted PDF, it opens very slowly (in Acrobat reader). It seems as it PDF is opening pixel by pixel. If I open any other PDF, it opens just fine.
2. The default size in acrobat reader is shown to a smaller value (like 15% or 24%, screenshot attached) for converted PDFs. Even though it covers 100% of the screen (15% sould have implied that I see a much smaller image, but that is not the case). When I change the size to 100%, I see a highly blurred image which is much larger than the actual image and I have to scroll left/right and top/down to see the complete image.
Both these observations make me feel that for some reason the PDF that is getting generated is a much higher resolution than it should have been. Would that be a fair statement? If so, how can I correct this?
PDFSize.PNG
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Usually I prefer to use Image to PDF converter when I have to convert multiple Image into PDF file format. I think it can prove useful for you too. But I would like to suggest you to try the free version first. When you are totally satisfied with the tool then only it's beneficial to purchase it.
Thanks & Regards
Edwin Hoffer