Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7607577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:41:57+00:00 2026-05-31T00:41:57+00:00

I have a PDF file. I would to get it height and width in

  • 0

I have a PDF file.
I would to get it height and width in mm.

So I do an exec(pdfinfo … );
I have this result :

Creator: Adobe InDesign CS5 (7.0.3) Producer: Acrobat Distiller 9.4.2 (Macintosh) CreationDate: Mon Jan 30 15:48:43 2012 ModDate: Fri Feb 10 10:35:05 2012 Tagged: no Pages: 34 Encrypted: no Page size: 552.744 x 708.643 pts File size: 80724791 bytes Optimized: yes PDF version: 1.3

I have a script witch extract my info :

<?php 
$output = shell_exec("pdfinfo ".$pdflivrelink);
$data = explode("\n", $output); //puts it into an array
for($c=0; $c < count($data); $c++) {
        if(stristr($data[$c],"Pages") == true) {
        $pagesnumber = trim(substr($data[$c],6));
        }
        if(stristr($data[$c],"Page size") == true) {
            $pagesize_H = height_pdf(trim(substr($data[$c],9)));
        }
        if(stristr($data[$c],"Page size") == true) {
            $pagesize_L = width_pdf(trim(substr($data[$c],9)));
        }

}
function height_pdf($size){
$hauteur = round(substr($size,7,7)/2.83);
return $hauteur;
}
function width_pdf($size){
$largeur = round(substr($size,17,7)/2.83);
return $largeur;
} ?>

It’s OK, because I have three numbers dot three numbers (552.744 x 708.643).
But, I don’t know why, some PDF files have this info :

Creator: pdftk 1.41 – http://www.pdftk.com Producer: iText 2.1.5 (by lowagie.com) CreationDate: Mon Feb 27 13:18:23 2012 ModDate: Mon Feb 27 16:26:12 2012 Tagged: no Pages: 36 Encrypted: no Page size: 425.2 x 538.582 pts File size: 5097597 bytes Optimized: yes PDF version: 1.6

425.2 x 538.582 : So my script doesn’t work!

Can you help me? thank a lot!


I test this :

    $output = shell_exec("pdfinfo ".$pdflivrelink);
    $data = explode("\n", $output); //puts it into an array
    for($c=0; $c < count($data); $c++) {
            if(stristr($data[$c],"Pages") == true) {
            $pagesnumber = trim(substr($data[$c],6));

            }
            if(stristr($data[$c],"Page size") == true) {
                echo $data[$c];
    preg_match('/Page size: ([0-9]*\.?[0-9]?) x ([0-9]*\.?[0-9]?)/', $data[$c], $matchess);
    $width = round($matchess[1]/2.83);
    $height = round($matchess[2]/2.83);

            }
}
echo "width = $width<br>height = $height";

it result :

Page size: 425.2 x 538.582 ptswidth = 0 height = 0

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:41:58+00:00Added an answer on May 31, 2026 at 12:41 am

    A little regex will get you the correct results.

    <?php
    $str = 'Creator: pdftk 1.41 - www.pdftk.com Producer: iText 2.1.5 (by lowagie.com) CreationDate: Mon Feb 27 13:18:23 2012 ModDate: Mon Feb 27 16:26:12 2012 Tagged: no Pages: 36 Encrypted: no Page size: 425.2 x 538.582 pts File size: 5097597 bytes Optimized: yes PDF version: 1.6';
    
    preg_match('/Page size: ([0-9]*\.?[0-9]?) x ([0-9]*\.?[0-9]?)/', $str, $matches);
    $width = round($matches[1]/2.83);
    $height = round($matches[2]/2.83);
    
    echo "width = $width<br>height = $height";
    ?>
    

    Update ( asked for more details ) :
    Complete working example below. I’ve updated Regex to match real output from pdfinfo

    <?php
    
    $output = shell_exec("pdfinfo ".$pdflivrelink);
    
    // find page count
    preg_match('/Pages:\s+([0-9]+)/', $output, $pagecountmatches);
    $pagecount = $pagecountmatches[1];
    
    // find page sizes
    preg_match('/Page size:\s+([0-9]{0,5}\.?[0-9]{0,3}) x ([0-9]{0,5}\.?[0-9]{0,3})/', $output, $pagesizematches);
    $width = round($pagesizematches[1]/2.83);
    $height = round($pagesizematches[2]/2.83);
    
    echo "pagecount = $pagecount <br>width = $width<br>height = $height";
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website that generates pdf file from CSP. Will this pdf file
I have this code that saves a pdf file. FileStream fs = new FileStream(SaveLocation,
I have a PDF file that's an output from an OCR processor, this OCR
I have a Django application which prints out a pdf file. I would like
I have a PDF file, which contains data that we need to import into
I have a pdf file.I need to find all the hyperlinks available in that
So, I have a .pdf file and I need to be able to determine
I have some code to read from a pdf file. Is there a way
I have an app that needs to read a PDF file from the file
I have an ASP.net application which returns a binary PDF file (stored from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.