How can PHP be used to determine the size (page format) of a PDF file?

To determine the size (page format) of a PDF file using PHP, you can use the `getimagesize()` function in combination with the `fopen()` and `fread()` functions to read the PDF file and extract the dimensions of the first page. This information can then be used to determine the size of the PDF file.

$pdfFile = 'example.pdf';

// Open the PDF file
$handle = fopen($pdfFile, 'rb');

// Read the first 20 bytes to identify the PDF version
$data = fread($handle, 20);

// Close the file handle
fclose($handle);

// Check if the file is a PDF
if (preg_match('/%PDF-(\d\.\d)/', $data, $match)) {
    // Get the dimensions of the first page
    $dimensions = getimagesize($pdfFile);
    
    // Output the dimensions
    echo 'Width: ' . $dimensions[0] . ' pixels<br>';
    echo 'Height: ' . $dimensions[1] . ' pixels';
} else {
    echo 'Not a valid PDF file';
}