Asked  7 Months ago    Answers:  5   Viewed   45 times

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)



Check out FPDF (with 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:

Update to add a more modern library: PDF Parser

Wednesday, March 31, 2021
answered 7 Months ago

You need DomPDF for rendering the PDF. Check if you have the DomPDF library, otherwise download and implement it as follow:

$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
$rendererLibrary = 'domPDF0.6.0beta3';
$rendererLibraryPath = dirname(__FILE__). 'libs/classes/dompdf' . $rendererLibrary;
Wednesday, March 31, 2021
answered 7 Months ago

The problem is that you're using file_get_contents incorrectly; as you've used it, it will fetch the contents of include.php, not the results of its execution. You need to expand it to a full URL in order to have it fetched that way, though I would advise not doing that. Have the script generate a PDF file and then load that, using the file output option of mpdf:

$mpdf = new mPDF();
$mpdf->Output('/path/to/files/doc.pdf', 'F');

Then run that script and attach the resulting file from PHPMailer (and delete the file afterwards):

include 'invoice.php';
$mail = new PHPMailer();

You could skip the external file approach by using the "return a string" output mode (S) of the Output method and returning the string from the included file:

$mpdf = new mPDF();
return $mpdf->Output('doc.pdf', 'S');

and then:

$pdf = include 'invoice.php';
$mail = new PHPMailer();
$mail->addStringAttachment($pdf, 'doc.pdf');
Wednesday, March 31, 2021
answered 7 Months ago

You need to implement the skipping functionality yourself in PHP. This is a code snippet that will do that.


$path = 'file.mp4';


if(!$fm) {
  // You can also redirect here
  header ("HTTP/1.0 404 Not Found");


if(isset($_SERVER['HTTP_RANGE'])) {
  if(preg_match('/bytes=h*(d+)-(d*)[D.*]?/i', $_SERVER['HTTP_RANGE'], $matches)) {
    if(!empty($matches[1])) {

  header('HTTP/1.0 206 Partial Content');
  header('HTTP/1.0 200 OK');

header("Content-Type: video/mp4");
header('Accept-Ranges: bytes');
header("Content-Disposition: inline;");
header("Content-Range: bytes $begin-$end/$size");
header("Content-Transfer-Encoding: binaryn");
header('Connection: close');


{ print fread($fm,min(1024*16,$end-$cur));

More Performance

Note that this is not the most efficient way to do it, because the whole file needs to go through PHP, so you will just need to try how it goes for you.

Assuming the reason you want to do this is to restrict access, and you need more efficiency later, you can use a flag for the web server.

Apache with X-Sendfile module or lightty (nginx info here)

$path = 'file.mp4';
header("X-Sendfile: $path");

This is a bit more advanced and you should only use it if you need it, but it is relaxing to know you have an upgrade option when you start out with something that is rather easy but has mediocre performance.

Thursday, June 10, 2021
answered 5 Months ago

i have a library that can do this exact thing linked over here :

Sunday, June 27, 2021
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :