KoolReport's Forum

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

Regarding first page of PDF Header Footer skipping #3057

Open Lawrbit opened this topic on on May 24, 2023 - 3 comments

Lawrbit commented on May 24, 2023

Hi Team,

We are trying to create a multi-page report into PDF with the help of an export package and trying to design the first page of the PDF as a cover page by skipping the header and footer from the first page and it's working fine.

But header and footer spacing remains the same on top and bottom how to remove that?

Please check the attached screenshot.

Sebastian Morales commented on May 25, 2023

If you use Export package, pls try setting custom headers and footers with call back:

$report->export()->pdf(array(
    ...
    //headerCallback and footerCallback could be js function that return header and footer content based on current page (pageNum), total number of page (numPages) and header/footer content set by pdf option or page-header, page-footer tags
    "headerCallback" => "function(headerContent, pageNum, numPages){
        if (pageNum == 1) return ''; //don't return any header for page number 1
        return 'This is a header' || headerContent;
    }",
    "footerCallback" => "function(footerContent, pageNum, numPages){
        if (pageNum == numPages) return ''; //don't return any footer for the last page
        return 'This is a footer' || footerContent;
    }",
))->toBrowser("myfile.pdf"); 

https://www.koolreport.com/docs/export/get_started/#export-to-pdf-header-and-footer-callbacks-(version-%3E=-5.0.0)

Lawrbit commented on May 25, 2023

Hi,

We are doing the same as the code shared by you, When I am skipping the header and footer from the first page, the header, and footer white space (header footer height) remain the same.

Can help us set the header footer height to 0px for the first page and 100px for the other pages?

Sebastian Morales commented on May 26, 2023

I'm afraid that with Export package's Phantomjs pdf rendering engine, dynamic header/footer content across pages is possible but header/footer height is always fixed. The best solution for your case is to export the first page without header/footer and later pages with header/footer independently and then merge them:

//export.php
$report->run();
$report->export("ReportFirstPageWithoutHeaderFooter")
...
->saveAs("cover.pdf");
$report->export("ReportContentWithHeaderFooter")
...
->saveAs("content.pdf");

//merge the pdf files here
...

There're multiple PHP packages to merge pdf files. For example:

https://packagist.org/packages/jurosh/pdf-merge

$pdf = new \Jurosh\PDFMerge\PDFMerger;

// add as many pdfs as you want
$pdf->addPDF('path/to/source/file.pdf', 'all', 'vertical')
  ->addPDF('path/to/source/file1.pdf', 'all')
  ->addPDF('path/to/source/file2.pdf', 'all', 'horizontal');

// call merge, output format `file`
$pdf->merge('file', 'path/to/export/dir/file.pdf');

Or https://packagist.org/packages/karriere/pdf-merge

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