I am using PDFBox library and create a A4 (8.5x11 inches) page size. Now I have images with 2500x3300 size that I want to write on PDF. But pdf size is actually is 612 x 792, how to write 300 DPI images to PDF ?
If I resize image to fit 2500x3300 -> 612x792, it loses quality. There should be some method to write image to pdf whose have 300 DPI.
I am using PDFBox, Please let me know if I missed anything in above explanation
Updated Question:
Let me explain the question in other way I want to provide a customize setting to user to provide the DPI of image with which image will be drawn to PDF. I know PDFBox can write images to PDF but there is no such DPI settings available which I can use to write images to PDF with respect to DPI. Currently I am using PDFBox with is using PDPageContentStream.drawImage(img, , ); but there is no DPI parameter available to write image on PDF. Please tell me method which we can use to draw images to pdf with DPI parameters.
Thanks
If the process does not down sample the image (the number of pixels does not changes), then you are not loosing quality. The resolution may change though if the physical dimensions of the image in the PDF changes but that does not decrease the quality; it just looks smaller or bigger.
If you want the resolution to stay the same, then the physical dimensions of the image in the PDF follows from that:
image width = 2500 / 300 inch = 600 points; image height = 3300 / 300 inch = 792 points
Your A4:
page width = 8.5 inch = 612 points; page height = 11 inch = 792 points
That is actually a nice fit.
Add a horizontal translation of 0, 6 or 12 points to horizontally align the image left, center or right.
--- update
You should not consider DPI as a setting when converting a raster image to PDF (or better: when creating a PDF page with an image on it). The DPI follows from the number of pixel rows and columns of the raster image -and- the physical width and height of that image on the PDF page. If you don't touch the image - which I assume because you don't want to loose quality - then you have to choose the physical width and height such that the resultant DPI is as required. DPI = #pixels / inch.