ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
tcPDF.php
Go to the documentation of this file.
1<?php
31if (file_exists($pdfRendererClassFile)) {
33 require_once $pdfRendererClassFile;
34} else {
35 throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library');
36}
37
46{
52 public function __construct(PHPExcel $phpExcel)
53 {
54 parent::__construct($phpExcel);
55 }
56
63 public function save($pFilename = NULL)
64 {
65 $fileHandle = parent::prepareForSave($pFilename);
66
67 // Default PDF paper size
68 $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.)
69
70 // Check for paper size and page orientation
71 if (is_null($this->getSheetIndex())) {
72 $orientation = ($this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation()
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()
81 ? 'L'
82 : 'P';
83 $printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
84 $printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins();
85 }
86
87 // Override Page Orientation
88 if (!is_null($this->getOrientation())) {
90 ? 'L'
91 : 'P';
92 }
93 // Override Paper Size
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 // Create PDF
104 $pdf = new TCPDF($orientation, 'pt', $paperSize);
105 $pdf->setFontSubsetting(FALSE);
106 // Set margins, converting inches to points (using 72 dpi)
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 // Set the appropriate font
116 $pdf->SetFont($this->getFont());
117 $pdf->writeHTML(
118 $this->generateHTMLHeader(FALSE) .
119 $this->generateSheetData() .
120 $this->generateHTMLFooter()
121 );
122
123 // Document info
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 // Write to file
131 fwrite($fileHandle, $pdf->output($pFilename, 'S'));
132
133 parent::restoreStateAfterSave($fileHandle);
134 }
135
136}
An exception for terminatinating execution or to throw for unit testing.
static getPdfRendererPath()
Return the directory path to the PDF Rendering Library that PHPExcel is currently configured to use.
Definition: Settings.php:354
generateHTMLFooter()
Generate HTML footer.
Definition: HTML.php:1004
getSheetIndex()
Get sheet index.
Definition: HTML.php:255
generateHTMLHeader($pIncludeStyles=false)
Generate HTML header.
Definition: HTML.php:305
generateSheetData()
Generate sheet data.
Definition: HTML.php:356
getFont()
Get Font.
Definition: Core.php:231
getPaperSize()
Get Paper Size.
Definition: Core.php:256
getOrientation()
Get Orientation.
Definition: Core.php:278
save($pFilename=NULL)
Save PHPExcel to file.
Definition: tcPDF.php:63
__construct(PHPExcel $phpExcel)
Create a new PHPExcel_Writer_PDF.
Definition: tcPDF.php:52
PHP class for generating PDF documents without requiring external extensions.
Definition: tcpdf.php:134
$pdf
Definition: example_001.php:31
$pdfRendererClassFile
Require tcPDF library.
Definition: tcPDF.php:30