1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27:
28:
29:
30: $pdfRendererClassFile = PHPExcel_Settings::getPdfRendererPath() . '/mpdf.php';
31: if (file_exists($pdfRendererClassFile)) {
32: require_once $pdfRendererClassFile;
33: } else {
34: throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library');
35: }
36:
37: 38: 39: 40: 41: 42: 43:
44: class PHPExcel_Writer_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter
45: {
46: 47: 48: 49: 50:
51: public function __construct(PHPExcel $phpExcel)
52: {
53: parent::__construct($phpExcel);
54: }
55:
56: 57: 58: 59: 60: 61:
62: public function save($pFilename = NULL)
63: {
64: $fileHandle = parent::prepareForSave($pFilename);
65:
66:
67: $paperSize = 'LETTER';
68:
69:
70: if (is_null($this->getSheetIndex())) {
71: $orientation = ($this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation()
72: == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
73: ? 'L'
74: : 'P';
75: $printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize();
76: $printMargins = $this->_phpExcel->getSheet(0)->getPageMargins();
77: } else {
78: $orientation = ($this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation()
79: == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
80: ? 'L'
81: : 'P';
82: $printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
83: $printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins();
84: }
85: $this->setOrientation($orientation);
86:
87:
88: if (!is_null($this->getOrientation())) {
89: $orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT)
90: ? PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT
91: : $this->getOrientation();
92: }
93: $orientation = strtoupper($orientation);
94:
95:
96: if (!is_null($this->getPaperSize())) {
97: $printPaperSize = $this->getPaperSize();
98: }
99:
100: if (isset(self::$_paperSizes[$printPaperSize])) {
101: $paperSize = self::$_paperSizes[$printPaperSize];
102: }
103:
104:
105: $pdf = new mpdf();
106: $ortmp = $orientation;
107: $pdf->_setPageSize(strtoupper($paperSize), $ortmp);
108: $pdf->DefOrientation = $orientation;
109: $pdf->AddPage($orientation);
110:
111:
112: $pdf->SetTitle($this->_phpExcel->getProperties()->getTitle());
113: $pdf->SetAuthor($this->_phpExcel->getProperties()->getCreator());
114: $pdf->SetSubject($this->_phpExcel->getProperties()->getSubject());
115: $pdf->SetKeywords($this->_phpExcel->getProperties()->getKeywords());
116: $pdf->SetCreator($this->_phpExcel->getProperties()->getCreator());
117:
118: $pdf->WriteHTML(
119: $this->generateHTMLHeader(FALSE) .
120: $this->generateSheetData() .
121: $this->generateHTMLFooter()
122: );
123:
124:
125: fwrite($fileHandle, $pdf->Output('', 'S'));
126:
127: parent::restoreStateAfterSave($fileHandle);
128: }
129:
130: }
131: