0

I'm trying to convert excel file directly to PDF with the help of PHPSpreadsheet. but got an error "Class 'Mpdf\Mpdf' not found", Here is my code:

<?php 
  require 'vendor/autoload.php';
  use PhpOffice\PhpSpreadsheet\IOFactory;
  use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
  use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
  use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;

  $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
  $reader->setReadDataOnly(true);
  $spreadsheet = $reader->load("excel.xlsx");


  // when I use this MPDF class, I'm getting an error Class \Mpdf\Mpdf not found

  $writer = new \PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf($spreadsheet);
  $writer->save("excel.pdf");

Kindly Help with above code.

Thanks

4

1 回答 1

4

From the documentation of phpspreadsheet:

You must now install a PDF rendering library yourself; but PhpSpreadsheet will work with a number of different libraries.

The error comes from not installing the rendering library you want to use (in this case mPDF). Just add mpdf/mpdf to your composer dependencies.

于 2018-03-20T07:59:21.333 回答