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
|
2016-07-31 12:35:06 +04:00
|
|
|
* @copyright 2010-2016 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-15 14:41:08 +07:00
|
|
|
use PhpOffice\PhpWord\Writer\WriterInterface;
|
2014-04-13 23:17:39 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* DomPDF writer
|
2014-05-19 17:39:31 +07:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/dompdf/dompdf
|
|
|
|
|
* @since 0.10.0
|
2014-04-13 23:17:39 +07:00
|
|
|
*/
|
2014-05-15 14:41:08 +07:00
|
|
|
class DomPDF extends AbstractRenderer implements WriterInterface
|
2014-04-13 23:17:39 +07:00
|
|
|
{
|
|
|
|
|
/**
|
2014-05-19 17:39:31 +07:00
|
|
|
* Name of renderer include file
|
2014-04-13 23:17:39 +07:00
|
|
|
*
|
2014-05-19 17:39:31 +07:00
|
|
|
* @var string
|
2014-04-13 23:17:39 +07:00
|
|
|
*/
|
2014-05-19 17:39:31 +07:00
|
|
|
protected $includeFile = 'dompdf_config.inc.php';
|
2014-04-13 23:17:39 +07:00
|
|
|
|
|
|
|
|
/**
|
2014-07-03 15:40:24 +04:00
|
|
|
* Save PhpWord to file.
|
2014-04-13 23:17:39 +07:00
|
|
|
*
|
2014-05-15 14:41:08 +07:00
|
|
|
* @param string $filename Name of the file to save as
|
2014-07-03 15:40:24 +04:00
|
|
|
* @return void
|
2014-04-13 23:17:39 +07:00
|
|
|
*/
|
2014-05-15 14:41:08 +07:00
|
|
|
public function save($filename = null)
|
2014-04-13 23:17:39 +07:00
|
|
|
{
|
2014-05-15 14:41:08 +07:00
|
|
|
$fileHandle = parent::prepareForSave($filename);
|
2014-04-13 23:17:39 +07:00
|
|
|
|
2014-05-19 17:39:31 +07:00
|
|
|
// PDF settings
|
2014-04-13 23:17:39 +07:00
|
|
|
$paperSize = 'A4';
|
2014-05-19 17:39:31 +07:00
|
|
|
$orientation = 'portrait';
|
2014-04-13 23:17:39 +07:00
|
|
|
|
|
|
|
|
// Create PDF
|
|
|
|
|
$pdf = new \DOMPDF();
|
|
|
|
|
$pdf->set_paper(strtolower($paperSize), $orientation);
|
2014-05-25 22:51:14 +07:00
|
|
|
$pdf->load_html($this->getContent());
|
2014-04-13 23:17:39 +07:00
|
|
|
$pdf->render();
|
|
|
|
|
|
|
|
|
|
// Write to file
|
|
|
|
|
fwrite($fileHandle, $pdf->output());
|
|
|
|
|
|
|
|
|
|
parent::restoreStateAfterSave($fileHandle);
|
|
|
|
|
}
|
|
|
|
|
}
|