mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-01 04:59:14 +00:00
39df9c3bcc
* Fix Some Pdf Problems Fix #1747. No support for text rotation in Pdf. That issue actually has a decent workaround, but PhpSpreadsheet should handle it on its own. Mpdf requires the proprietary text-rotate css attribute; Html and Dompdf will use the CSS3 attribute transform:rotate. Fix #1713. Some paper-size values in PhpSpreadsheet are strings, some are 2-element float arrays. Dompdf accepts strings or 4-element float arrays, where the first 2 elements are always 0. Convert the PhpSpreadsheet array accordingly before passing it to Dompdf. Some tests had been disabled when Dompdf and Tcpdf were slow to achieve PHP8 compliance. They achieved it some time ago. Re-enable the tests. * Remove Tcpdf From One Test No problem with the other tests I added it in for.
66 lines
2.4 KiB
PHP
66 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Writer\Dompdf;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\File;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class PaperSizeArrayTest extends TestCase
|
|
{
|
|
/** @var string */
|
|
private $outfile = '';
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
if ($this->outfile !== '') {
|
|
unlink($this->outfile);
|
|
$this->outfile = '';
|
|
}
|
|
}
|
|
|
|
public function testPaperSizeArray(): void
|
|
{
|
|
// Issue 1713 - array in PhpSpreadsheet is 2 elements,
|
|
// but in Dompdf it is 4 elements, first 2 are zero.
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
// TABLOID is a 2-element array in Writer/Pdf.php $paperSizes
|
|
$size = PageSetup::PAPERSIZE_TABLOID;
|
|
$sheet->getPageSetup()->setPaperSize($size);
|
|
$sheet->setPrintGridlines(true);
|
|
$sheet->getStyle('A7')->getAlignment()->setTextRotation(90);
|
|
$sheet->setCellValue('A7', 'Lorem Ipsum');
|
|
$writer = new Dompdf($spreadsheet);
|
|
$this->outfile = File::temporaryFilename();
|
|
$writer->save($this->outfile);
|
|
$spreadsheet->disconnectWorksheets();
|
|
unset($spreadsheet);
|
|
$contents = file_get_contents($this->outfile);
|
|
self::assertNotFalse($contents);
|
|
self::assertStringContainsString('/MediaBox [0.000 0.000 792.000 1224.000]', $contents);
|
|
}
|
|
|
|
public function testPaperSizeNotArray(): void
|
|
{
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
// LETTER is a string in Writer/Pdf.php $paperSizes
|
|
$size = PageSetup::PAPERSIZE_LETTER;
|
|
$sheet->getPageSetup()->setPaperSize($size);
|
|
$sheet->setPrintGridlines(true);
|
|
$sheet->getStyle('A7')->getAlignment()->setTextRotation(90);
|
|
$sheet->setCellValue('A7', 'Lorem Ipsum');
|
|
$writer = new Dompdf($spreadsheet);
|
|
$this->outfile = File::temporaryFilename();
|
|
$writer->save($this->outfile);
|
|
$spreadsheet->disconnectWorksheets();
|
|
unset($spreadsheet);
|
|
$contents = file_get_contents($this->outfile);
|
|
self::assertNotFalse($contents);
|
|
self::assertStringContainsString('/MediaBox [0.000 0.000 612.000 792.000]', $contents);
|
|
}
|
|
}
|