Change soon in TCPDF via form

1

I created a PDF generator with TCPDF , it works ok, I'm just having a little problem. I want the logo-marca to enter, whatever I choose in the form.

Follow the codes.

Formulary code that sends the data ( index.php )

<table align="right" width="100%">
    <tr> 
        <td size="50px">Logo
            <div style="padding-top:5px;">
                <input name="logo" type="radio" 
                       value="http://www.example.com/logo1.jpg" /> LOGO 1
                <input name="logo" type="radio" 
                       value="http://www.example.com/logo2.jpg" /> LOGO 2
                <input name="logo" type="radio" 
                       value="http://www.example.com/logo3.jpg" /> LOGO 3
            </div>
        </td>
    </tr>
</table>

Code php of the file that generates pdf ( invoice2.php )

<?
require_once('tcpdf_include.php');
class MYPDF extends TCPDF {
    public function Header() {
        $image_file = 'http://www.example.com/logo.jpg';
      //$pdf->Image('images/image_demo.jpg', $x, $y, $w, $h, 'JPG', '',
      //     '', false, 300, '', false, false, 0, $fitbox, false, false);
        $this->Image($image_file,'',8,80,'', 'JPG', '', 'T', false, 300,
                     'L', false, false, 0, false, false, false);
    }
    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica', 'I', 8);
    }
}

I want you to, for example: The person who chooses LOGO 1 , when generating PDF , the image that was selected appears at the top of PDF generated. At the moment, the image that is appearing is the one that is in the code of invoice2.php .

public function Header() {
    $image_file = 'http://www.example.com/logo.jpg';
}

Could anyone help me with this?

    
asked by anonymous 31.08.2015 / 01:37

1 answer

0

You can do this using the methods GET or POST when submitting the form. (In the example below I used POST )

The first thing I did to illustrate was to change the code HTML by adding the form, see:

<form method="post" action="seu_script_que_gera_o_pdf.php">
    <table align="right" width="100%">
        <tr>
            <td size="50px">Logo
                <div style="padding-top:5px;">
                    <input name="logo" type="radio" 
                           value="http://www.example.com/logo1.jpg" /> LOGO 1
                    <input name="logo" type="radio" 
                           value="http://www.example.com/logo2.jpg" /> LOGO 2
                    <input name="logo" type="radio" 
                           value="http://www.example.com/logo3.jpg" /> LOGO 3
                </div>
            </td>
        </tr>
    </table>
</form>

Now we can change the script that generates PDF to behave accordingly see:

<?
require_once('tcpdf_include.php');

class MYPDF extends TCPDF {
    public function Header($logo) {
        $image_file = $logo; //'http://www.example.com/logo.jpg';
      //$pdf->Image('images/image_demo.jpg', $x, $y, $w, $h, 'JPG', '', 
                    '', false, 300, '', false, false, 0, $fitbox, false, false);
        $this->Image($image_file,'',8,80,'', 'JPG', '', 'T', false, 300, 
                     'L', false, false, 0, false, false, false);
    }
    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica', 'I', 8);
    }
}

if ($_SERVER['REQUEST_METHOD'] == 'POST'){
    $image = $_POST['logo'];

    $myPdf = new MYPDF();
    $myPdf->Header($logo);
}

The Header method has been changed so that you can enter the desired image when the form is submitted.

    
31.08.2015 / 13:30