pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eliot Kimber <ekim...@rsicms.com>
Subject Re: Understanding Image Placement and Sizing
Date Thu, 17 Jan 2013 19:00:41 GMT
Thanks--I am implementing the scaling logic now. I'll share at least the
basic logic if not a usable code sample (this is all embedded in a larger

As for the ppi of the image, I think I must have gotten confused by things I
had stumbled on. The PDF spec (dated 2008) says:

8.9.4 Image Coordinate System

"Each image has its own internal coordinate system, or image space. The
image occupies a rectangle in image space w units wide and h units high,
where w and h are the width and height of the image in samples."

So that means that, barring the application of some graphic transform, that
pixels will equal points since the base measurement unit is points. Since
I'm placing directly onto the page, then it does follow that the size as
rendered should be points equal to the image width.

So I was just doing the wrong thing before.

Since I'm not trying to do anything other than scale (no rotation or
anything) it looks like just using drawXObject() is about as complicated as
I need to be, given code to calculate the effective rendered width and
height based on the graphic's actual pixel dimensions.



On 1/17/13 12:43 PM, "Andreas Lehmkuehler" <andreas@lehmi.de> wrote:

> 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

Eliot Kimber
Senior Solutions Architect, RSI Content Solutions
"Bringing Strategy, Content, and Technology Together"
Main: 512.554.9368
Book: DITA For Practitioners, from XML Press,

View raw message