2014-04-12 10:12:24 +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-12 10:12:24 +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-12 10:12:24 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Writer;
|
|
|
|
|
|
2014-05-04 21:03:28 +04:00
|
|
|
use PhpOffice\PhpWord\PhpWord;
|
2014-04-12 10:12:24 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* HTML writer
|
|
|
|
|
*
|
2014-04-24 14:58:15 +07:00
|
|
|
* Not supported: PreserveText, PageBreak, Object
|
2014-04-12 10:12:24 +07:00
|
|
|
* @since 0.10.0
|
|
|
|
|
*/
|
|
|
|
|
class HTML extends AbstractWriter implements WriterInterface
|
|
|
|
|
{
|
2014-04-16 12:12:32 +07:00
|
|
|
/**
|
|
|
|
|
* Is the current writer creating PDF?
|
|
|
|
|
*
|
|
|
|
|
* @var boolean
|
|
|
|
|
*/
|
|
|
|
|
protected $isPdf = false;
|
|
|
|
|
|
2014-04-16 17:17:42 +07:00
|
|
|
/**
|
|
|
|
|
* Footnotes and endnotes collection
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $notes = array();
|
|
|
|
|
|
2014-04-12 10:12:24 +07:00
|
|
|
/**
|
|
|
|
|
* Create new instance
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(PhpWord $phpWord = null)
|
|
|
|
|
{
|
|
|
|
|
$this->setPhpWord($phpWord);
|
2014-05-23 12:48:34 +07:00
|
|
|
|
|
|
|
|
$this->parts = array('Head', 'Body');
|
|
|
|
|
foreach ($this->parts as $partName) {
|
|
|
|
|
$partClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Part\\' . $partName;
|
|
|
|
|
if (class_exists($partClass)) {
|
|
|
|
|
/** @var \PhpOffice\PhpWord\Writer\HTML\Part\AbstractPart $part Type hint */
|
|
|
|
|
$part = new $partClass();
|
|
|
|
|
$part->setParentWriter($this);
|
|
|
|
|
$this->writerParts[strtolower($partName)] = $part;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-12 10:12:24 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Save PhpWord to file
|
|
|
|
|
*
|
|
|
|
|
* @param string $filename
|
2014-05-15 14:41:08 +07:00
|
|
|
* @throws \PhpOffice\PhpWord\Exception\Exception
|
2014-04-12 10:12:24 +07:00
|
|
|
*/
|
|
|
|
|
public function save($filename = null)
|
|
|
|
|
{
|
2014-05-25 22:51:14 +07:00
|
|
|
$fileHandle = $this->openFile($filename);
|
|
|
|
|
$this->writeFile($fileHandle, $this->getContent());
|
2014-04-12 10:12:24 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-25 22:51:14 +07:00
|
|
|
* Get content
|
2014-04-12 10:12:24 +07:00
|
|
|
*
|
|
|
|
|
* @return string
|
2014-05-25 22:51:14 +07:00
|
|
|
* @since 0.11.0
|
2014-04-12 10:12:24 +07:00
|
|
|
*/
|
2014-05-25 22:51:14 +07:00
|
|
|
public function getContent()
|
2014-04-12 10:12:24 +07:00
|
|
|
{
|
2014-05-09 14:57:06 +07:00
|
|
|
$content = '';
|
2014-05-25 22:51:14 +07:00
|
|
|
|
2014-05-09 14:57:06 +07:00
|
|
|
$content .= '<!DOCTYPE html>' . PHP_EOL;
|
|
|
|
|
$content .= '<!-- Generated by PHPWord -->' . PHP_EOL;
|
|
|
|
|
$content .= '<html>' . PHP_EOL;
|
2014-05-23 12:48:34 +07:00
|
|
|
$content .= $this->getWriterPart('Head')->write();
|
|
|
|
|
$content .= $this->getWriterPart('Body')->write();
|
2014-05-09 14:57:06 +07:00
|
|
|
$content .= '</html>' . PHP_EOL;
|
2014-04-12 10:12:24 +07:00
|
|
|
|
2014-05-09 14:57:06 +07:00
|
|
|
return $content;
|
2014-04-12 10:12:24 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-24 14:58:15 +07:00
|
|
|
* Get is PDF
|
2014-04-12 10:12:24 +07:00
|
|
|
*
|
2014-04-24 14:58:15 +07:00
|
|
|
* @return bool
|
2014-04-12 10:12:24 +07:00
|
|
|
*/
|
2014-04-24 14:58:15 +07:00
|
|
|
public function isPdf()
|
2014-04-12 10:12:24 +07:00
|
|
|
{
|
2014-04-24 14:58:15 +07:00
|
|
|
return $this->isPdf;
|
2014-04-12 10:12:24 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-24 14:58:15 +07:00
|
|
|
* Get notes
|
2014-04-12 10:12:24 +07:00
|
|
|
*
|
2014-04-24 14:58:15 +07:00
|
|
|
* @return array
|
2014-04-12 10:12:24 +07:00
|
|
|
*/
|
2014-04-24 14:58:15 +07:00
|
|
|
public function getNotes()
|
2014-04-12 10:12:24 +07:00
|
|
|
{
|
2014-04-24 14:58:15 +07:00
|
|
|
return $this->notes;
|
2014-04-12 10:12:24 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-24 14:58:15 +07:00
|
|
|
* Add note
|
2014-04-12 10:12:24 +07:00
|
|
|
*
|
2014-04-24 14:58:15 +07:00
|
|
|
* @param int $noteId
|
|
|
|
|
* @param string $noteMark
|
2014-04-16 12:12:32 +07:00
|
|
|
*/
|
2014-04-24 14:58:15 +07:00
|
|
|
public function addNote($noteId, $noteMark)
|
2014-04-16 12:12:32 +07:00
|
|
|
{
|
2014-04-24 14:58:15 +07:00
|
|
|
$this->notes[$noteId] = $noteMark;
|
2014-04-16 12:12:32 +07:00
|
|
|
}
|
2014-05-25 22:51:14 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Write document
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
* @deprecated 0.11.0
|
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
|
*/
|
|
|
|
|
public function writeDocument()
|
|
|
|
|
{
|
|
|
|
|
return $this->getContent();
|
|
|
|
|
}
|
2014-04-12 10:12:24 +07:00
|
|
|
}
|