Zend_Pdf操作PDF形態分野
-
26-09-2019 - |
質問
私は現在、プロジェクトが多数形に加工され、保存されました。レッスンを終了する管理通知メールの内容となる。
問題は、これらのいずれかの形式が必要で眺めるとまったく同じように、メバージョンからPDFファイルとなっております。
私には二つの基本的なオプション:
- 図の座標での"分野"私は書く必要があるため、オーバーレイマ描かれたテキストをその座標
- のpdfへのpdf形式を使用Acrobat Proのフォームウィザードを設定し、フィールド値のテンション
オプション1んは可.もちろん、いのではないでしょうか。の問題には複雑で、多くの座標を出---また、多くの試行錯誤しました。
オプション2少ないので、工夫が必要かと思いきやすくていいアクセスできる分野を通して繰り返しまたは名前とidをセットするだけで、実際に値です。
その後、私の質問は、Zend_Pdf支援の操作PDF形式。あまりないと思いまったくなにも見え、API以外の提出およびリセットフォームのアクションうることを示に対応します。
また、その他のOO F/OSS PDF図書館支援オプション2うことを聞いてんでいるかのようにして、他の代替アプローチ。
解決
申し訳は少し遅いものの考えをクリックすると、含まれる...
アクセスできる場合は付加部品をサーバーを利用することができPDF研PDF Tooklit(pdftk)図書館ではコマンドライン用ができることで利用できるシステム/exec/passthruコマンドをクリアしました。まpdftkしい情報はこちら http://www.pdflabs.com/docs/pdftk-man-page/ PDFTK可能にする合併し、Pdfの追加の背景のPdfに記入フォームフィール内のPDF(荷重)をする必要はないと思います。fill_formスイッチです。
場合は追加できますpdftkをサーバーそしても利用できるアンドリュー Heissのpdftk-phpのクラスのしやすいように更新の分野におpdfから情報を引きからDBき出すことができ詳細情報: https://github.com/andrewheiss/pdftk-php/
では最後に一言だったPdfの作成の直接HTMLからその後の解WKHTML2PDF- http://code.google.com/p/wkhtmltopdf/ では作品のようなPDF画面のHTML画面(複雑によるものがある。
としてできるのではないでしょうかかいても同様の問題が楽く頭痛に働きます。
他のヒント
prodigitalson,しようと思ったのはこのソリューション、などの場合については、好奇心を持つことから始まいを探しています。でのみ動作プログラミング言語の最適化のためのバージョン1.5(Acrobat6.0)な作品を彩ります。では、各社の商標または登録商標パッチZend Framework1.12.3くPDF形式ます。 サイトの議論とパッチ
インスタンスは、外部プログラムは、座標
最初の更新をクリアしました。iniファイルを以下のようなもの(注っているのかわからない難しい変更.iniファイルも実際にwebサーバーの時にアップロードこれらの変化):
include_path = ".;C:\wamp\www\includes"
ただ注意:いすべての図書館のコンテンツから'ZendFramework-1.12.3\図書館フォルダのフォルダへというZend: C:\wamp\www\includes\Zend
を容易に参照での図書館において必要とするすべて鏡).
そしてphpファイルを使った'DIRECTORY_SEPARATORいただけるよう、使用でき勝利やUnixサーバとなっている任意のコードで変化がmy.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ファイルのないように詰まっサーバー:attach_mailer_class.php こちらでご用意 Copyright(c)2006年、オラフ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);
場合はページが存在しないこちらのパッチPDF.php (わからない場合はどのように実際にパッチ、基本的にはすごPDF.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.