phptcpdfphpoffice-phpspreadsheet

PHPSpreadsheet writer - How to fit content


I've successfully convert Excel to PDF using this code:

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Tcpdf');
$writer->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE);
header("Content-Disposition: attachment; filename=test.pdf");
$writer->save('php://output');

My problem is, the Excels has too many columns so the generated PDF crop the data.

Is it possible to either:

  1. Fit the Excel into A4 Landscape (make the Excel scale smaller)
  2. Auto resize the PDF to fit the content (it will be bigger than A4 and not necessary standard US Paper Size)

Solution

  • I think there's no solution for this. So I just reduce the font size. When my data is small, the paper space will be wasted