How to Read PDF Files in PHP

Save

Reading a PDF file is becoming more necessary for programmers, as the use of these dynamic file types is growing. Reading PDF files requires an extra component added to the host server. This component is then called in the PHP file, enabling the compiler to read the content.

  • Download the component. The component used in this example is XPDF. The software can be downloaded from the following address:
    foolabs.com/xpdf/download.html

  • Unzip the files from the download into the local bin directory of the web host. This bin directory needs to be a place where the PHP compiler has access to call the software's executable files.

  • Create a string with the path to the PDF file. Below is a string variable assigned the path of the PDF file to read.
    $path = "c:\myFile.PDF";

  • Read the content of a file into another string variable. The following code retrieves the PDF file using the add-on installed in Step 2:
    $myPDFString = shell_exec('/usr/local/bin/pdftotext '.$path.' -');

References

Promoted By Zergnet

Comments

You May Also Like

Related Searches

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!