How to Read PDF Files in PHP
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.
Instructions
-
-
1
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 -
2
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.
-
-
3
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"; -
4
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.' -');
-
1
References
Comments
-
nikossumed
Jun 18, 2010
I have copied xpdf into local bin directory but I can't convert pdf file into text file. A have used this command : '$myPDFString = shell_exec('/usr/local/bin/pdftotext '.$path.' -');'. Is there something I missed?