2012-12-18 56 views
1

我以爲我能找到一個插件,但似乎並沒有一個。我需要從wordpress站點上的表單填充pdf

這是所需要的過程:

用戶在網站上的形式填充(!優選cforms) 從形式的數據填充的PDF的空單元上的服務器

然後,好吧,一旦我得到那麼多,我會擔心下一步!

生成PDF不是一個選項,因爲它是一個法律文件。

謝謝。

+0

我想,這將是讀有用http://stackoverflow.com/questions/7364/摸出我想寫的確切位置pdf-editing-in-php – Igor

+0

「生成PDF不是一個選項,因爲它是一個法律文件。」請解釋一下,「填充」和「生成」之間的區別是什麼? 'cforms' API當然可以用來提供用於構建您所使用的PDF的數據,查看文檔。 – soulseekah

+0

感謝您的意見!當我說「填充」時,我的意思是採用現有的pdf並使用表單數據填充空白;當我說「生成」時,我的意思是使用html/css/php創建一個模板,然後將其轉換爲pdf(可以在wordpress中使用該模板):http://crosstec.de/en/markets/breezingforms-form- apps/details/30/16/community-market-type-form-apps-pdf-download-on-thank-you-page.html) – daveyb

回答

1

好吧,我已經制定了如何做到這一點,它似乎有點凌亂,可惜沒有一個更簡單的方法!

我使用的兩個插件是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格式不是正確的ype,你可以通過使用Zend pdf創建pdf來檢查你的代碼是否正確,因爲它應該始終有效(請參閱framework.zend.com/manual/1.12/en/zend.pdf.html)。

我使用Photoshop在借尺子設置爲「點」