Reputation: 77
I have PDFs with filled out form fields from a customer, which have to be parsed with PHP5 and written into a MySQL-DB.
With Google I only find libraries, like Zend_Pdf, which are helpful for creating or manipulating PDFs but not for parsing for form fields. Do you know any libraries or classes for this task?
Upvotes: 5
Views: 7421
Reputation: 1002
EDIT: The originaly posted solution only returns all form fields, without their filled values. To retrieve field values the approach of @max-matti in the comments can be used.
This solution works without any additional dependencies/requirements:
Use the FPDM
class: https://github.com/codeshell/fpdm.
Then define your own class that extends FPDM
and retrieves the protected value_entries
after calling merge()
on your PDF file.
Your class:
use \FPDM;
class FPDMHelper extends FPDM {
public function getFormFields() {
$this->merge();
return $this->value_entries;
}
}
And call it like this:
$pathToYourFile = __DIR__.'\your-file.pdf';
$pdf = new FPDMHelper($pathToYourFile);
$formFields = $pdf->getFormFields();
print_r($formFields);
Upvotes: 0
Reputation: 196
Take a look at this project on github... php-pdftk I was looking for the same thing and found this project which appears to provide a nice wrapper to pdftk for use in PHP.
Upvotes: 1
Reputation: 54056
Check out Pdftk. It allows you to manipulate PDF files in many ways.
Upvotes: 2