Andromeda
Andromeda

Reputation: 12897

FDF to PDF using PHP

I was trying to create a pdf from an FDF file. I have created the FDF file succesfully. But when i try to convert it into pdf i get some errors. Below is the part of my code. the test.pdf file open in a download box and when i try to open it gives error "couldn't open test.pdf because it is either not supported file type or has been damaged"

if($fp=fopen($fdf_file,'w')){
            fwrite($fp,$fdf_data,strlen($fdf_data));
            echo $fdf_file,' written successfully.';
            header('Content-type: application/pdf');
            header('Content-Disposition: attachment; filename="test.pdf"');
            passssthru("pdftk test.pdf fill_form test.fdf output - ");
            exit;

        }else{
            die('U

Upvotes: 1

Views: 2562

Answers (4)

user1431775
user1431775

Reputation:

if($fp=fopen($fdf_file,'w')){
        fwrite($fp,$fdf_data,strlen($fdf_data));
        //echo $fdf_file,' written successfully.';
        header('Content-type: application/pdf');
        header('Content-Disposition: attachment; filename="test.pdf"');
        passssthru("pdftk test.pdf fill_form test.fdf output - ");
        exit;
}

Upvotes: 1

Chalise
Chalise

Reputation: 3666

You probably need to be making sure to directly reference where pdftk is installed, as such:

passthru('/usr/local/bin/pdftk /forms/test.pdf fill_form /forms/test.fdf output - ');

Also, you can add >> output.pdf at the end of the command to create a new pdf file.

Upvotes: 0

Fuzzy76
Fuzzy76

Reputation: 921

To further debug this, check the size of the downloaded file, and take a peek at it in an editor. I am guessing you have output before or after this code.

Upvotes: 0

Peter Lindqvist
Peter Lindqvist

Reputation: 10210

Remove echo $fdf_file,' written successfully.';

Upvotes: 0

Related Questions