PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.35k stars 3.47k forks source link

Class 'Mpdf\Mpdf' not found in ..\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Writer\Pdf\Mpdf.php #1677

Closed jmechevarria closed 2 years ago

jmechevarria commented 4 years ago

This is:

- [X] a bug report
- [ ] a feature request
- [X] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

\Mpdf\Mpdf to be defined and its constructor's signature to comply with the parent class' (PhpOffice\PhpSpreadsheet\Writer\Pdf)

What is the current behavior?

\Mpdf\Mpdf is not defined

What are the steps to reproduce?

  1. install via composer require phpoffice/phpspreadsheet
  2. Follow the example in the docs to write a spreadsheet into pdf format.

Errors screens Screenshot (576) : Screenshot (577)

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php
require __DIR__ . '/vendor/autoload.php';

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');

$writer = new \PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf($spreadsheet); //tried the three variants in the example for instantiating

$writer->save("05featuredemo.pdf"); //<----- triggers the error

First time using this tool, but the only Mpdf class I can find in the whole codebase is the same in which the error is occurring, there's no Mpdf folder at all, hence there can't be an \Mpdf\Mpdf class. So I tried to change:

    `return new \Mpdf\Mpdf($config);`

with

    `return new Mpdf($config);`

since it did make more sense to me and, yes, the error went away, but then this happened:

Screenshot (580)

Screenshot (579)

So I switched it back and posted this here.

Thanks

Which versions of PhpSpreadsheet and PHP are affected?

PHP 7.4.11 PhpSpreadsheet 1.14.1 - 2020-07-19


PS there's also a typo in the docs (same link), in section Or you can instantiate directly the writer of your choice like so: $writer = \PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf($spreadsheet); throws error Call to undefined function PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf(), it seems to be missing the keyword new after = sign.

MarkBaker commented 4 years ago

Have you actually composer installed mPDF? This is an option, not installed as part of PHPSpreadsheet itself

composer require mpdf/mpdf

jmechevarria commented 4 years ago

Have you actually composer installed mPDF? This is an option, not installed as part of PHPSpreadsheet itself

composer require mpdf/mpdf

I had not. I really missed this: You must now install a PDF rendering library yourself. I guess I scanned the docs instead of reading the docs, and missed that bit.

Thanks a lot

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. If this is still an issue for you, please try to help by debugging it further and sharing your results. Thank you for your contributions.

qant commented 3 years ago

Have you actually composer installed mPDF? This is an option, not installed as part of PHPSpreadsheet itself

composer require mpdf/mpdf

It MUST be in docs ar least... i get the same error...