tags:

views:

84

answers:

1

Hello,

I have to generate a PDF with TCPDF, my information come from my database, so I have to write PHP variables. I know how to do.

But I want to write CSS + xHTML (as an example I have seen of TCPDF site) using :

$html = <<<EOF

<style>
  <!-- My CSS -->
</style>

  <!-- My xHTML -->

EOF;

$pdf->writeHTML('$html', '');

I have errors when I try to open the PDF. I have read I must escape the '$' with '\'. After this, I have no error, but the content of my variables doesn't appear in my PDF.

EDIT :

@Sarfraz: I don't see how can I do this if I do this, it doesn't work ?

$html = <<<EOF

    <style>
      <!-- My CSS -->
    </style>

      <!-- My xHTML -->
      <span><?php echo $myVar; ?></span>

    EOF;

    $pdf->writeHTML('$html', '');
+1  A: 

Make sure that there is no space and indentation before EOF; otherwise you will get error.

Also if you have any variables in heredoc syntax escape put them in {} like {$somevar}

Sarfraz
I generate PDF without errors, but the variables aren't displayed.
Corum
@Corum: You can't interprest php variables in pdf. You need to echo variables before sending them to php library
Sarfraz