Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
 
3
namespace PhpOffice\PhpSpreadsheet\Writer\Pdf;
4
 
5
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
6
use PhpOffice\PhpSpreadsheet\Writer\Pdf;
7
 
8
class Dompdf extends Pdf
9
{
10
    /**
11
     * embed images, or link to images.
12
     */
13
    protected bool $embedImages = true;
14
 
15
    /**
16
     * Gets the implementation of external PDF library that should be used.
17
     *
18
     * @return \Dompdf\Dompdf implementation
19
     */
20
    protected function createExternalWriterInstance(): \Dompdf\Dompdf
21
    {
22
        return new \Dompdf\Dompdf();
23
    }
24
 
25
    /**
26
     * Save Spreadsheet to file.
27
     *
28
     * @param string $filename Name of the file to save as
29
     */
30
    public function save($filename, int $flags = 0): void
31
    {
32
        $fileHandle = parent::prepareForSave($filename);
33
 
34
        //  Check for paper size and page orientation
35
        $setup = $this->spreadsheet->getSheet($this->getSheetIndex() ?? 0)->getPageSetup();
36
        $orientation = $this->getOrientation() ?? $setup->getOrientation();
37
        $orientation = ($orientation === PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
38
        $printPaperSize = $this->getPaperSize() ?? $setup->getPaperSize();
39
        $paperSize = self::$paperSizes[$printPaperSize] ?? PageSetup::getPaperSizeDefault();
40
        if (is_array($paperSize) && count($paperSize) === 2) {
41
            $paperSize = [0.0, 0.0, $paperSize[0], $paperSize[1]];
42
        }
43
 
44
        $orientation = ($orientation == 'L') ? 'landscape' : 'portrait';
45
 
46
        //  Create PDF
47
        $pdf = $this->createExternalWriterInstance();
48
        $pdf->setPaper($paperSize, $orientation);
49
 
50
        $pdf->loadHtml($this->generateHTMLAll());
51
        $pdf->render();
52
 
53
        //  Write to file
54
        fwrite($fileHandle, $pdf->output() ?? '');
55
 
56
        parent::restoreStateAfterSave();
57
    }
58
}