Jump to content


Photo

Find out Width and Height of a given PDF file


  • Please log in to reply
2 replies to this topic

#1 pranaysharmadelhi

pranaysharmadelhi

    Newbie

  • New Members
  • Pip
  • 1 posts

Posted 24 November 2008 - 01:45 PM

Hi,
I am working on a project which requires the following:
User uploads a pdf file(through basic php form)
pdf is stored temporarily and the Width/Height of the pdf is checked against a matrix in database and a price is calculated and the user is sent to shopping cart for printing.
I have tried fpdi with FPDF and TCPDF but both of them require me to enter a value for a new PDF and then import an existing PDF.  ???
I am having hard time finding out how to find out widht/height of the imported pdf and also how many pages exists.
Any help would be greatly appreciated.

Thanks!

#2 jwilliam

jwilliam

    Member

  • Members
  • PipPip
  • 13 posts

Posted 24 November 2008 - 02:18 PM

This is the way I do it, but you'll need to be on a linux server with Image Magick installed:

$command = escapeshellcmd('identify -format "%wx%h" ' . $path_to_pdf) . '[0]';
$geometry = `$command`;
list($width, $height) = split("x", $geometry);

Then you can access the dimensions through $width and $height.

#3 Mchl

Mchl

    Advanced Member

  • Staff Alumni
  • 8,507 posts
  • LocationHigh Memory Area

Posted 24 November 2008 - 02:34 PM

Correct if I'm wrong, but every page in PDF file can have different dimensions, so you will need to get all of them.
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com