我以为我可以为此找到一个插件,但似乎没有。
这是必需的过程:
用户在网站上填写表格(最好是 cforms!)表格中的数据填充服务器上 pdf 的空单元格
然后,一旦我走到那一步,我就会担心接下来的步骤!
生成 pdf 不是一种选择,因为它是法律文件。
谢谢。
好的,我已经想出了如何做到这一点,它似乎有点乱,可惜没有更简单的方法!
我使用的两个插件是 cforms (www.deliciousdays.com/cforms-plugin) 和一个加载 Zend 框架的插件 (h6e.net/wordpress/plugins/zend-framework) pdf写作能力。
激活两个插件后,在 cforms 插件目录中找到名为 my-functions.php 的文件并下载到您的计算机。该文件的大部分内容已被注释掉,因此您需要取消注释该功能
function my_cforms_action($cformsdata) {
}
按下提交按钮时,此函数中的任何内容都会运行(有关详细信息,请参阅 cforms API 文档)。您可以测试它是否有效,但会在 this 函数中回显某些内容。您还可以测试 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 类型不正确,您可以通过使用 Zend pdf 创建一个 pdf 来检查您的代码是否正确,因为这应该始终有效(在此处了解如何做到这一点:framework.pdf)。 zend.com/manual/1.12/en/zend.pdf.html)。
我使用 Photoshop 通过将标尺设置为“点”来计算出我想要书写的确切位置