2014-04-13 23:17:39 +07:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-05-05 13:06:53 +04:00
|
|
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
|
|
|
|
* word processing documents.
|
|
|
|
|
*
|
|
|
|
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
|
|
|
|
* General Public License version 3 as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please read the LICENSE
|
|
|
|
|
* file that was distributed with this source code. For the full list of
|
|
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
2014-04-13 23:17:39 +07:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PhpWord
|
2014-05-05 12:38:31 +04:00
|
|
|
* @copyright 2010-2014 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2014-04-13 23:17:39 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Writer\PDF;
|
|
|
|
|
|
2014-04-14 10:07:35 +07:00
|
|
|
use PhpOffice\PhpWord\Exception\Exception;
|
2014-04-13 23:17:39 +07:00
|
|
|
use PhpOffice\PhpWord\PhpWord;
|
2014-05-15 14:41:08 +07:00
|
|
|
use PhpOffice\PhpWord\Writer\HTML;
|
2014-04-13 23:17:39 +07:00
|
|
|
|
|
|
|
|
/**
|
2014-04-14 10:07:35 +07:00
|
|
|
* Abstract PDF renderer
|
2014-04-13 23:17:39 +07:00
|
|
|
*/
|
2014-05-15 14:41:08 +07:00
|
|
|
abstract class AbstractRenderer extends HTML
|
2014-04-13 23:17:39 +07:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Temporary storage directory
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $tempDir = '';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Font
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $font;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Paper size
|
|
|
|
|
*
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
|
|
|
|
protected $paperSize = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Orientation
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $orientation = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Paper Sizes xRef List
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected static $paperSizes = array(
|
|
|
|
|
9 => 'A4', // (210 mm by 297 mm)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create new instance
|
|
|
|
|
*
|
|
|
|
|
* @param PhpWord $phpWord PhpWord object
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(PhpWord $phpWord)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct($phpWord);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Font
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getFont()
|
|
|
|
|
{
|
|
|
|
|
return $this->font;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set font. Examples:
|
|
|
|
|
* 'arialunicid0-chinese-simplified'
|
|
|
|
|
* 'arialunicid0-chinese-traditional'
|
|
|
|
|
* 'arialunicid0-korean'
|
|
|
|
|
* 'arialunicid0-japanese'
|
|
|
|
|
*
|
|
|
|
|
* @param string $fontName
|
2014-05-14 19:41:44 +07:00
|
|
|
* @return self
|
2014-04-13 23:17:39 +07:00
|
|
|
*/
|
|
|
|
|
public function setFont($fontName)
|
|
|
|
|
{
|
|
|
|
|
$this->font = $fontName;
|
2014-05-14 19:41:44 +07:00
|
|
|
|
2014-04-13 23:17:39 +07:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Paper Size
|
|
|
|
|
*
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function getPaperSize()
|
|
|
|
|
{
|
|
|
|
|
return $this->paperSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set Paper Size
|
|
|
|
|
*
|
2014-05-15 14:41:08 +07:00
|
|
|
* @param int $value Paper size = PAPERSIZE_A4
|
2014-04-13 23:17:39 +07:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2014-05-15 14:41:08 +07:00
|
|
|
public function setPaperSize($value = 9)
|
2014-04-13 23:17:39 +07:00
|
|
|
{
|
2014-05-15 14:41:08 +07:00
|
|
|
$this->paperSize = $value;
|
2014-04-13 23:17:39 +07:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Orientation
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getOrientation()
|
|
|
|
|
{
|
|
|
|
|
return $this->orientation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set Orientation
|
|
|
|
|
*
|
2014-05-15 14:41:08 +07:00
|
|
|
* @param string $value Page orientation ORIENTATION_DEFAULT
|
2014-04-13 23:17:39 +07:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2014-05-15 14:41:08 +07:00
|
|
|
public function setOrientation($value = 'default')
|
2014-04-13 23:17:39 +07:00
|
|
|
{
|
2014-05-15 14:41:08 +07:00
|
|
|
$this->orientation = $value;
|
2014-04-13 23:17:39 +07:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Save PhpWord to PDF file, pre-save
|
|
|
|
|
*
|
2014-05-15 14:41:08 +07:00
|
|
|
* @param string $filename Name of the file to save as
|
2014-04-16 12:12:32 +07:00
|
|
|
* @return resource
|
2014-05-14 19:41:44 +07:00
|
|
|
* @throws \PhpOffice\PhpWord\Exception\Exception
|
2014-04-13 23:17:39 +07:00
|
|
|
*/
|
2014-05-15 14:41:08 +07:00
|
|
|
protected function prepareForSave($filename = null)
|
2014-04-13 23:17:39 +07:00
|
|
|
{
|
2014-05-15 14:41:08 +07:00
|
|
|
$fileHandle = fopen($filename, 'w');
|
2014-04-13 23:17:39 +07:00
|
|
|
if ($fileHandle === false) {
|
2014-05-15 14:41:08 +07:00
|
|
|
throw new Exception("Could not open file $filename for writing.");
|
2014-04-13 23:17:39 +07:00
|
|
|
}
|
2014-04-16 12:12:32 +07:00
|
|
|
$this->isPdf = true;
|
|
|
|
|
|
2014-04-13 23:17:39 +07:00
|
|
|
return $fileHandle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Save PhpWord to PDF file, post-save
|
|
|
|
|
*
|
|
|
|
|
* @param resource $fileHandle
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
protected function restoreStateAfterSave($fileHandle)
|
|
|
|
|
{
|
|
|
|
|
fclose($fileHandle);
|
|
|
|
|
}
|
|
|
|
|
}
|