PhpSpreadsheet/samples/01_Simple_download_pdf.php
Adrien Crivelli 035281f04c
Basic test covering of all PDF writers
Third party PDF libraries must now be installed via composer and naturally
via composer autoloading mechanism. Because of that it is not necessary
to specify their path on disk. The usage is simplified and it allows us
to include them in our unit tests.

This also means that from now on PhpSpreadsheet must use composer autoloader
mechanism. The internal autoloading implementation was dropped.
2017-01-22 00:49:44 +09:00

59 lines
2.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once __DIR__ . '/../src/Bootstrap.php';
$helper = new \PhpOffice\PhpSpreadsheet\Helper\Sample();
if ($helper->isCli()) {
echo 'This example should only be run from a Web Browser' . PHP_EOL;
return;
}
// Change these values to select the Rendering library that you wish to use
// and its directory location on your server
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF;
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF;
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF;
// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
// Set document properties
$spreadsheet->getProperties()->setCreator('Maarten Balliauw')
->setLastModifiedBy('Maarten Balliauw')
->setTitle('PDF Test Document')
->setSubject('PDF Test Document')
->setDescription('Test document for PDF, generated using PHP classes.')
->setKeywords('pdf php')
->setCategory('Test result file');
// Add some data
$spreadsheet->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello')
->setCellValue('B2', 'world!')
->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!');
// Miscellaneous glyphs, UTF-8
$spreadsheet->setActiveSheetIndex(0)
->setCellValue('A4', 'Miscellaneous glyphs')
->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');
// Rename worksheet
$spreadsheet->getActiveSheet()->setTitle('Simple');
$spreadsheet->getActiveSheet()->setShowGridLines(false);
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$spreadsheet->setActiveSheetIndex(0);
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName);
// Redirect output to a clients web browser (PDF)
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="01simple.pdf"');
header('Cache-Control: max-age=0');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'PDF');
$writer->save('php://output');
exit;