Am 17.01.2013 01:07, schrieb Eliot Kimber:
I am placing images onto a PDF page. The incoming images may be much larger (in bytes) than I want to put in the PDF, so I am downsampling as needed to keep the images below a certain maximum size. However, I don't want to downsample too much so that I don't degrade from the original any more than necessary.In my current code I'm generating JPEG images and then loading those as BufferedImages using ImageIO.read()(), creating a PixelMap from the BufferedImage, and then placing them using drawImage(), e.g. (many details omitted): bImage = ImageIO.read(imageFile); PDPixelMap ximage = new PDPixelMap(document, bImage); contentStream.drawImage( ximage, posX, posY); Based on my experiments, it appears that PDFBox takes the extent in pixels of the image as the *point* extent. For example, given an image that is 400x300 pixels, using the above code, the PDF viewed in Acrobat measures the image as 400x300 *points*. That seems wrong to me--my expectation was that the image would reflect the PDF 96ppi resolution, but maybe I've misunderstood that aspect of PDF? In this particular case, 400x300 pixels is too low of a resolution--I could easily have 3 or 4 times that and still be within my size limits. What I haven't quite figured out is how to place a higher-resolution image so that its rendered width is still the 400x300 *points*. I think the correct technique is to calculate the display width (preserving aspect ratio) and then use drawXObject, specifying the width and height parameters. Is that correct or is there something I can do in the construction of the binary image itself to get the effect I want?
Yes, you have to scale the image using one of the drawXObject methods.
I haven't been able to find any code samples or guidance online on this issue, so if I've missed some source of graphic knowledge please point me there.
I'm afraid there is nothing but a simple sample using drawImage
Thanks, Eliot
BR Andreas Lehmkühler

