PdfBox-Android
PdfBox-Android copied to clipboard
Setting Page dimensions/DPI of Images
In PDImageXObject.createJPEG the dpi parameter is not used at all. The Bitmap and/or Canvas dpi should be set to the given value (I don't know if that works correctly). How do I create pages of a given size and draw Bitmaps on it in the correct size?
Size of A4 page was only around 595 x 841 and I had to resize all images to very less resolution. I couldn't write high quality images of documents as they get very pixelated to a point where it makes the text impossible to read. Any way to write HQ images?
to make use of the dpi parameter set the canvas' dpi to 72. see https://stackoverflow.com/a/47970652
The dpi parameter appears to only change the metadata for the image, so it isn't the issue. Are the images pixelated when generating a PDF or is it pixelated when you are trying to render a PDF to an image?
The dpi parameter should determine the size of the image on the page, if you want the page to be of a specific physical size. So you have to set the dpi of the bitmap to the desired value and set the dpi of the canvas to "undetermined" explicitely, i.e. 72pt. All of this should happen in PDImageXObject.createJPEG.
@hurzl did you find the solution for this?
No :(
@hurzl the only walk around i found is to use bigger page (A3 OR A2 ) and them scale the image.
This way the image doesn't lose any quality but the pdf dimensions is not A4.
I switched to android.graphics.pdf.PdfDocument ;)
But using pdfdocument increases the pdf size considerably.
How did you manage to solve that?
On Wed, Oct 21, 2020, 6:20 PM hurzl [email protected] wrote:
I switched to android.graphics.pdf.PdfDocument ;)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/TomRoush/PdfBox-Android/issues/138#issuecomment-713545239, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEEZXYHL2MYE4EEGSNJ4FW3SL3KIJANCNFSM4EIOZBCQ .
I didn't find that. I only had to split into 50 page pieces and join them via com.lowagie.text.pdf.PdfWriter.
Maybe your size increase has to do with resolution?