KoolReport's Forum

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

Issue in export PDF - DataTables Plugins #2259

Open abedalqader swedan opened this topic on on Aug 12, 2021 - 17 comments

abedalqader swedan commented on Aug 12, 2021

Dears, I hope all is well,

We faced issue in exporting the PDF file from DataTables plugins.

The details of this issue as following:

When is our data length is short the number of appear columns in PDF file more than when the length of data is long. (But in the all cases the data doesn't fitting well in PDF file!). We have 8 columns in our data. attachments explain the issue.

Can you help?

Sebastian Morales commented on Aug 12, 2021

Pls try this buttons options:

    "plugins" => ["Buttons"],
    "options" => array(
                    "dom" => 'Blfrtip',
                    "buttons" => [
                        [
                            "extend" => 'pdfHtml5', 
                            "orientation" => "landscape",
                            "pageSize" => "A0",
                        ],
                        ...
abedalqader swedan commented on Aug 12, 2021

I did it but have same issue.

Sebastian Morales commented on Aug 12, 2021

Is the exported page in landscape or portrait and what's its size?

abedalqader swedan commented on Aug 12, 2021

portrait and A4 size, and data not fit in it.

Sebastian Morales commented on Aug 12, 2021

Remove your old "pdf" button and use the "pdfHtml5" button setting I posted exclusively. In anyway, pls post your DataTabels' create code and its pdf button result.

abedalqader swedan commented on Aug 12, 2021

DataTables::create(array(

            "plugins" => ["Buttons"],
            "options" => array(
                "dom" => 'Blfrtip',
                "buttons" => 
                    [
                        "extend" => 'pdfHtml5', 
                        "orientation" => "landscape",
                        "pageSize" => "A0",
                    ],
                "searching"=>true,
                "paging" => true
            ),
            "dataStore"=>$this->dataStore("orders"),
            
    
    "cssClass"=>array(
        "table"=>"table table-striped table-bordered"
    ),
            "columns"=>array(
                "Client_ID"=>array(
                    "label"=>"Client ID",
                ),
                "Hostname"=>array(
                    "label"=>"Hostname",
                ),
                    "MAC_Address"=>array(
                        "label"=>"MAC Address",
                    ),
                    "OS"=>array(
                        "label"=>"OS",
                    ),
                    "Create_Date"=>array(
                        "label"=>"Create Date",
                    ),
                    "Last_Update"=>array(
                        "label"=>"Last Update",
                    ),
                    "KeepAliveTime"=>array(
                        "label"=>"Keep Alive Time",
                    ),
                    
                "Type"=>array(
                    "label"=>"Type"
                )
            ),
            
            "class"=>array(
                "table"=>"table table-striped"
            )
        ));
Sebastian Morales commented on Aug 13, 2021

Pls fully refresh your page (Ctrl+F5) and try the Buttons pdfHtml5 (the button's text should be "PDF") again. Send us the pdf file if it isn't in A0 size and landscape mode. Rgds,

abedalqader swedan commented on Aug 13, 2021

I did it, but still not working!

This is the PDF file.

abedalqader swedan commented on Aug 13, 2021

https://drive.google.com/file/d/1eNMxudjfF3M_DnVp-8BgzrF0bO9Zu7Gb/view?usp=sharing

abedalqader swedan commented on Aug 15, 2021

is there any update?

Sebastian Morales commented on Aug 16, 2021

After carefully checking your code, I found that your Buttons setting is wrong. It should not be:

                "buttons" => // wrong
                    [
                        "extend" => 'pdfHtml5', 
                        "orientation" => "landscape",
                        "pageSize" => "A0",
                    ],

"buttons" should be an array of either default strings ("csv", "print", "pdf", etc) or custom button arrays.(i.e array of arrays). This setting of yours doesn't affect "buttons" in any way.

Look at my initial answer:

https://www.koolreport.com/forum/topics/2259#p12163

You missed the important start of an array mark [ after "buttons".

The setting should be this exact:

                "buttons" => [
                    [
                        "extend" => 'pdfHtml5', 
                        "orientation" => "landscape",
                        "pageSize" => "A0",
                    ],
                ]
abedalqader swedan commented on Aug 16, 2021

OK, It's work. Thank you.

How can I change the format of header of the PDF file? Do you have any idea?

Sebastian Morales commented on Aug 16, 2021

Pls use css rules for your table header. Rgds,

abedalqader swedan commented on Aug 16, 2021

I mean the header of the file not the header of the table. I want to add logo and make some design.

Any advice?

Sebastian Morales commented on Aug 17, 2021

Did you mean a header/title only in the first page or a page header which appears in every page?

abedalqader swedan commented on Aug 17, 2021

Just the first page.

Sebastian Morales commented on Aug 18, 2021

Oh, in your pdf view just design that header/title part with html tags including img, css rule like a normal html page. The exported pdf would render it like in a browser view.

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

DataGrid