KoolReport's Forum

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

Can we skip header footer from page 1 #1628

Open Mukesh opened this topic on on Sep 24, 2020 - 7 comments

Mukesh commented on Sep 24, 2020

Hello,

I am using koolreport with cloud export library every thinks working fine but I want to first page of PDF without a header footer any idea how can we do this.

Thanks in advance

David Winterburn commented on Sep 24, 2020

Hi,

Unfortunately at the moment headless Chrome hasn't support such customization of of header/footer for a certain page. There's some trick to set margin=0 for some pages to hide their header/footer but it's not consistent. While we wait for headless Chrome to support customized header/footer, I think the best solution for your case is to print different pdf files using "pageRange" option like this:

    //Export.php
    $report->cloudExport("MyReportPdf")
    ->chromeHeadlessio($secretToken)
    ->settings($settings)
    ->pdf([
        ...//set options here to disable header/footer
        "pageRanges" => '1', //print only the first page
    ])
    ->saveAs($pathToExportFilePdf1);
    ;

    $report->cloudExport("MyReportPdf")
    ->chromeHeadlessio($secretToken)
    ->settings($settings)
    ->pdf([
        ...//set options here to enable header/footer
        "pageRanges" => '2-', //print page 2 -> end
    ])
    ->saveAs($pathToExportFilePdf2);
    ;

    //Merge $pathToExportFilePdf1 and $pathToExportFilePdf2 here and return it to client

Let us know if you have any difficulty with each step. Thanks!

Mukesh commented on Sep 24, 2020

it's not working giving error Filename cannot be empty .

So I am doing like this, code is below:

$chromePDFOptions = array("scale"=>1, "format"=>"A4", "landscape"=>true);

$services = new \chromeheadlessio\Service("Token");

$report = new MyReport;

$services->export([
	"html"=>$html
])->pdf([
    //"format"=>"A4",
    "displayHeaderFooter"=>false,
    "printBackground"=>false,
	"orientation"=>"portrait",
	"width"=>"900px",
	"height"=>"1070px",
	"pageRanges" => "2-",
])->save('..pdf/certificateReport.pdf');

this is generating pdf but only a single PDF.

If I am redeclaring this its giving error you can't redeclare.

I am using cloud export if I purchase an export library then can I achieve this without creating 2 different pdf, I want this functionality in a single PDF

David Winterburn commented on Sep 29, 2020

Hi,

I asked the development team of the Export package and they confirmed that it's also not possible at the moment to hide header/footer for first page only.

David Winterburn commented on Sep 30, 2020

Good news! I have confirmation from the development team that the next version of Export package will allow user's different customization of header and footer for each page. If you have purchased either the Export package or KoolReport Pro please send us an email to support@koolphp.net. We will send you the development version of Export which could solve this issue. Thanks!

Mukesh commented on Oct 5, 2020

Wow, it's great news.

Thomas commented on Mar 18, 2022

For those who are interested, I found a simple workaround.

Add this to your css:

@page:first {margin-top: 0;margin-bottom: 0;} body {margin-top: 1,25cm;margin-bottom: 1,25cm;}

And add this to the beginning of your view:

<div id="hide-frontpage-header" style="height: 50px ; width: 100%; background-color: white;"></div>
<div id="hide-frontpage-footer" style="position:absolute; bottom: 0; height: 50px; width: 100%; background-color: white;"></div> 

The header and footer are covered by the white divs.

Sebastian Morales commented on Mar 21, 2022

It's an excellent solution for CloudExport with Chrome headless engine. Thank you, Thomas!

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
help needed

Export