0

In php, I want to create pdf with tcpdf. based on tutorials, I have to put html tags in a variable as string and then pass that variable to tcpdf. like this:

$html = "<div>Hello World</div>";
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);

But in a real world application, I want to do some foreach inside my html and create html tags from database data.

<div><?php foreach ($myData as $key => $value) {echo $value}; ?></div>;

But in this way, I get an error:

Some data has already been output to browser, can't send PDF file

What I have to do? in fact I want tp put a large html with php loops inside that completes that html inside a variable, and the pass that variable to tcpdf whithout getting that error.

Fcoder
  • 9,066
  • 17
  • 63
  • 100

1 Answers1

0

You are outputting data to the request body before you send the PDF.

This could be a space or newline before your <?php tag or perhaps an echo statement from previous debugging attempts.

Quick example, this is correct

<?php // code

and these aren't

 <?php // code

<?php // code

for a more detailed explanation see this answer https://stackoverflow.com/a/9475817/9208510

Joeri
  • 626
  • 5
  • 18