I'm new to programming and I've been trying to make a pdf with mpdf, but it's been a bit more complicated than I thought. I have already built some variables but joining them together is complicated, in a few words they wanted to put this table that contains mpdf and php in a pdf
this is the table:
<table id="Liderazgo">
<caption class ="titulos">Liderazgo</caption>
<tr id="lid">
<?php $obj = json_decode($myJSON,true);
foreach($obj as $data){
if($data['llave'] == 'Visionario'){ ?>
<td class ="Visionario" width="51" height="27">
<?php for($i=0;$i<$data['stars'];$i++){
echo '★'; } ?></td> <?php
}
}
?>
<?php $obj = json_decode($myJSON,true);
foreach($obj as $data){
if($data['llave'] == 'Protector'){ ?>
<td class ="Protector" width="51" height="27">
<?php for($i=0;$i<$data['stars'];$i++){
echo '★'; } ?></td> <?php
}
}
?>
<?php $obj = json_decode($myJSON,true);
foreach($obj as $data){
if($data['llave'] == 'Participativo'){ ?>
<td class ="Participativo" width="51" height="27">
<?php for($i=0;$i<$data['stars'];$i++){
echo '★'; } ?></td> <?php
}
}
?>
</tr>
<Tr class = "texto">
<Td width="48" height="15">Visionario</Td>
<Td width="48" height="15">Protector</Td>
<Td width="48" height="15">Participativo</Td>
</Tr>
</table>
and this is the mpdf i created:
<?php
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf([
'mode' => 'utf-8',
'format' => 'A4',
'default_font' => 'mycustomfont',
'margin_left' => 15,
'margin_right' => 10,
'margin_top' => 16,
'margin_bottom' => 10,
'margin_header' => 10,
'margin_footer' => 10
]);
$mpdf->allow_charset_conversion=true;
$mpdf->charset_in='UTF-8';
$Autoritario ="";
ob_start();
$obj = json_decode($myJSON,true);
foreach($obj as $data)
{if($data['llave'] == 'Autoritario'){
for($i=0;$i<$data['stars'];$i++)
{ echo "★";
}
}
}
$Autoritario = ob_get_contents();//get the content
$Protector ="";
ob_start();
$obj = json_decode($myJSON,true);
foreach($obj as $data)
{if($data['llave'] == 'Protector '){
for($i=0;$i<$data['stars'];$i++)
{ echo "★";
}
}
}
$Protector = ob_get_contents();//get the content
$Participativo ="";
ob_start();
$obj = json_decode($myJSON,true);
foreach($obj as $data)
{if($data['llave'] == 'Participativo'){
for($i=0;$i<$data['stars'];$i++)
{ echo "★";
}
}
}
$Participativo = ob_get_contents();//get the content
$Negociador ="";
ob_start();
$obj = json_decode($myJSON,true);
foreach($obj as $data)
{if($data['llave'] == 'Negociador'){
for($i=0;$i<$data['stars'];$i++)
{ echo "★";
}
}
}
$Negociador = ob_get_contents();//get the content
ob_end_clean();//erase the output buffer
$mpdf->WriteHTML($Autoritario);
$mpdf->WriteHTML($Protector);
$mpdf->WriteHTML($Participativo);
$mpdf->WriteHTML($Negociador);
$mpdf->Output();
?>
Hope you can help me please