PHPWord/src/PhpWord/Writer/PDF/AbstractRenderer.php

175 lines
3.6 KiB
PHP

<?php
/**
* 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.
*
* @link https://github.com/PHPOffice/PhpWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Writer\PDF;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
/**
* Abstract PDF renderer
*/
abstract class AbstractRenderer extends \PhpOffice\PhpWord\Writer\HTML
{
/**
* 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
* @return self
*/
public function setFont($fontName)
{
$this->font = $fontName;
return $this;
}
/**
* Get Paper Size
*
* @return int
*/
public function getPaperSize()
{
return $this->paperSize;
}
/**
* Set Paper Size
*
* @param int $pValue Paper size = PAPERSIZE_A4
* @return self
*/
public function setPaperSize($pValue = 9)
{
$this->paperSize = $pValue;
return $this;
}
/**
* Get Orientation
*
* @return string
*/
public function getOrientation()
{
return $this->orientation;
}
/**
* Set Orientation
*
* @param string $pValue Page orientation ORIENTATION_DEFAULT
* @return self
*/
public function setOrientation($pValue = 'default')
{
$this->orientation = $pValue;
return $this;
}
/**
* Save PhpWord to PDF file, pre-save
*
* @param string $pFilename Name of the file to save as
* @return resource
* @throws \PhpOffice\PhpWord\Exception\Exception
*/
protected function prepareForSave($pFilename = null)
{
$fileHandle = fopen($pFilename, 'w');
if ($fileHandle === false) {
throw new Exception("Could not open file $pFilename for writing.");
}
$this->isPdf = true;
return $fileHandle;
}
/**
* Save PhpWord to PDF file, post-save
*
* @param resource $fileHandle
* @throws Exception
*/
protected function restoreStateAfterSave($fileHandle)
{
fclose($fileHandle);
}
}