How to adjust Width of a Table in PDF?

0

I'm exporting a report to PDF but the colors and widths are not working.

$campo = $service->relatorioOrcamentario($data);

$tabela = '<table border="1">';//abre table
$tabela .='<thead>';//abre cabeçalho
$tabela .= '<tr>';//abre uma linha
$tabela .= '<td style="background-color: #00cce9; width: width: 100%;">Setor</td>'; // colunas do cabeçalho
$tabela .= '<td style="background-color: #00cce9; ">C/C</td>';
$tabela .= '<td style="background-color: #00cce9; ">Direção</td>';
$tabela .= '<td style="background-color: #00cce9; ">Período</td>';
$tabela .= '<td style="background-color: #00cce9; ">Saldo Inicial</td>';
$tabela .= '<td style="background-color: #00cce9; ">Entradas</td>';
$tabela .= '<td style="background-color: #00cce9; ">Trans Crédito</td>';
$tabela .= '<td style="background-color: #00cce9; ">Trans Débito</td>';
$tabela .= '<td style="background-color: #00cce9; ">Saídas</td>';
$tabela .= '<td style="background-color: #00cce9; ">Saldo Final</td>';
$tabela .= '</tr>';//fecha linha
$tabela .='</thead>'; //fecha cabeçalho
$tabela .='<tbody>';//abre corpo da tabela
foreach ($campo as $campos){
$tabela .= '<tr>'; // abre uma linha
$tabela .= '<td>'.utf8_decode($campos['DEPARTAMENTO_DESCRICAO']).'</td>';
$tabela .= '<td>'.$campos\['REDUZIDO'].'</td>';
$tabela .= '<td>'.utf8_decode($campos['SUPERIOR']).'</td>';
$tabela .= '<td>'.$campos['DATA_INICIO'].' - '. $campos['DATA_INICIO'].'</td>';
$tabela .= '<td>'.'vazio'.'</td>';
$tabela .= '<td>'.$campos['ENTRADAS'].'</td>';
$tabela .= '<td>'.$campos['TRANSFERENCIA_CREDITO'].'</td>';
$tabela .= '<td>'.$campos['TRANSFERENCIA_DEBITO'].'</td>';
$tabela .= '<td>'.$campos['SAIDAS'].'</td>';
$tabela .= '<td>'.'vazio'.'</td>';
$tabela .= '</tr>'; // fecha linha
}
$tabela .='</tbody>'; //fecha corpo
$tabela .= '</table>';//fecha tabela

//echo $tabela;

$pdf = new PDF();
$pdf->AddPage('L');
$pdf->SetFont('Arial','B',10);
$pdf->WriteHTML($tabela);
$pdf->Output ( 'Resumo_Orcamento' . date ( 'YmdHis' ) . '.pdf', 'D' );][1]][1]

The PDF report is coming out this way.

You need to add a color to the header and let the TDs fit the width.

    
asked by anonymous 21.11.2018 / 19:44

1 answer

0

I ended up changing the library, because the previous one did not accept CSS.

I switched to dompdf

$dompdf = new DOMPDF();
$dompdf->loadHtml($tabela);
$dompdf->setPaper('a4', "landscape");
$dompdf->render();
$dompdf->stream('Orcamento_Detalhado'.date( 'YmdHis' ).'pdf');*/
    
30.11.2018 / 11:34