これ用のプラグインを見つけることができると思っていましたが、ないようです。
必要なプロセスは次のとおりです。
ユーザーがサイトのフォームに入力します (できれば cforms!) フォームからのデータがサーバー上の pdf の空のセルに入力されます
さて、そこまで来たら、次のステップについて心配します。
PDF は法律文書であるため、生成することはできません。
ありがとう。
わかりました、私はこれを行う方法を考え出しました、それは少し厄介なようです、残念なことに、もっと簡単な方法はありません!
私が使用している2つのプラグインは、cforms(www.deliciousdays.com/cforms-plugin)とZendフレームワークをロードするプラグイン(h6e.net/wordpress/plugins/zend-framework)です。 pdf書き込み能力。
両方のプラグインをアクティブにした状態で、my-functions.phpという名前のcformsプラグインディレクトリでファイルを見つけて、コンピュータにダウンロードします。このファイルのほとんどはコメント化されているため、関数のコメントを解除する必要があります
function my_cforms_action($cformsdata) {
}
この関数のすべては、送信ボタンが押されたときに実行されます(詳細については、cforms APIのドキュメントを参照してください)。これが機能していることをテストできますが、この関数で何かをエコーします。Zendフレームワークがロードされていることをテストすることもできます
if (defined('WP_ZEND_FRAMEWORK') && constant('WP_ZEND_FRAMEWORK')) {
echo 'Zend is working!';
}
フォームフィールドは配列になっているので、最初にそれを印刷してフィールドの名前を計算する必要があります(「5」を使用しているフォームに置き換えます)。
$formID = $cformsdata['id'];
$form = $cformsdata['data'];
if ( $formID == '5' ) {
print_r($form);
}
フィールド名を取得したら、これがPDFに書き込む完全なコードです
//Get the ID of the current form and all the data that's been submitted
$formID = $cformsdata['id'];
$form = $cformsdata['data'];
//run this code only if it's the form with this ID
if ( $formID == '5' ) {
//Loads the Zend pdf code
require_once 'Zend/Pdf.php';
//Set the path of the pdf (in the root of my wordpress installation)
$fileName = 'c100-eng2.pdf';
//loads the pdf
$pdf = Zend_Pdf::load($fileName);
//Selects the page to write to
$page = $pdf->pages[0];
//Selects which font to use
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
$page->setFont($font, 12);
//Writes the text from the field 'Your name' 210 points from the left and 420 points from the bottom of the selected page
$page->drawText($form['cf_form5_Your name'], 210, 420);
//for some reason there is no way to wrap text using Zend_pdf so we have to do it ourselves for any paragraphs...
//starting 600 points from the bottom of the page
$startPos = 600;
//we're using the form field "About you"
$paragraph = $form['cf_form5_About you'];
//sets the width of the paragraph to 30 characters
$paragraph = wordwrap( $paragraph, 30, '\n');
//breaks paragraph into lines
$paragraphArray = explode('\n', $paragraph);
//writes out the lines starting 200 points from the left with a line height of 12 points
foreach ($paragraphArray as $line) {
$line = ltrim($line);
$page->drawText($line, 200, $startPos);
$startPos = $startPos - 12;
}
//saves the pdf
$pdf->save('new.pdf');
私が使用していたpdfが正しいタイプではなかったため、最初は問題がありました。Zendpdfを使用してpdfを作成することで、コードが正しいことを確認できます。これは常に機能するはずです(これを行う方法については、フレームワークを参照してください)。 zend.com/manual/1.12/en/zend.pdf.html)。
Photoshopを使用して、定規を「ポイント」に設定することにより、書き込みたい正確な場所を計算します。