PHP Classes

File: pdf_example.php

Recommend this page to a friend!
  Classes of Rene Kluwen   pdf_search   pdf_example.php   Download  
File: pdf_example.php
Role: Example script
Content type: text/plain
Description: Example usage
Class: pdf_search
Searches pdf documents for text
Author: By
Last change: Added author
Date: 21 years ago
Size: 1,048 bytes
 

Contents

Class file image Download
<?

/**********************************************************************
**
** Example script that goes with the pdf_search class.
**
** License: Public Domain
** Warranty: None
**
** Author: Rene Kluwen / Chimit Software <rene.kluwen@chimit.nl>
**
***********************************************************************/

require("pdfsearch.php");

// The following determines the document to search in.
$theDocument = "MyDocument.pdf";

// The text to search for. Usually we get this as a result of a form
// submit.
$searchText = "marbles";

// First we read the document into memory space.
// Also, pdf documents can be read from a database or otherwise
// (which is what I did when writing the class).
$fp = fopen($theDocument, "r");
$content = fread($fp, filesize($theDocument));
fclose($fp);

// Allocate class instance
$pdf = new pdf_search($content);

// And do the search
if ($pdf->textfound($searchText)) {
    echo
"We found $searchText.";
}
else {
    echo
"$searchText was not found.";
}

?>