@gaurissl22 posted a new topic, subject "Pdftk edit and fill forms". It read:

   I have been working with pdftk to edit and fill pdf forms.
    
    I have a problem with filling the data from a PHP array into the form.  
    Also I tried it using XFDF/FDF file, but still got an error.
    
    In this when I send data using xfdf I get the following error -  
    Unhandled Java Exception in create_output(): java.lang.ClassCastException: pdftk.com.lowagie.text.pdf.PdfNull cannot be cast to pdftk.com.lowagie.text.pdf.PdfDictionary at 0x0059a84e (Unknown Source) at 0x0059ad42 (Unknown Source) at 0x005e9bd4 (Unknown Source) at 0x005ba4a4 (Unknown Source) at 0x005b2044 (Unknown Source) at 0x0059231e (Unknown Source) at 0x004723f1 (Unknown Source) at 0x00472045 (Unknown Source) at 0x004df3e2 (Unknown Source) at 0x004df38a (Unknown Source) at 0x00471e74 (Unknown Source)
    
    Please guide me through this.

To which @Mittineague replied

    Hi gaurissl22 welcome to the forum
    
    I'm a bit confused, you're using PHP and Java together?
    
    I use Java for desktop apps using the CLI, and though AFAIK Java and PHP can work together, I've never bothered to try and use PHP for PHP
    
    Are you sure you've set up everything correctly?

After which, @gaurissl22 added

    Hello,
    
    Thanks for your response.  
    No, Im not using java.
    
    Following is my code:
    [code] 
        <?php 
        require 'vendor/autoload.php';
        use mikehaertl\pdftk\Pdf;
        use mikehaertl\pdftk\FdfFile;
        
        define("FORM_", "D:/wamp/www/pdftk/forms/");
        
        $pdf = new Pdf(FORM_.'form.pdf', [
            'command' => 'C:\Program Files (x86)\PDFtk Server\bin\pdftk.exe',
            'useExec' => true,  // May help on Windows systems if execution fails
        ]);
        
        $fields = array(
        	'Street_Address'=>'test address',
        	'Tax_ID' => 'test id'
        	);
        	
        $fdf = new FdfFile($fields);
        $fdf->saveAs(FORM_.'data_fdf.fdf');
        
        $pdf->fillForm(FORM_.'data_fdf.fdf')
        	 ->needAppearances()
             ->saveAs(FORM_.'filled.pdf');
        		 
        if (!$pdf->saveAs('filled.pdf')) {
            $error = $pdf->getError();
        	echo $error;
        	die;
        }
        
        $pdf = new Pdf(FORM_.'filled.pdf', [
            'command' => 'C:\Program Files (x86)\PDFtk Server\bin\pdftk.exe',
            'useExec' => true,  // May help on Windows systems if execution fails
        ]);
        $pdf->send();
        
    [/code]
    
    I have extracted the fields using " $pdf->getDataFields(); " and created an array named fields.  
    In this the data_fdf.fdf file get created.  
    This error is coming while saving the Filled.pdf. (echo $error)  
    Did I miss out something?  
    Or am I doing something wrong?

Then @system said

    This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.


{'source': 'discourse', 'url': 'https://www.sitepoint.com/community/t/pdftk-edit-and-fill-forms/264401', 'title': 'Pdftk edit and fill forms', 'views': 1863, 'has_accepted_answer': False, 'word_count': 369, 'like_count': 0, 'reply_count': 1, 'participant_count': 2, 'posts': 4, 'tags': '', 'author': '@gaurissl22', 'participants': '@gaurissl22, @Mittineague, @system', 'image_url': [None], 'created_at': '2017-05-24T14:11:37.224Z', 'last_posted_at': '2017-08-24T13:03:48.268Z'}