KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Export wide datatable to PDF with many rows #1821

Open Ron opened this topic on on Jan 6, 2021 - 1 comments

Ron commented on Jan 6, 2021

Hi,

I have a report with more then 50 columns. I am trying to export it to PDF as A4 landscape. but I have two issues: 1. When rows overflow the A4 page it is cut in the next page. no option to use page-break because all the table is printed in one time. 2. Trying to fit the width of the table to the page width but without success.

    //MyReport.view.php
    use \koolreport\datagrid\DataTables;
?>
<html>
<head>
</head>
    <body DIR="RTL" style="margin:0.2in 0.2in 0.2in 0.2in">
        <div class="row d-print-none">
            <div class="col text-center">
                <button id="print" class="btn btn-success" href="<?php echo site_url('reports'); ?>" onclick="javascript: window.print()">
                    <?php echo lang('tts.print'); ?>
                </button>
                <a class="btn btn-secondary mr-2" href="<?php echo site_url('reports'); ?>">
                    <?php echo lang('tts.back'); ?>
                </a>
            </div>
        </div>
        <?php
        echo '<div class="header print-only"><img src="'.site_url('../assets/img/'.(isset($_SESSION['institute_number']) ? $_SESSION['institute_number'].'.png' : "logo.svg")).'" height="38" /></div>';
        ?>
        <h1 class="text-center"><?php echo lang('tts.report_teachers_attendance'); ?></h1>
        <h3 class="text-center"><u><?php echo lang('tts.for_month').' '.lang('tts.'.date('F', mktime(0, 0, 0, $this->month, 10))).' '.$this->year;  ?></u></h3>
        <?php
        DataTables::create(array(
            "name" => "myTable",
            "dataSource"=>$this->dataStore("st"),
            "fastRender" => true,
            "options"=>array(
                "order"=>[],
                'columnDefs' => array(
                    array(
        				'visible' => false,
        				//'targets' => [$this->monthDays+6], //hide the first column
        			)
        		),
            ),
            'complexHeaders' => true,
            'headerSeparator' => ' - ',
            // 'cssClass'=>array(
            //     'table'=>'table table-bordered',
            //     'tr'=>'cssItem',
            //     'td'=>function($row,$colName)
            //     {
            //         return in_array($colName, array('teacher_id','id_number', 'reason')) ? 'text-right' : 'text-center';
            //     },
            //     'th'=>function($colName)
            //     {
            //         return in_array($colName, array('teacher_id','id_number','reason')) ? 'table-dark text-right' : 'table-dark text-center';
            //     },
            // ),
        ));
        echo '<div class="footer print-only">Footer</div>';
        ?>
    </body>
</html>


Sebastian Morales commented on Jan 7, 2021

If you don't want page break inside your row pls use this css rule in your pdf view

<style>
    table tr, table tr td, table tr th {
        page-break-inside: avoid !important;
    }
</style>

Regarding the pdf width in comparison with your 50-column table, if A4 format with landscape doesn't fit you could set a custom width yourself.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None