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() . '/tcpdf.php';
31: if (file_exists($pdfRendererClassFile)) {
32: $k_path_url = PHPExcel_Settings::getPdfRendererPath();
33: require_once $pdfRendererClassFile;
34: } else {
35: throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library');
36: }
37:
38: 39: 40: 41: 42: 43: 44:
45: class PHPExcel_Writer_PDF_tcPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter
46: {
47: 48: 49: 50: 51:
52: public function __construct(PHPExcel $phpExcel)
53: {
54: parent::__construct($phpExcel);
55: }
56:
57: 58: 59: 60: 61: 62:
63: public function save($pFilename = NULL)
64: {
65: $fileHandle = parent::prepareForSave($pFilename);
66:
67:
68: $paperSize = 'LETTER';
69:
70:
71: if (is_null($this->getSheetIndex())) {
72: $orientation = ($this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation()
73: == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
74: ? 'L'
75: : 'P';
76: $printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize();
77: $printMargins = $this->_phpExcel->getSheet(0)->getPageMargins();
78: } else {
79: $orientation = ($this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation()
80: == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
81: ? 'L'
82: : 'P';
83: $printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
84: $printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins();
85: }
86:
87:
88: if (!is_null($this->getOrientation())) {
89: $orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
90: ? 'L'
91: : 'P';
92: }
93:
94: if (!is_null($this->getPaperSize())) {
95: $printPaperSize = $this->getPaperSize();
96: }
97:
98: if (isset(self::$_paperSizes[$printPaperSize])) {
99: $paperSize = self::$_paperSizes[$printPaperSize];
100: }
101:
102:
103:
104: $pdf = new TCPDF($orientation, 'pt', $paperSize);
105: $pdf->setFontSubsetting(FALSE);
106:
107: $pdf->SetMargins($printMargins->getLeft() * 72, $printMargins->getTop() * 72, $printMargins->getRight() * 72);
108: $pdf->SetAutoPageBreak(TRUE, $printMargins->getBottom() * 72);
109:
110: $pdf->setPrintHeader(FALSE);
111: $pdf->setPrintFooter(FALSE);
112:
113: $pdf->AddPage();
114:
115:
116: $pdf->SetFont($this->getFont());
117: $pdf->writeHTML(
118: $this->generateHTMLHeader(FALSE) .
119: $this->generateSheetData() .
120: $this->generateHTMLFooter()
121: );
122:
123:
124: $pdf->SetTitle($this->_phpExcel->getProperties()->getTitle());
125: $pdf->SetAuthor($this->_phpExcel->getProperties()->getCreator());
126: $pdf->SetSubject($this->_phpExcel->getProperties()->getSubject());
127: $pdf->SetKeywords($this->_phpExcel->getProperties()->getKeywords());
128: $pdf->SetCreator($this->_phpExcel->getProperties()->getCreator());
129:
130:
131: fwrite($fileHandle, $pdf->output($pFilename, 'S'));
132:
133: parent::restoreStateAfterSave($fileHandle);
134: }
135:
136: }
137: