मुझे यह मिला और यह मेरे लिए काम करता है। यह ज़ेड के लिए एफडीएफ फॉर्म फ़ील्ड भरने के लिए एक अनौपचारिक पैच है। Site with the discussion and patch
कोई इंस्टॉलेशन, नहीं बाहर कार्यक्रमों, नहीं निर्देशांक
उपयोग:
$pdf = Zend_Pdf::load('input-file-containing-form.pdf');
$pdf->setTextField('name', 'Someone');
$pdf->setTextField('address', '1 Main Street');
$pdf->setTextField('city', 'Cyberspace');
$pdf->save('outputfile.pdf');
पृष्ठ अब यहाँ मौजूद है पीडीएफ के लिए पैच है।php (अगर किसी को समस्या है - मुझे निजी संदेश लिखें):
--- Pdf.php.orig 2009-11-15 17:52:57.000000000 +0100
+++ Pdf.php 2010-01-07 04:05:23.000000000 +0100
@@ -202,6 +202,13 @@
* @var array
*/
protected static $_inheritableAttributes = array('Resources', 'MediaBox', 'CropBox', 'Rotate');
+
+ /**
+ * List of form fields
+ *
+ * @var array - Associative array, key: name of form field, value: Zend_Pdf_Element
+ */
+ protected $_formFields = array();
/**
* Request used memory manager
@@ -315,6 +322,7 @@
$this->_loadNamedDestinations($this->_trailer->Root, $this->_parser->getPDFVersion());
$this->_loadOutlines($this->_trailer->Root);
+ $this->_loadFormfields($this->_trailer->Root);
if ($this->_trailer->Info !== null) {
$this->properties = $this->_trailer->Info->toPhp();
@@ -557,6 +565,61 @@
$this->_originalOpenOutlinesCount = $root->Outlines->Count->value;
}
}
+
+ /**
+ * Load form fields
+ * Populates the _formFields array, for later lookup of fields by name
+ *
+ * @param Zend_Pdf_Element_Reference $root Document catalog entry
+ */
+ protected function _loadFormFields(Zend_Pdf_Element_Reference $root)
+ {
+ if ($root->AcroForm === null || $root->AcroForm->Fields === null) {
+ return;
+ }
+
+ foreach ($root->AcroForm->Fields->items as $field)
+ {
+ if ($field->FT->value == 'Tx' && $field->T !== null) /* We only support fields that are textfields and have a name */
+ {
+ $this->_formFields[$field->T->value] = $field;
+ }
+ }
+
+ if (!$root->AcroForm->NeedAppearances || !$root->AcroForm->NeedAppearances->value)
+ {
+ /* Ask the .pdf viewer to generate its own appearance data, so we do not have to */
+ $root->AcroForm->add(new Zend_Pdf_Element_Name('NeedAppearances'), new Zend_Pdf_Element_Boolean(true));
+ $root->AcroForm->touch();
+ }
+ }
+
+ /**
+ * Retrieves a list with the names of the AcroForm textfields in the PDF
+ *
+ * @return array of strings
+ */
+ public function getTextFieldNames()
+ {
+ return array_keys($this->_formFields);
+ }
+
+ /**
+ * Sets the value of an AcroForm text field
+ *
+ * @param string $name Name of textfield
+ * @param string $value Value
+ * @throws Zend_Pdf_Exception if the textfield does not exist in the pdf
+ */
+ public function setTextField($name, $value)
+ {
+ if (!isset($this->_formFields[$name]))
+ throw new Zend_Pdf_Exception("Field '$name' does not exist or is not a textfield");
+
+ $field = $this->_formFields[$name];
+ $field->add(new Zend_Pdf_Element_Name('V'), new Zend_Pdf_Element_String($value));
+ $field->touch();
+ }
/**
* Orginize pages to tha pages tree structure.
स्रोत
2012-08-03 09:47:30
आपके उत्तर के लिए बहुत बहुत धन्यवाद। मुझे आपके से थोड़ा और चाहिए, क्या पीडीएफटीके सर्वर पर कुछ स्थापित होना चाहिए ?? मैंने पीडीएफ के साथ काम नहीं किया, क्या कोई उदाहरण है, या आप थोड़ा और बता सकते हैं कि मैं बाहरी प्रोग्राम कैसे निष्पादित कर सकता हूं ?? कृपया मेरी मदद करें। – Sohail
हां, सर्वर पर पीडीएफटीके स्थापित करें। आप [निर्देश यहां] (http://www.pdflabs.com/docs/install-pdftk/) पा सकते हैं। PHP से सिस्टम कमांड निष्पादित करने के लिए बस निष्पादन फ़ंक्शन को कॉल करें। उदाहरण के लिए। ' php exec ('/ usr/bin/pdftk form.pdf fill_form data.fdf output form_with_data.pdf'); ?> ' –
थेंक्स रिचर्ड, मैं कोशिश करूंगा। बहुत - बहुत धन्यवाद। – Sohail