【问题标题】:parse pdf html form解析pdf html表单
【发布时间】:2015-05-13 08:11:44
【问题描述】:

我有一个可填写的 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 字段。

这怎么可能。

【问题讨论】:

    标签: php pdf yii


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-28
      相关资源
      最近更新 更多