Some refactoring of PDF renderer wrappers and PDF Writer

This commit is contained in:
Mark Baker 2012-11-03 23:44:10 +00:00
parent 0ad1c8b585
commit 016ee6e4d8
6 changed files with 686 additions and 591 deletions

View File

@ -41,5 +41,6 @@ interface PHPExcel_Writer_IWriter
* @param string $pFilename * @param string $pFilename
* @throws PHPExcel_Writer_Exception * @throws PHPExcel_Writer_Exception
*/ */
public function save($pFilename = null); public function save($pFilename = NULL);
} }

View File

@ -33,7 +33,8 @@
* @package PHPExcel_Writer * @package PHPExcel_Writer
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Writer_PDF { class PHPExcel_Writer_PDF
{
private $_renderer = NULL; private $_renderer = NULL;
@ -41,10 +42,10 @@ class PHPExcel_Writer_PDF {
* Create a new PHPExcel_Writer_PDF * Create a new PHPExcel_Writer_PDF
* *
* @param PHPExcel $phpExcel PHPExcel object * @param PHPExcel $phpExcel PHPExcel object
* @throws PHPExcel_Writer_Exception Exception when directory does not exist * @throws PHPExcel_Writer_Exception Exception when PDF library is not configured
*/ */
public function __construct(PHPExcel $phpExcel) { public function __construct(PHPExcel $phpExcel)
{
$pdfLibraryName = PHPExcel_Settings::getPdfRendererName(); $pdfLibraryName = PHPExcel_Settings::getPdfRendererName();
if (is_null($pdfLibraryName)) { if (is_null($pdfLibraryName)) {
throw new PHPExcel_Writer_Exception("PDF Rendering library has not been defined."); throw new PHPExcel_Writer_Exception("PDF Rendering library has not been defined.");
@ -54,24 +55,31 @@ class PHPExcel_Writer_PDF {
if (is_null($pdfLibraryName)) { if (is_null($pdfLibraryName)) {
throw new PHPExcel_Writer_Exception("PDF Rendering library path has not been defined."); throw new PHPExcel_Writer_Exception("PDF Rendering library path has not been defined.");
} }
$includePath = str_replace('\\','/',get_include_path()); $includePath = str_replace('\\', '/', get_include_path());
$rendererPath = str_replace('\\','/',$pdfLibraryPath); $rendererPath = str_replace('\\', '/', $pdfLibraryPath);
if (strpos($rendererPath,$includePath) === false) { if (strpos($rendererPath, $includePath) === false) {
set_include_path(get_include_path() . PATH_SEPARATOR . $pdfLibraryPath); set_include_path(get_include_path() . PATH_SEPARATOR . $pdfLibraryPath);
} }
$rendererName = 'PHPExcel_Writer_PDF_'.$pdfLibraryName; $rendererName = 'PHPExcel_Writer_PDF_' . $pdfLibraryName;
$this->_renderer = new $rendererName($phpExcel); $this->_renderer = new $rendererName($phpExcel);
} }
/**
* Magic method to handle direct calls to the renderer library
*
* @param string $name Renderer library method name
* @param mixed[] $arguments Array of arguments to pass to the renderer method
* @return mixed Returned data from the renderer method
*/
public function __call($name, $arguments) public function __call($name, $arguments)
{ {
if ($this->_renderer === NULL) { if ($this->_renderer === NULL) {
throw new PHPExcel_Writer_Exception("PDF Renderer has not been defined."); throw new PHPExcel_Writer_Exception("PDF Renderer has not been defined.");
} }
return call_user_func_array(array($this->_renderer,$name),$arguments); return call_user_func_array(array($this->_renderer, $name), $arguments);
} }
} }

View File

@ -33,7 +33,8 @@
* @package PHPExcel_Writer * @package PHPExcel_Writer
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML { abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML
{
/** /**
* Temporary storage directory * Temporary storage directory
* *
@ -53,14 +54,14 @@ abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML {
* *
* @var string * @var string
*/ */
private $_orientation = null; private $_orientation = NULL;
/** /**
* Paper size (Over-ride) * Paper size (Over-ride)
* *
* @var int * @var int
*/ */
private $_paperSize = null; private $_paperSize = NULL;
/** /**
@ -69,73 +70,138 @@ abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML {
* @var array * @var array
*/ */
protected static $_paperSizes = array( protected static $_paperSizes = array(
// Excel Paper Size TCPDF Paper Size PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER => 'LETTER', // (8.5 in. by 11 in.) => 'LETTER', // (8.5 in. by 11 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_SMALL => 'LETTER', // (8.5 in. by 11 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_SMALL
PHPExcel_Worksheet_PageSetup::PAPERSIZE_TABLOID => array(792.00,1224.00), // (11 in. by 17 in.) => 'LETTER', // (8.5 in. by 11 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LEDGER => array(1224.00,792.00), // (17 in. by 11 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_TABLOID
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LEGAL => 'LEGAL', // (8.5 in. by 14 in.) => array(792.00, 1224.00), // (11 in. by 17 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_STATEMENT => array(396.00,612.00), // (5.5 in. by 8.5 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_LEDGER
PHPExcel_Worksheet_PageSetup::PAPERSIZE_EXECUTIVE => 'EXECUTIVE', // (7.25 in. by 10.5 in.) => array(1224.00, 792.00), // (17 in. by 11 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3 => 'A3', // (297 mm by 420 mm) PHPExcel_Worksheet_PageSetup::PAPERSIZE_LEGAL
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4 => 'A4', // (210 mm by 297 mm) => 'LEGAL', // (8.5 in. by 14 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_SMALL => 'A4', // (210 mm by 297 mm) PHPExcel_Worksheet_PageSetup::PAPERSIZE_STATEMENT
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A5 => 'A5', // (148 mm by 210 mm) => array(396.00, 612.00), // (5.5 in. by 8.5 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_B4 => 'B4', // (250 mm by 353 mm) PHPExcel_Worksheet_PageSetup::PAPERSIZE_EXECUTIVE
PHPExcel_Worksheet_PageSetup::PAPERSIZE_B5 => 'B5', // (176 mm by 250 mm) => 'EXECUTIVE', // (7.25 in. by 10.5 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_FOLIO => 'FOLIO', // (8.5 in. by 13 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3
PHPExcel_Worksheet_PageSetup::PAPERSIZE_QUARTO => array(609.45,779.53), // (215 mm by 275 mm) => 'A3', // (297 mm by 420 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_1 => array(720.00,1008.00), // (10 in. by 14 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4
PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_2 => array(792.00,1224.00), // (11 in. by 17 in.) => 'A4', // (210 mm by 297 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_NOTE => 'LETTER', // (8.5 in. by 11 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_SMALL
PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO9_ENVELOPE => array(279.00,639.00), // (3.875 in. by 8.875 in.) => 'A4', // (210 mm by 297 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO10_ENVELOPE => array(297.00,684.00), // (4.125 in. by 9.5 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_A5
PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO11_ENVELOPE => array(324.00,747.00), // (4.5 in. by 10.375 in.) => 'A5', // (148 mm by 210 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO12_ENVELOPE => array(342.00,792.00), // (4.75 in. by 11 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_B4
PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO14_ENVELOPE => array(360.00,828.00), // (5 in. by 11.5 in.) => 'B4', // (250 mm by 353 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_C => array(1224.00,1584.00), // (17 in. by 22 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_B5
PHPExcel_Worksheet_PageSetup::PAPERSIZE_D => array(1584.00,2448.00), // (22 in. by 34 in.) => 'B5', // (176 mm by 250 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_E => array(2448.00,3168.00), // (34 in. by 44 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_FOLIO
PHPExcel_Worksheet_PageSetup::PAPERSIZE_DL_ENVELOPE => array(311.81,623.62), // (110 mm by 220 mm) => 'FOLIO', // (8.5 in. by 13 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_C5_ENVELOPE => 'C5', // (162 mm by 229 mm) PHPExcel_Worksheet_PageSetup::PAPERSIZE_QUARTO
PHPExcel_Worksheet_PageSetup::PAPERSIZE_C3_ENVELOPE => 'C3', // (324 mm by 458 mm) => array(609.45, 779.53), // (215 mm by 275 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_C4_ENVELOPE => 'C4', // (229 mm by 324 mm) PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_1
PHPExcel_Worksheet_PageSetup::PAPERSIZE_C6_ENVELOPE => 'C6', // (114 mm by 162 mm) => array(720.00, 1008.00), // (10 in. by 14 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_C65_ENVELOPE => array(323.15,649.13), // (114 mm by 229 mm) PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_2
PHPExcel_Worksheet_PageSetup::PAPERSIZE_B4_ENVELOPE => 'B4', // (250 mm by 353 mm) => array(792.00, 1224.00), // (11 in. by 17 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_B5_ENVELOPE => 'B5', // (176 mm by 250 mm) PHPExcel_Worksheet_PageSetup::PAPERSIZE_NOTE
PHPExcel_Worksheet_PageSetup::PAPERSIZE_B6_ENVELOPE => array(498.90,354.33), // (176 mm by 125 mm) => 'LETTER', // (8.5 in. by 11 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_ITALY_ENVELOPE => array(311.81,651.97), // (110 mm by 230 mm) PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO9_ENVELOPE
PHPExcel_Worksheet_PageSetup::PAPERSIZE_MONARCH_ENVELOPE => array(279.00,540.00), // (3.875 in. by 7.5 in.) => array(279.00, 639.00), // (3.875 in. by 8.875 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_6_3_4_ENVELOPE => array(261.00,468.00), // (3.625 in. by 6.5 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO10_ENVELOPE
PHPExcel_Worksheet_PageSetup::PAPERSIZE_US_STANDARD_FANFOLD => array(1071.00,792.00), // (14.875 in. by 11 in.) => array(297.00, 684.00), // (4.125 in. by 9.5 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_GERMAN_STANDARD_FANFOLD => array(612.00,864.00), // (8.5 in. by 12 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO11_ENVELOPE
PHPExcel_Worksheet_PageSetup::PAPERSIZE_GERMAN_LEGAL_FANFOLD => 'FOLIO', // (8.5 in. by 13 in.) => array(324.00, 747.00), // (4.5 in. by 10.375 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_ISO_B4 => 'B4', // (250 mm by 353 mm) PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO12_ENVELOPE
PHPExcel_Worksheet_PageSetup::PAPERSIZE_JAPANESE_DOUBLE_POSTCARD => array(566.93,419.53), // (200 mm by 148 mm) => array(342.00, 792.00), // (4.75 in. by 11 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_PAPER_1 => array(648.00,792.00), // (9 in. by 11 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO14_ENVELOPE
PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_PAPER_2 => array(720.00,792.00), // (10 in. by 11 in.) => array(360.00, 828.00), // (5 in. by 11.5 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_PAPER_3 => array(1080.00,792.00), // (15 in. by 11 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_C
PHPExcel_Worksheet_PageSetup::PAPERSIZE_INVITE_ENVELOPE => array(623.62,623.62), // (220 mm by 220 mm) => array(1224.00, 1584.00), // (17 in. by 22 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_EXTRA_PAPER => array(667.80,864.00), // (9.275 in. by 12 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_D
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LEGAL_EXTRA_PAPER => array(667.80,1080.00), // (9.275 in. by 15 in.) => array(1584.00, 2448.00), // (22 in. by 34 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_TABLOID_EXTRA_PAPER => array(841.68,1296.00), // (11.69 in. by 18 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_E
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_EXTRA_PAPER => array(668.98,912.76), // (236 mm by 322 mm) => array(2448.00, 3168.00), // (34 in. by 44 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_TRANSVERSE_PAPER => array(595.80,792.00), // (8.275 in. by 11 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_DL_ENVELOPE
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_TRANSVERSE_PAPER => 'A4', // (210 mm by 297 mm) => array(311.81, 623.62), // (110 mm by 220 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_EXTRA_TRANSVERSE_PAPER => array(667.80,864.00), // (9.275 in. by 12 in.) PHPExcel_Worksheet_PageSetup::PAPERSIZE_C5_ENVELOPE
PHPExcel_Worksheet_PageSetup::PAPERSIZE_SUPERA_SUPERA_A4_PAPER => array(643.46,1009.13), // (227 mm by 356 mm) => 'C5', // (162 mm by 229 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_SUPERB_SUPERB_A3_PAPER => array(864.57,1380.47), // (305 mm by 487 mm) PHPExcel_Worksheet_PageSetup::PAPERSIZE_C3_ENVELOPE
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_PLUS_PAPER => array(612.00,913.68), // (8.5 in. by 12.69 in.) => 'C3', // (324 mm by 458 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_PLUS_PAPER => array(595.28,935.43), // (210 mm by 330 mm) PHPExcel_Worksheet_PageSetup::PAPERSIZE_C4_ENVELOPE
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A5_TRANSVERSE_PAPER => 'A5', // (148 mm by 210 mm) => 'C4', // (229 mm by 324 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_JIS_B5_TRANSVERSE_PAPER => array(515.91,728.50), // (182 mm by 257 mm) PHPExcel_Worksheet_PageSetup::PAPERSIZE_C6_ENVELOPE
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3_EXTRA_PAPER => array(912.76,1261.42), // (322 mm by 445 mm) => 'C6', // (114 mm by 162 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A5_EXTRA_PAPER => array(493.23,666.14), // (174 mm by 235 mm) PHPExcel_Worksheet_PageSetup::PAPERSIZE_C65_ENVELOPE
PHPExcel_Worksheet_PageSetup::PAPERSIZE_ISO_B5_EXTRA_PAPER => array(569.76,782.36), // (201 mm by 276 mm) => array(323.15, 649.13), // (114 mm by 229 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A2_PAPER => 'A2', // (420 mm by 594 mm) PHPExcel_Worksheet_PageSetup::PAPERSIZE_B4_ENVELOPE
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3_TRANSVERSE_PAPER => 'A3', // (297 mm by 420 mm) => 'B4', // (250 mm by 353 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3_EXTRA_TRANSVERSE_PAPER => array(912.76,1261.42) // (322 mm by 445 mm) PHPExcel_Worksheet_PageSetup::PAPERSIZE_B5_ENVELOPE
=> 'B5', // (176 mm by 250 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_B6_ENVELOPE
=> array(498.90, 354.33), // (176 mm by 125 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_ITALY_ENVELOPE
=> array(311.81, 651.97), // (110 mm by 230 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_MONARCH_ENVELOPE
=> array(279.00, 540.00), // (3.875 in. by 7.5 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_6_3_4_ENVELOPE
=> array(261.00, 468.00), // (3.625 in. by 6.5 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_US_STANDARD_FANFOLD
=> array(1071.00, 792.00), // (14.875 in. by 11 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_GERMAN_STANDARD_FANFOLD
=> array(612.00, 864.00), // (8.5 in. by 12 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_GERMAN_LEGAL_FANFOLD
=> 'FOLIO', // (8.5 in. by 13 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_ISO_B4
=> 'B4', // (250 mm by 353 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_JAPANESE_DOUBLE_POSTCARD
=> array(566.93, 419.53), // (200 mm by 148 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_PAPER_1
=> array(648.00, 792.00), // (9 in. by 11 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_PAPER_2
=> array(720.00, 792.00), // (10 in. by 11 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_PAPER_3
=> array(1080.00, 792.00), // (15 in. by 11 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_INVITE_ENVELOPE
=> array(623.62, 623.62), // (220 mm by 220 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_EXTRA_PAPER
=> array(667.80, 864.00), // (9.275 in. by 12 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LEGAL_EXTRA_PAPER
=> array(667.80, 1080.00), // (9.275 in. by 15 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_TABLOID_EXTRA_PAPER
=> array(841.68, 1296.00), // (11.69 in. by 18 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_EXTRA_PAPER
=> array(668.98, 912.76), // (236 mm by 322 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_TRANSVERSE_PAPER
=> array(595.80, 792.00), // (8.275 in. by 11 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_TRANSVERSE_PAPER
=> 'A4', // (210 mm by 297 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_EXTRA_TRANSVERSE_PAPER
=> array(667.80, 864.00), // (9.275 in. by 12 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_SUPERA_SUPERA_A4_PAPER
=> array(643.46, 1009.13), // (227 mm by 356 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_SUPERB_SUPERB_A3_PAPER
=> array(864.57, 1380.47), // (305 mm by 487 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_PLUS_PAPER
=> array(612.00, 913.68), // (8.5 in. by 12.69 in.)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_PLUS_PAPER
=> array(595.28, 935.43), // (210 mm by 330 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A5_TRANSVERSE_PAPER
=> 'A5', // (148 mm by 210 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_JIS_B5_TRANSVERSE_PAPER
=> array(515.91, 728.50), // (182 mm by 257 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3_EXTRA_PAPER
=> array(912.76, 1261.42), // (322 mm by 445 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A5_EXTRA_PAPER
=> array(493.23, 666.14), // (174 mm by 235 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_ISO_B5_EXTRA_PAPER
=> array(569.76, 782.36), // (201 mm by 276 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A2_PAPER
=> 'A2', // (420 mm by 594 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3_TRANSVERSE_PAPER
=> 'A3', // (297 mm by 420 mm)
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3_EXTRA_TRANSVERSE_PAPER
=> array(912.76, 1261.42) // (322 mm by 445 mm)
); );
/** /**
@ -143,9 +209,10 @@ abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML {
* *
* @param PHPExcel $phpExcel PHPExcel object * @param PHPExcel $phpExcel PHPExcel object
*/ */
public function __construct(PHPExcel $phpExcel) { public function __construct(PHPExcel $phpExcel)
{
parent::__construct($phpExcel); parent::__construct($phpExcel);
$this->setUseInlineCss(true); $this->setUseInlineCss(TRUE);
$this->_tempDir = PHPExcel_Shared_File::sys_get_temp_dir(); $this->_tempDir = PHPExcel_Shared_File::sys_get_temp_dir();
} }
@ -154,7 +221,8 @@ abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML {
* *
* @return string * @return string
*/ */
public function getFont() { public function getFont()
{
return $this->_font; return $this->_font;
} }
@ -167,7 +235,8 @@ abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML {
* *
* @param string $fontName * @param string $fontName
*/ */
public function setFont($fontName) { public function setFont($fontName)
{
$this->_font = $fontName; $this->_font = $fontName;
return $this; return $this;
} }
@ -177,7 +246,8 @@ abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML {
* *
* @return int * @return int
*/ */
public function getPaperSize() { public function getPaperSize()
{
return $this->_paperSize; return $this->_paperSize;
} }
@ -187,7 +257,8 @@ abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML {
* @param int $pValue * @param int $pValue
* @return PHPExcel_Writer_PDF * @return PHPExcel_Writer_PDF
*/ */
public function setPaperSize($pValue = PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER) { public function setPaperSize($pValue = PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER)
{
$this->_paperSize = $pValue; $this->_paperSize = $pValue;
return $this; return $this;
} }
@ -197,7 +268,8 @@ abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML {
* *
* @return string * @return string
*/ */
public function getOrientation() { public function getOrientation()
{
return $this->_orientation; return $this->_orientation;
} }
@ -207,7 +279,8 @@ abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML {
* @param string $pValue * @param string $pValue
* @return PHPExcel_Writer_PDF * @return PHPExcel_Writer_PDF
*/ */
public function setOrientation($pValue = PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT) { public function setOrientation($pValue = PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT)
{
$this->_orientation = $pValue; $this->_orientation = $pValue;
return $this; return $this;
} }
@ -217,7 +290,8 @@ abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML {
* *
* @return string * @return string
*/ */
public function getTempDir() { public function getTempDir()
{
return $this->_tempDir; return $this->_tempDir;
} }
@ -228,7 +302,8 @@ abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML {
* @throws PHPExcel_Writer_Exception Exception when directory does not exist * @throws PHPExcel_Writer_Exception Exception when directory does not exist
* @return PHPExcel_Writer_PDF * @return PHPExcel_Writer_PDF
*/ */
public function setTempDir($pValue = '') { public function setTempDir($pValue = '')
{
if (is_dir($pValue)) { if (is_dir($pValue)) {
$this->_tempDir = $pValue; $this->_tempDir = $pValue;
} else { } else {
@ -236,4 +311,33 @@ abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML {
} }
return $this; return $this;
} }
/**
* Save PHPExcel to file, pre-save
*
* @param string $pFileName
* @throws PHPExcel_Writer_Exception
*/
protected function prepareForSave($pFilename = NULL)
{
// garbage collect
$this->_phpExcel->garbageCollect();
$saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType();
PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE);
// Open file
$fileHandle = fopen($pFilename, 'w');
if ($fileHandle === FALSE) {
throw new PHPExcel_Reader_Exception("Could not open file $pFilename for writing.");
}
// Set PDF
$this->_isPdf = TRUE;
// Build CSS
$this->buildCSS(TRUE);
return $fileHandle;
}
} }

View File

@ -41,13 +41,15 @@ if (file_exists($pdfRendererClassFile)) {
* @package PHPExcel_Writer * @package PHPExcel_Writer
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Writer_PDF_DomPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter { class PHPExcel_Writer_PDF_DomPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter
{
/** /**
* Create a new PHPExcel_Writer_PDF * Create a new PHPExcel_Writer_PDF
* *
* @param PHPExcel $phpExcel PHPExcel object * @param PHPExcel $phpExcel PHPExcel object
*/ */
public function __construct(PHPExcel $phpExcel) { public function __construct(PHPExcel $phpExcel)
{
parent::__construct($phpExcel); parent::__construct($phpExcel);
} }
@ -55,44 +57,37 @@ class PHPExcel_Writer_PDF_DomPDF extends PHPExcel_Writer_PDF_Core implements PHP
* Save PHPExcel to file * Save PHPExcel to file
* *
* @param string $pFileName * @param string $pFileName
* @throws PHPExcel_Reader_Exception * @throws PHPExcel_Writer_Exception
*/ */
public function save($pFilename = null) { public function save($pFilename = NULL)
// garbage collect {
$this->_phpExcel->garbageCollect(); $fileHandle = parent::prepareForSave($pFilename);
$saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType();
PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE);
// Open file
$fileHandle = fopen($pFilename, 'w');
if ($fileHandle === false) {
throw new PHPExcel_Reader_Exception("Could not open file $pFilename for writing.");
}
// Set PDF
$this->_isPdf = true;
// Build CSS
$this->buildCSS(true);
// Default PDF paper size // Default PDF paper size
$paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.)
// Check for paper size and page orientation // Check for paper size and page orientation
if (is_null($this->getSheetIndex())) { if (is_null($this->getSheetIndex())) {
$orientation = ($this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $orientation = ($this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation()
== PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
? 'L'
: 'P';
$printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize(); $printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize();
$printMargins = $this->_phpExcel->getSheet(0)->getPageMargins(); $printMargins = $this->_phpExcel->getSheet(0)->getPageMargins();
} else { } else {
$orientation = ($this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $orientation = ($this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation()
== PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
? 'L'
: 'P';
$printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); $printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
$printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins(); $printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins();
} }
// Override Page Orientation // Override Page Orientation
if (!is_null($this->getOrientation())) { if (!is_null($this->getOrientation())) {
$orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT) ? $orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT)
PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT : $this->getOrientation(); ? PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT
: $this->getOrientation();
} }
// Override Paper Size // Override Paper Size
if (!is_null($this->getPaperSize())) { if (!is_null($this->getPaperSize())) {
@ -110,7 +105,7 @@ class PHPExcel_Writer_PDF_DomPDF extends PHPExcel_Writer_PDF_Core implements PHP
$pdf->set_paper(strtolower($paperSize), $orientation); $pdf->set_paper(strtolower($paperSize), $orientation);
$pdf->load_html( $pdf->load_html(
$this->generateHTMLHeader(false) . $this->generateHTMLHeader(FALSE) .
$this->generateSheetData() . $this->generateSheetData() .
$this->generateHTMLFooter() $this->generateHTMLFooter()
); );

View File

@ -41,13 +41,15 @@ if (file_exists($pdfRendererClassFile)) {
* @package PHPExcel_Writer * @package PHPExcel_Writer
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Writer_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter { class PHPExcel_Writer_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter
{
/** /**
* Create a new PHPExcel_Writer_PDF * Create a new PHPExcel_Writer_PDF
* *
* @param PHPExcel $phpExcel PHPExcel object * @param PHPExcel $phpExcel PHPExcel object
*/ */
public function __construct(PHPExcel $phpExcel) { public function __construct(PHPExcel $phpExcel)
{
parent::__construct($phpExcel); parent::__construct($phpExcel);
} }
@ -55,36 +57,28 @@ class PHPExcel_Writer_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPEx
* Save PHPExcel to file * Save PHPExcel to file
* *
* @param string $pFileName * @param string $pFileName
* @throws PHPExcel_Reader_Exception * @throws PHPExcel_Writer_Exception
*/ */
public function save($pFilename = null) { public function save($pFilename = NULL)
// garbage collect {
$this->_phpExcel->garbageCollect(); $fileHandle = parent::prepareForSave($pFilename);
$saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType();
PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE);
// Open file
$fileHandle = fopen($pFilename, 'w');
if ($fileHandle === false) {
throw new PHPExcel_Reader_Exception("Could not open file $pFilename for writing.");
}
// Set PDF
$this->_isPdf = true;
// Build CSS
$this->buildCSS(true);
// Default PDF paper size // Default PDF paper size
$paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.)
// Check for paper size and page orientation // Check for paper size and page orientation
if (is_null($this->getSheetIndex())) { if (is_null($this->getSheetIndex())) {
$orientation = ($this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $orientation = ($this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation()
== PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
? 'L'
: 'P';
$printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize(); $printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize();
$printMargins = $this->_phpExcel->getSheet(0)->getPageMargins(); $printMargins = $this->_phpExcel->getSheet(0)->getPageMargins();
} else { } else {
$orientation = ($this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $orientation = ($this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation()
== PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
? 'L'
: 'P';
$printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); $printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
$printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins(); $printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins();
} }
@ -92,8 +86,9 @@ class PHPExcel_Writer_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPEx
// Override Page Orientation // Override Page Orientation
if (!is_null($this->getOrientation())) { if (!is_null($this->getOrientation())) {
$orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT) ? $orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT)
PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT : $this->getOrientation(); ? PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT
: $this->getOrientation();
} }
$orientation = strtoupper($orientation); $orientation = strtoupper($orientation);
@ -121,13 +116,13 @@ class PHPExcel_Writer_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPEx
$pdf->SetCreator($this->_phpExcel->getProperties()->getCreator()); $pdf->SetCreator($this->_phpExcel->getProperties()->getCreator());
$pdf->WriteHTML( $pdf->WriteHTML(
$this->generateHTMLHeader(false) . $this->generateHTMLHeader(FALSE) .
$this->generateSheetData() . $this->generateSheetData() .
$this->generateHTMLFooter() $this->generateHTMLFooter()
); );
// Write to file // Write to file
fwrite($fileHandle, $pdf->Output('','S')); fwrite($fileHandle, $pdf->Output('', 'S'));
// Close file // Close file
fclose($fileHandle); fclose($fileHandle);

View File

@ -42,13 +42,15 @@ if (file_exists($pdfRendererClassFile)) {
* @package PHPExcel_Writer * @package PHPExcel_Writer
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Writer_PDF_tcPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter { class PHPExcel_Writer_PDF_tcPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter
{
/** /**
* Create a new PHPExcel_Writer_PDF * Create a new PHPExcel_Writer_PDF
* *
* @param PHPExcel $phpExcel PHPExcel object * @param PHPExcel $phpExcel PHPExcel object
*/ */
public function __construct(PHPExcel $phpExcel) { public function __construct(PHPExcel $phpExcel)
{
parent::__construct($phpExcel); parent::__construct($phpExcel);
} }
@ -56,51 +58,43 @@ class PHPExcel_Writer_PDF_tcPDF extends PHPExcel_Writer_PDF_Core implements PHPE
* Save PHPExcel to file * Save PHPExcel to file
* *
* @param string $pFileName * @param string $pFileName
* @throws PHPExcel_Reader_Exception * @throws PHPExcel_Writer_Exception
*/ */
public function save($pFilename = null) { public function save($pFilename = NULL)
// garbage collect {
$this->_phpExcel->garbageCollect(); $fileHandle = parent::prepareForSave($pFilename);
$saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType();
PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE);
// Open file
$fileHandle = fopen($pFilename, 'w');
if ($fileHandle === false) {
throw new PHPExcel_Reader_Exception("Could not open file $pFilename for writing.");
}
// Set PDF
$this->_isPdf = true;
// Build CSS
$this->buildCSS(true);
// Default PDF paper size // Default PDF paper size
$paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.)
// Check for paper size and page orientation // Check for paper size and page orientation
if (is_null($this->getSheetIndex())) { if (is_null($this->getSheetIndex())) {
$orientation = ($this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $orientation = ($this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation()
== PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
? 'L'
: 'P';
$printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize(); $printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize();
$printMargins = $this->_phpExcel->getSheet(0)->getPageMargins(); $printMargins = $this->_phpExcel->getSheet(0)->getPageMargins();
} else { } else {
$orientation = ($this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $orientation = ($this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation()
== PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
? 'L'
: 'P';
$printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); $printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
$printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins(); $printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins();
} }
// Override Page Orientation // Override Page Orientation
if (!is_null($this->getOrientation())) { if (!is_null($this->getOrientation())) {
$orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? $orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
'L' : 'P'; ? 'L'
: 'P';
} }
// Override Paper Size // Override Paper Size
if (!is_null($this->getPaperSize())) { if (!is_null($this->getPaperSize())) {
$printPaperSize = $this->getPaperSize(); $printPaperSize = $this->getPaperSize();
} }
if (isset(self::$_paperSizes[$printPaperSize])) { if (isset(self::$_paperSizes[$printPaperSize])) {
$paperSize = self::$_paperSizes[$printPaperSize]; $paperSize = self::$_paperSizes[$printPaperSize];
} }
@ -108,22 +102,20 @@ class PHPExcel_Writer_PDF_tcPDF extends PHPExcel_Writer_PDF_Core implements PHPE
// Create PDF // Create PDF
$pdf = new TCPDF($orientation, 'pt', $paperSize); $pdf = new TCPDF($orientation, 'pt', $paperSize);
$pdf->setFontSubsetting(false); $pdf->setFontSubsetting(FALSE);
// Set margins, converting inches to points (using 72 dpi) // Set margins, converting inches to points (using 72 dpi)
$pdf->SetMargins($printMargins->getLeft() * 72,$printMargins->getTop() * 72,$printMargins->getRight() * 72); $pdf->SetMargins($printMargins->getLeft() * 72, $printMargins->getTop() * 72, $printMargins->getRight() * 72);
$pdf->SetAutoPageBreak(true,$printMargins->getBottom() * 72); $pdf->SetAutoPageBreak(TRUE, $printMargins->getBottom() * 72);
// $pdf->setHeaderMargin($printMargins->getHeader() * 72);
// $pdf->setFooterMargin($printMargins->getFooter() * 72);
$pdf->setPrintHeader(false); $pdf->setPrintHeader(FALSE);
$pdf->setPrintFooter(false); $pdf->setPrintFooter(FALSE);
$pdf->AddPage(); $pdf->AddPage();
// Set the appropriate font // Set the appropriate font
$pdf->SetFont($this->getFont()); $pdf->SetFont($this->getFont());
$pdf->writeHTML( $pdf->writeHTML(
$this->generateHTMLHeader(false) . $this->generateHTMLHeader(FALSE) .
$this->generateSheetData() . $this->generateSheetData() .
$this->generateHTMLFooter() $this->generateHTMLFooter()
); );