我以为我能找到一个插件,但似乎并没有一个。我需要从wordpress站点上的表单填充pdf
这是所需要的过程:
用户在网站上的形式填充(!优选cforms) 从形式的数据填充的PDF的空单元上的服务器
然后,好吧,一旦我得到那么多,我会担心下一步!
生成PDF不是一个选项,因为它是一个法律文件。
谢谢。
我以为我能找到一个插件,但似乎并没有一个。我需要从wordpress站点上的表单填充pdf
这是所需要的过程:
用户在网站上的形式填充(!优选cforms) 从形式的数据填充的PDF的空单元上的服务器
然后,好吧,一旦我得到那么多,我会担心下一步!
生成PDF不是一个选项,因为它是一个法律文件。
谢谢。
好吧,我已经制定了如何做到这一点,它似乎有点凌乱,可惜没有一个更简单的方法!
我使用的两个插件是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在借尺子设置为“点”
我想,这将是读有用http://stackoverflow.com/questions/7364/摸出我想写的确切位置pdf-editing-in-php – Igor
“生成PDF不是一个选项,因为它是一个法律文件。”请解释一下,“填充”和“生成”之间的区别是什么? 'cforms' API当然可以用来提供用于构建您所使用的PDF的数据,查看文档。 – soulseekah
感谢您的意见!当我说“填充”时,我的意思是采用现有的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