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-05-04 21:03:28 +04:00
|
|
|
use PhpOffice\PhpWord\Exception\Exception;
|
2014-04-13 23:17:39 +07:00
|
|
|
use PhpOffice\PhpWord\PhpWord;
|
|
|
|
|
use PhpOffice\PhpWord\Settings;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* DomPDF writer
|
|
|
|
|
*/
|
2014-04-14 10:07:35 +07:00
|
|
|
class DomPDF extends AbstractRenderer implements \PhpOffice\PhpWord\Writer\WriterInterface
|
2014-04-13 23:17:39 +07:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Create new instance
|
|
|
|
|
*
|
|
|
|
|
* @param PhpWord $phpWord PhpWord object
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(PhpWord $phpWord)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct($phpWord);
|
2014-04-16 07:12:57 +07:00
|
|
|
$configFile = Settings::getPdfRendererPath() . '/dompdf_config.inc.php';
|
|
|
|
|
if (file_exists($configFile)) {
|
|
|
|
|
require_once $configFile;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception('Unable to load PDF Rendering library');
|
|
|
|
|
}
|
2014-04-13 23:17:39 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Save PhpWord to file
|
|
|
|
|
*
|
|
|
|
|
* @param string $pFilename Name of the file to save as
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function save($pFilename = null)
|
|
|
|
|
{
|
|
|
|
|
$fileHandle = parent::prepareForSave($pFilename);
|
|
|
|
|
|
|
|
|
|
// Default PDF paper size
|
|
|
|
|
$paperSize = 'A4';
|
|
|
|
|
$orientation = 'P';
|
|
|
|
|
$printPaperSize = 9;
|
|
|
|
|
|
|
|
|
|
if (isset(self::$paperSizes[$printPaperSize])) {
|
|
|
|
|
$paperSize = self::$paperSizes[$printPaperSize];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$orientation = ($orientation == 'L') ? 'landscape' : 'portrait';
|
|
|
|
|
|
|
|
|
|
// Create PDF
|
|
|
|
|
$pdf = new \DOMPDF();
|
|
|
|
|
$pdf->set_paper(strtolower($paperSize), $orientation);
|
|
|
|
|
|
|
|
|
|
$pdf->load_html($this->writeDocument());
|
|
|
|
|
$pdf->render();
|
|
|
|
|
|
|
|
|
|
// Write to file
|
|
|
|
|
fwrite($fileHandle, $pdf->output());
|
|
|
|
|
|
|
|
|
|
parent::restoreStateAfterSave($fileHandle);
|
|
|
|
|
}
|
|
|
|
|
}
|