How to adjust Table Width in PDF?

Asked

Viewed 323 times

0

I am 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]

inserir a descrição da imagem aqui

The PDF report is coming out like this.

And I need to add a color to the header and have the TD fit the width.

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');*/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.