kartik-v / yii2-export

A library to export server/db data in various formats (e.g. excel, html, pdf, csv etc.)
http://demos.krajee.com/export
Other
165 stars 126 forks source link

pdfConfig is being ignored #343

Closed adhayward closed 3 years ago

adhayward commented 3 years ago

Not sure if the issue lies in the yii2-export library or with the yii2-mpdf one but it seems that the pdfConfig doesn't get applied when exporting pdfs. I've checked the Control Export Formats demo and there the settings listed there don't apply to the PDF products (there is no header/footer and the various meta properties are not filled in.

Prerequisites

Steps to reproduce the issue

  1. Specify any settings in the pdfConfig, eg.
    echo ExportMenu::widget([
    'exportConfig' => [
        ExportMenu::FORMAT_PDF => [
            'pdfConfig' => [
                'methods' => [
                    'SetTitle' => 'Grid Export - Krajee.com',
                    'SetSubject' => 'Generating PDF files via yii2-export extension has never been easy',
                    'SetHeader' => ['Krajee Library Export||Generated On: ' . date("r")],
                    'SetFooter' => ['|Page {PAGENO}|'],
                    'SetAuthor' => 'Kartik Visweswaran',
                    'SetCreator' => 'Kartik Visweswaran',
                    'SetKeywords' => 'Krajee, Yii2, Export, PDF, MPDF, Output, GridView, Grid, yii2-grid, yii2-mpdf, yii2-export',
                ]
            ]
        ],
    ],
  2. Export as pdf using the widget dropdown

Expected behavior and actual behavior

When I follow those steps, the PDF produced uses the default config, completely ignoring every option I've tried to specify.

I was expecting the config specified to affect the PDF produced

Environment

Browsers

Operating System

Libraries

Isolating the problem

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/96362916-pdfconfig-is-being-ignored?utm_campaign=plugin&utm_content=tracker%2F7668315&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F7668315&utm_medium=issues&utm_source=github).
adhayward commented 3 years ago

I've done some digging into this issue and I believe the issue lies in how kartik\export\ExportWriterPdf and it's parent class PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf work.

Essentially the save function isn't overridden and sets a lot of the properties to values retrieved from the spreadsheet.

The settings defined in ExportMenu::pdfConfig get passed to kartik\mpdf\Mpdf but the output function in kartik\mpdf\Pdf never gets called so none of the properties set in the pdfConfig propagate down to the outputted pdf file.

I'm going to have a look at overriding the save function in ExportWriterPdf in such a way as to mimic the Pdf::output function which should hopefully allow all of the config to be passed correctly.

If I get it working I can post a Pull Request.

adhayward commented 3 years ago

PR #344 gets the config to pass through however I encountered issues with the headers only appearing on page 1. I've put some code in to rectify that too but I feel like there should be a better way of fixing it.

kartik-v commented 3 years ago

Thanks will check.

lloyd966 commented 3 years ago

Any idea when this might be verified, and fixed if necessary?

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.