I want to display in the header of the document, an image from the database. The image depends on the company being selected. I tried every solution I found here, nothing works. Two of them work outside the header, but inside, they either break the page, or the image is not visible. What I am doing wrong?
$stmt_antet = $conn -> prepare ("SELECT antet FROM societati WHERE id_societate = ?");
$stmt_antet->bind_param("s",$id_societate_raport);
if (!$stmt_antet -> execute()) {
echo mysqli_errno($conn);
}
else {
$result_antet = $stmt_antet -> get_result();
$row_antet = $result_antet -> fetch_assoc();
$antet = $row_antet['antet'];
}
require_once('tcpdf/examples/tcpdf_include.php');
class MYPDF extends TCPDF {
public function Header() {
// this gives a broken page
$imgdata_m = base64_decode($antet);
$this->Image('@'.$imgdata_m, 25, 35, 160, 24, 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
// this gives a broken page and doesn't work outside the header either
$antet_encoded = "data:image/png;base64,".$antet;
$this->tcpdf->Image("@".$antet_encoded, 25, 35, 160, 24, 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
// TCPDF ERROR: [Image] Unable to get the size of the image
$img_base64_encoded = 'data:image/jpg;base64,'.$antet;
$imageContent = file_get_contents($img_base64_encoded);
$path = tempnam(sys_get_temp_dir(), 'prefix');
file_put_contents ($path, $imageContent);
$img = '<img src="' . $path . '">';
$this->writeHTML($img, 25, 35, 160, 24, 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
}
// outside the header, it works just fine
$imgdata_m = base64_decode($antet);
$pdf->Image('@'.$imgdata_m, 25, 35, 160, 24, 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
// outside the header, it works just fine
$img_base64_encoded = 'data:image/jpg;base64,'.$antet;
$imageContent = file_get_contents($img_base64_encoded);
$path = tempnam(sys_get_temp_dir(), 'prefix');
file_put_contents ($path, $imageContent);
$img = '<img src="' . $path . '">';
$pdf->writeHTML($img, 25, 35, 160, 24, 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);