pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilad Denneboom <gilad.denneb...@gmail.com>
Subject Re: How to get PDF page width & height?
Date Tue, 02 Apr 2013 08:32:46 GMT
- A PDRectangle object has a getHeight() method as well as a getWidth()
method... It's documented here:
http://pdfbox.apache.org/apidocs/org/apache/pdfbox/pdmodel/common/PDRectangle.html

- The results of these methods are floats, representing the page size in
PostScript points.
To convert them to inches you need to divide them by 72.

- A PDF does not have a single height and width definition. It contains
multiple pages boxes, each one used for different purposes.
So there isn't a single answer to the question: What is the page height and
width of a PDF? Usually, the default property used by most application is
the Crop box, though.

PS - I recommend using the findMediaBox (or findCropBox, or whatever)
methods over the getMediaBox ones.


Gilad



On Tue, Apr 2, 2013 at 2:49 AM, David Luu <mangaroo@gmail.com> wrote:

> I can send an example test PDF if needed. But wanted to know in general how
> to get PDF page size (width & height of page) using PDFBox.
>
> In terms of page size, I'm referring to the value reported by Adobe Acrobat
> Reader Document Properties like "Page Size: 7.25 x 10.25 in" as reported in
> Adobe Reader X.
>
> I don't mind if the value extracted is not in inches as long as I can
> convert the unit from x to inches.
>
> I wasn't able to existing code for it right off the bat. The closest I came
> was in the user guide:
>
> http://pdfbox.apache.org/userguide/
>
> PDPage page = ...;
> PDRectangle mediaBox = page.getMediaBox();
> System.out.println( "Width:" + mediaBox.getWidth() );
>
> but that only gave the width & is based on page width defined by media box.
> What about height? And is media box usually the component within the PDF
> that defines page width & height? If not what else to check for?
>
> Thanks,
> David
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message