Merge FDF data into a PDF file using PHP

前端 未结 4 514
悲哀的现实
悲哀的现实 2020-12-07 15:08

Is it possible to merge FDF data with a PDF file using PHP alone? Or is there no option but to use a 3rd party command line tool to achieve this?

If that is the cas

4条回答
  •  爱一瞬间的悲伤
    2020-12-07 15:33

    There is another way to day that not using passthru nor pdftk but just a script made in 2004 but still working well : forge_fdf

    it helps you to build a fdf that you can incoporate straithly in your pdf, it means that you

    Save this in a php file, let's say generatePdf.php

    require_once('forge_fdf.php');  
    
    // leave this blank if we're associating the FDF w/ the PDF via URL
    $pdf_form_url= "";
    
    
    // default data; these two arrays must ultimately list all of the fields
    // you desire to alter, even if you just want to set the 'hidden' flag;
    //
    //
    $fdf_data_names= array(); // none of these in this example
    $fdf_data_strings= array(); // none of these in this example
    
    $fdf_data_strings['email']=mb_strtolower($row_delivreur['firstname']).'.'.mb_strtolower($row_delivreur['lastname']).'@gmail.com';
    
    $fields_hidden= array();
    $fields_readonly= array();
    
    // set this to retry the previous state
    $retry_b= false;
    
    header( 'content-type: application/vnd.fdf' );
    
    echo forge_fdf( $pdf_form_url,
            $fdf_data_strings, 
            $fdf_data_names,
            $fields_hidden,
            $fields_readonly );
    

    Making a link to Pathtoyourpdf/nameofpdffile.pdf#FDF=generatePdf.php will open your PDF file in browser (alternatively there is a way to save it to disk i think i remember) and the field email will be filled with data from MYSQL : mb_strtolower($row_delivreur['firstname']).'.'.mb_strtolower($row_delivreur['lastname']).'@gmail.com'

    It works with checkboxes, radio button,... It opens well in firefox, it has to be tested with other browsers.

    More infos on PDF HACKS

提交回复
热议问题