PdfBox-Android icon indicating copy to clipboard operation
PdfBox-Android copied to clipboard

Setting Page dimensions/DPI of Images

Open hurzl opened this issue 7 years ago • 10 comments
trafficstars

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?

hurzl avatar Dec 15 '17 16:12 hurzl

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?

saravanabalagi avatar Dec 27 '17 14:12 saravanabalagi

to make use of the dpi parameter set the canvas' dpi to 72. see https://stackoverflow.com/a/47970652

hurzl avatar Jan 09 '18 11:01 hurzl

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?

TomRoush avatar Jan 19 '18 20:01 TomRoush

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 avatar Jan 20 '18 14:01 hurzl

@hurzl did you find the solution for this?

maxakash avatar Oct 21 '20 06:10 maxakash

No :(

hurzl avatar Oct 21 '20 11:10 hurzl

@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.

maxakash avatar Oct 21 '20 11:10 maxakash

I switched to android.graphics.pdf.PdfDocument ;)

hurzl avatar Oct 21 '20 12:10 hurzl

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 .

maxakash avatar Oct 21 '20 12:10 maxakash

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?

hurzl avatar Oct 21 '20 13:10 hurzl