How to check if a pdf file is blank using php?

by muriel.schmidt , in category: PHP General , 8 months ago

How to check if a pdf file is blank using php?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by edmond_brakus , 8 months ago

@muriel.schmidt 

You can check if a PDF file is blank by using the following code in PHP:

1
2
3
4
5
6
7
8
$pdfFile = 'file.pdf';
$content = file_get_contents($pdfFile);

if (trim($content) == '') {
    echo 'PDF file is blank';
} else {
    echo 'PDF file is not blank';
}


This code reads the contents of the PDF file using file_get_contents and then checks if the content is empty by t******* any whitespace. If the content is empty, it means the PDF file is blank.