开发者

Fillable PDF Form with PHP using PDFtk error

开发者 https://www.devze.com 2022-12-07 22:26 出处:网络
i am trying tofill out pdf files using a github project that i found on [https://github.com/mrdigitalau/PHP-PDFTK-Tutorial]

i am trying to fill out pdf files using a github project that i found on [https://github.com/mrdigitalau/PHP-PDFTK-Tutorial]

basically there is 2 page, one named: GenaratedPDF that hold code:

<?php
namespace Classes;

if(!defined('ACCESSCHECK')) {
      die('Direct access not permitted');
}


use mikehaertl\pdftk\Pdf;

class GeneratePDF {


           public function generate($data)
           {      

                  try {

                        $filename = 'pdf_' . rand(2000,1200000) . '.pdf';

                        $pdf = new Pdf('./test.pdf');
                        $pdf->fillForm($data)
         开发者_高级运维               ->flatten()
                        ->saveAs( './completed/' . $filename);
                        //->send( $filename . '.pdf');

                        return $filename;
   
                  }
                  catch(Exception $e)
                  {
                        return $e->getMessage();
                  }
      

           }
}

and another page name generate.php thad hold code:

<?php 

if ($_SERVER['REQUEST_METHOD'] != 'POST') {
     exit;
}

define('ACCESSCHECK', TRUE);

require_once 'vendor/autoload.php';

use Classes\GeneratePDF;


$data = [

      'name_field' => $_POST['fname'] .' ' . $_POST['lname'],
      'email_field' => $_POST['email'],
      'phone_field' => $_POST['phone'],
      'enquiry_field' => $_POST['enquiry']
];


$pdf = new GeneratePdf;
$response = $pdf->generate($data);


header('Location: thanks.php?fname=' . $_POST['fname'] . '&link=' . $response);

The problem is every time i try to fill out a pdf i got error:

Fatal error: Uncaught Error: Class 'Classes\GeneratePDF' not found in C:\xampp\htdocs\generate.php:23 Stack trace: #0 {main} thrown in C:\xampp\htdocs\generate.php on line 23

Any idea the problem here? thanks in advance

0

精彩评论

暂无评论...
验证码 换一张
取 消