English 中文(简体)
Zend_Pdf 操纵 PDF 表格领域
原标题:Zend_Pdf manipulating PDF Form Fields

目前,我有一个项目,处理和储存了一些表格。 成功完成后,通过电子邮件将表格内容通知行政部门。

问题在于其中一种形式,即需要它完全像我以PDF格式编制的邮购单版本。

因此,我有两个基本选择:

  1. Figure out all the coordinates of the "field" i need to write to, and then overlay my drawn text at those coordinates
  2. Turn the pdf into a pdf form using Acrobat Pro s form wizard and then set the field values programmatically

备选案文1一知道是可行的。 我以前做了类似的事情。 问题在于形式相当复杂,有一条坐标坐标线图...... 此外,这一过程还有许多审判和错误。

备选案文2似乎认为,只要能够通过代用或名称/id进入田地,并且仅仅确定价值,就比较容易。

因此,我的问题是,Zentd_Pdf是否支持篡改人民抵抗力量的田地? 我无意看到亚普森文中除提交和重新制定行动之外的任何内容,表明它支持这样做。

此外,如果还有其他的OO F/OSS PDF图书馆将支持备选办法2,即有兴趣听取它们的意见以及任何替代做法。

最佳回答
问题回答

亲森松,我想把这一解决办法交给你,就在你想要找到答案时,你仍然 cur。 它只是优化了第1.5版(Acrobat 6.0)的“人民抵抗力量”的工作,但它确实做了出色的工作。 它是Zentd Framework 1.12.3的一个非正式配送,以填充PDF表格领域:。 讨论地点和发送

不详

第一,更新你的php.ini案卷,其内容类似(注:在我上载这些改动时,我不得不在实际的网络服务器上改变我的基文):

include_path = ".;C:wampwwwincludes"

只是一份说明:我把所有图书馆内容从ZendFramework-1.12.3library 翻到一个叫Zentd的夹:C:wampwwwincludesend。 简而言之,方便查询图书馆(你们都需要任何途径)。

之后,在你的实验室档案中(我使用DIRECTORY_SEPARATOR,以便你能够在Win或Unix服务器上使用该软件,而且我得票,不得不根据我的.php档案,对密码作任何改动,我只不得不改变服务器配置):

require_once( Zend .DIRECTORY_SEPARATOR. Loader .DIRECTORY_SEPARATOR. Autoloader.php );
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace( Zend_ );

之后,实际使用代码:

$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 );

或者,正如我为我的目的所做的那样(我还列入了我用来发送我已完成的就业申请的密码,然后删除了.pdf文档,以便其能够把我的服务器 up起来:随附:电子邮箱_em.php;(c) 2006, Olaf Lederer:

// Write $_POST form data to associative array
foreach ($_POST as $key => $value) { 
    $NameArray[$key] = $value;
}

// Path to PDF application fillable file
$pdf_path = dirname(__FILE__) . "\docs";
$pdf_filename =  employment_applicationJBzend.pdf ;
$pdf_file_path = $pdf_path . "\" . $pdf_filename;

// Path to PDF application file save location
$result_path = dirname(__FILE__) . "\results";
$result_filename = ucfirst($_POST[ first_name ]) . ucfirst($_POST[ last_name ]) . $filedatetime .  .pdf ;
$result_file_path = $result_path . "\" . $result_filename;

//Filling PDF fields | Example: $pdf->setTextField( position_applied_for ,  IT Manager );
$pdf = Zend_Pdf::load($pdf_file_path);

foreach ($NameArray as $key1 => $value) {
    foreach($ExceptionArray as $key2 => $value)
    {
        if($key1 == $ExceptionArray[$key2]){
            $boolSetText = false;
            break;
        }else{
            $boolSetText = true;
        }
    }
    if($boolSetText){
        $pdf->setTextField($key1, $NameArray[$key1]); 
    }
}
$pdf->save($result_file_path);

//Create and send message using  attach_mailer_class.php
$email = new attach_mailer($from_name, $from_mail, $mail_to, $cc = "", $bcc = "", $subject);
$email->text_body = $message;
$email->add_attach_file($result_file_path);
// $email->add_attach_file("ip2nation.zip"); 
$email->process_mail();
unlink($result_file_path);

如果一页已经不复存在,那是国防军的派系。 php(如果你不知道如何管理实际派遣,你基本上通过你们的国防军。) php在前面提出并取代以下所有线: 你们可以发现,他们的位置是标签@-202,6 +202,13 @,该位置位于第200条左右,然后是复制件和过去,用新版取代旧法典:

--- 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.




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签