Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read pdf files with php

Tags:

php

pdf

I have a large PDF file that is a floor map for a building. It has layers for all the office furniture including text boxes of seat location.

My goal is to read this file with PHP, search the document for text layers, get their contents and coordinates in the file. This way I can map out seat locations -> x/y coordinates.

Is there any way to do this via PHP? (Or even Ruby or Python if that's what's necessary)

like image 591
Ryan Doherty Avatar asked Jun 16 '09 23:06

Ryan Doherty


People also ask

Can we read PDF file in PHP?

php“. Include it in the required web page using PHP. Create an HTML form, in which we can choose a PDF file from your computer and also check whether its file extension is PDF or not. Approach: Make sure you have a XAMPP server or WAMP server installed on your machine.

How can I open PDF file in PHP?

Here are two ways. header("Content-type: application/pdf"); header("Content-Disposition: inline; filename=filename. pdf"); @readfile('path\to\filename. pdf');

How can I open PDF file without downloading in PHP?

Under "Privacy and security," click Content settings. Near the bottom, click PDF documents. Turn off Download PDF files instead of automatically opening them in Chrome. Click on Extreme Right 3 lines.

How do I open a PDF file on my website?

Navigate to the "Open With" option and choose "Chrome PDF Viewer" from the drop-down menu. You can also drag a PDF document directly into the browser, and it will open.


2 Answers

Check out FPDF (with FPDI):

http://www.fpdf.org/

http://www.setasign.de/products/pdf-php-solutions/fpdi/

These will let you open an pdf and add content to it in PHP. I'm guessing you can also use their functionality to search through the existing content for the values you need.

Another possible library is TCPDF: https://tcpdf.org/

Update to add a more modern library: PDF Parser

like image 174
Jay Avatar answered Sep 20 '22 14:09

Jay


There is a php library (pdfparser) that does exactly what you want.

project website

http://www.pdfparser.org/

github

https://github.com/smalot/pdfparser

Demo page/api

http://www.pdfparser.org/demo

After including pdfparser in your project you can get all text from mypdf.pdf like so:

<?php $parser = new \installpath\PdfParser\Parser(); $pdf    = $parser->parseFile('mypdf.pdf');   $text = $pdf->getText(); echo $text;//all text from mypdf.pdf  ?> 

Simular you can get the metadata from the pdf as wel as getting the pdf objects (for example images).

like image 27
kasper Taeymans Avatar answered Sep 20 '22 14:09

kasper Taeymans