pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eliot Kimber <ekim...@rsicms.com>
Subject Understanding Image Placement and Sizing
Date Thu, 17 Jan 2013 00:07:07 GMT
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?

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.

Thanks,

Eliot

-- 
Eliot Kimber
Senior Solutions Architect, RSI Content Solutions
"Bringing Strategy, Content, and Technology Together"
Main: 512.554.9368
www.rsicms.com
www.rsuitecms.com
Book: DITA For Practitioners, from XML Press,
http://xmlpress.net/publications/dita/practitioners-1/


Mime
View raw message