KoolReport's Forum

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

Export PDF + chromeBinary + nodeBinary = can't disable "emulateScreenMedia" #1438

Open Locness Tecnologia e Inovação opened this topic on on May 13, 2020 - 3 comments

Locness Tecnologia e Inovação commented on May 13, 2020

Friends, whenever I'm trying to export a PDF using Headless chrome and Node, paths specified in the chromeBinary and nodeBinary parameters, it causes PHP-Puppetteer to emulate a browser screen ( `emulateScreenMedia=true ` ) .

I commented out the line await page.emulateMedia('screen'); (php-puppeteer/src/js/puppetteer-api.js, line 29) and it renders like printed paper, which is what I need.

It would be nice to add a parameter to determine whether PDFs should print as paper or screen.

My code: `

      $report->pdf([
        "format"=>"A4",
        "orientation"=>"portrait",
        'chromeBinary'=>realpath(dirname(__FILE__)) . "/../../../node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome",
        'nodeBinary'=>'/usr/bin/nodejs',
    ])->saveAs($file);

`

Result, stock - page breaks anywhere, no repetition of headers afterwards:

After commenting this line:

It shows as expected: page breaks don't split up cells and the headers show with every page start:

I can, of course, just comment and leave as is, but then every update to the Koolreport code would be a nightmare.

A configurable option to set params.emulateScreenMedia would be a neater path.

Thanks, Daniel

David Winterburn commented on May 14, 2020

Hi Daniel,

I think there's one solution you could apply by adding another php-puppeteer/puppeteer-api.js, says php-puppeteer/puppeteer-api-print.js and comment out the line await page.emulateMedia('screen'); in this file.

Then in the method pdf() of php-puppeteer/Browser.php you could choose to use either of these executable js files based on an option of the $config parameter. For example:

if (isset($config['usePrintMedia'])) {
    $this->executable = __DIR__.'/js/puppeteer-api-print.js';
}

Finally in your export file, you could set 'usePrintMedia' option when exporting if you want.

Please try it and let us know if you have any difficulty. Thanks!

For future releases of KoolReport, we have been moving the chromeheadless, wkhtmltopdf engines to the CloudExport package while Export package keeps focus on using PhantomJS so it's unlikely we will add more puppeteer features to Export.

Locness Tecnologia e Inovação commented on May 26, 2020

Does that mean all exports are moving to the cloud?

David Winterburn commented on May 26, 2020

No, it doesn't mean that. Export package still runs locally using PhantomJS engine while CloudExport run in the cloud using Chrome headless and WkHtmlToPdf engines.

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
bug
suggestion

Export