Skip to content

Instantly share code, notes, and snippets.

@carlosleonam
Last active April 20, 2024 01:31
Show Gist options
  • Save carlosleonam/edba2f09aad1746d9a29ef4efec8f4bc to your computer and use it in GitHub Desktop.
Save carlosleonam/edba2f09aad1746d9a29ef4efec8f4bc to your computer and use it in GitHub Desktop.
Paging with DomPDF and Adianti Framework ( by Eduardo )

Paging with DomPDF and Adianti Framework ( by Eduardo )

Boa tarde Srs. Utilizo o Dompdf para gerar meus relatórios feitos em html. Para chamada do Dompdf utilizo o Seguinte padrão

// converts the HTML template into PDF
                $dompdf = new \Dompdf\Dompdf();
                $options = new \Dompdf\Options();
                $options->set('isRemoteEnabled', TRUE);
                $options->set('isPhpEnabled', TRUE);
                $dompdf = new \Dompdf\Dompdf($options);
                $dompdf->loadHtml($pdf);
                $dompdf->setPaper('A4', 'landscape');
                $dompdf->render();

                file_put_contents($output, $dompdf->output());

Observe a propriedade isPhpEnabled deve estar definida como true; No corpo do HTML insiro o seguinte o seguinte script que gera a numeracao de pagina:

<script type="text/php">
if (isset($pdf)) {
$text = "Emitido em " . "' . date('d/m/Y - H:i') . '". " - Página {PAGE_NUM} / {PAGE_COUNT}";
$text2 = "Sistema de Gestão WEB";
//$text = "Página {PAGE_NUM}";
$size = 8;
$font = $fontMetrics->getFont("Helvetica");
$width = $fontMetrics->get_text_width($text, $font, $size) / 2;
//$x = ($pdf->get_width() - $width) / 2;
$pdf->page_line(40,555,805,555,array(0,0,0),1);
$x = 40;
$y = $pdf->get_height() - 35;
$pdf->page_text($x, $y, $text2, $font, $size);
$x = $pdf->get_width() - 200;
$y = $pdf->get_height() - 35;
$pdf->page_text($x, $y, $text, $font, $size);
}
</script>

na verdade quando fiz da primeira vez mesmo usando isRemoteEnable a imagem nao aparecia.. dae tive concatenar o resultado do seguinte metodo com o caminho da imagem para que aparecesse adequadamente

static function getUrlPath( $add_slash = false )
    {
        $base_url  = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");    // Select whether it is HTTPS or HTTP
        $base_url .= "://".$_SERVER['HTTP_HOST'];                                                     // Capture the name of the HOST
        $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);       // Capture the FOLDER name
        if (substr($base_url, -1) !== '/' && $add_slash ) {
            $base_url .= '/';
        }
        return $base_url;
    }

com tudo isso o relatório funciona filé!

@carlosleonam
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment