Example #1
0
 /**
  * Returns the pdftk singleton.
  * @return Pdftk the Pdftk singleton.
  */
 public static function getInstance()
 {
     if (empty(self::$_instance)) {
         self::$_instance = new Pdftk();
     }
     return self::$_instance;
 }
Example #2
0
 /**
  * Fill the PDF form
  * @param boolean $runValidation whether to perform validation before filling the form.
  * If the validation fails, the data will not be filled in.
  * @param array $attributes list of attributes that need to be saved. Defaults to null,
  * meaning all attributes that are loaded from PDF meta data will be filled.
  * @return PdfString instance of filled form on sucess false on failure
  */
 public function fill($runValidation = true, $attributes = null)
 {
     if (!$runValidation || $this->validate($attributes)) {
         $pdftk = Pdftk::getInstance();
         if (false !== ($result = $pdftk->fillForm($this, $this->getFdf($attributes)))) {
             return new PdfString($result);
         }
     }
     return false;
 }
Example #3
0
 /**
  * Constructor.
  * @param PdfFile $pdf the PDF file instance
  */
 public function __construct(PdfFile $pdf)
 {
     $this->_pdf = $pdf;
     $pdftk = Pdftk::getInstance();
     $result = $pdftk->dumpDataFields($pdf);
     for ($i = 0, $count = count($result); $i < $count; $i++) {
         $column = array();
         while ($i < $count && '---' !== $result[$i]) {
             list($name, $value) = explode(':', $result[$i], 2);
             $column[trim($name)] = trim($value);
             $i++;
         }
         if (isset($column['FieldName'])) {
             $this->fields[$column['FieldName']] = $column;
         }
     }
 }
Example #4
0
 /**
  * Apply another PDF as background for each page of current PDF
  * @param PdfFile $back an instance of PdfFile which will be used as a background
  * @return PdfString an instance of PdfString with applied background
  * on success, false on failure
  */
 function applyBackground(PdfFile $back)
 {
     $pdftk = Pdftk::getInstance();
     $result = $pdftk->background($this, $back);
     return $result ? new PdfString($result) : false;
 }