解析pdf html表单

时间:2015-05-13 08:11:44

标签: php pdf yii

我有一个可填写的pdf文件,我想用db中的值填充此表单。现在我可以用一种形式填写表格(我的意思是有限的字段)。这是我的yii控制器动作

public function actionFormanalysis() 
{
    $pdf_file = 'http://koivi.com/fill-pdf-form-fields/test.pdf';

    // allow for up to 25 different files to be created, based on the minute

    $min = date('i') % 25;
    $fdf_file = Yii::getPathOfAlias('webroot') . '/uploads/posted-' . $min . '.fdf';
    $pdf_to_fill = Yii::getPathOfAlias('webroot') . '/uploads/forms/I-129rrrr.pdf';
    if (isset($_POST['__NAME__'])) {
        $_POST['__CSZ__'] = $_POST['__CITY__'] . ', ' . $_POST['__STATE__'] . ' ' . $_POST['__ZIP__'];

        // get the FDF file contents

        $fdf = new Pdfparser;
        $fdf = $fdf->createFDF($pdf_file, $_POST);

        // Create a file for later use

        if ($fp = fopen($fdf_file, 'w')) {
            fwrite($fp, $fdf);
            $CREATED = TRUE;
        }
        else {
            echo 'Unable to create file: ' . $fdf_file . '<br /><br />';
            $CREATED = FALSE;
        }

        fclose($fp);
        header('Content-type: application/pdf');
        header('Content-Disposition: attachment; filename="Download.pdf"');
        passthru("pdftk " . $pdf_to_fill . " fill_form " . $fdf_file . " output - ");
        exit;
    }

    $this->render('formanalysis');
}

我想在pdf依赖

上做这个部分
$_POST['__CSZ__'] = $_POST['__CITY__'] . ', ' . 
                    $_POST['__STATE__'] . ' ' . 
                    $_POST['__ZIP__'];

如果名称不同,我可以填写pdf字段。

怎么可能。

1 个答案:

答案 0 :(得分:1)

在渲染到模板之前使用exec()函数。

 exec("pdftk ".$pdffile." dump_data_fields 2>&1", $output,$retval);
 $this->render('formanalysis',array('pdffields',$output));