diff --git a/CHANGELOG.md b/CHANGELOG.md index cb408f43..af9754cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,15 +15,16 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3; new r - HTML: Ability to add elements to PHPWord object via html - @basjan GH-231 - ListItemRun: New element that can add a list item with inline formatting like a textrun - @basjan GH-235 - Table: Ability to add table inside a cell (nested table) - @ivanlanin GH-149 -- RTF: UTF8 support for RTF: Internal UTF8 text is converted to Unicode before writing - @ivanlanin GH-158 +- RTF Writer: UTF8 support for RTF: Internal UTF8 text is converted to Unicode before writing - @ivanlanin GH-158 - Table: Ability to define table width (in percent and twip) and position - @ivanlanin GH-237 -- RTF: Ability to add links and page breaks in RTF - @ivanlanin GH-196 +- RTF Writer: Ability to add links and page breaks in RTF - @ivanlanin GH-196 - ListItemRun: Remove fontStyle parameter because ListItemRun is inherited from TextRun and TextRun doesn't have fontStyle - @ivanlanin - Config: Ability to use a config file to store various common settings - @ivanlanin GH-200 -- ODT: Enable inline font style in TextRun - @ivanlanin -- ODT: Enable underline, strike/doublestrike, smallcaps/allcaps, superscript/subscript font style - @ivanlanin -- ODT: Enable section and column - @ivanlanin -- PDF: Add TCPDF and mPDF as optional PDF renderer library - @ivanlanin +- ODT Writer: Enable inline font style in TextRun - @ivanlanin +- ODT Writer: Enable underline, strike/doublestrike, smallcaps/allcaps, superscript/subscript font style - @ivanlanin +- ODT Writer: Enable section and column - @ivanlanin +- PDF Writer: Add TCPDF and mPDF as optional PDF renderer library - @ivanlanin +- ODT Writer: Enable title element and custom document properties - @ivanlanin ### Bugfixes diff --git a/docs/intro.rst b/docs/intro.rst index 0b0c1dfe..3c6277f5 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -61,17 +61,15 @@ Writers +---------------------------+----------------------+--------+-------+-------+--------+-------+ | Features | | DOCX | ODT | RTF | HTML | PDF | +===========================+======================+========+=======+=======+========+=======+ -| **Document Properties** | Standard | ✓ | | | | | +| **Document Properties** | Standard | ✓ | ✓ | | | | +---------------------------+----------------------+--------+-------+-------+--------+-------+ -| | Extended | ✓ | | | | | -+---------------------------+----------------------+--------+-------+-------+--------+-------+ -| | UserDefined | ✓ | | | | | +| | Custom | ✓ | ✓ | | | | +---------------------------+----------------------+--------+-------+-------+--------+-------+ | **Element Type** | Text | ✓ | ✓ | ✓ | ✓ | ✓ | +---------------------------+----------------------+--------+-------+-------+--------+-------+ | | Text Run | ✓ | ✓ | ✓ | ✓ | ✓ | +---------------------------+----------------------+--------+-------+-------+--------+-------+ -| | Title | ✓ | | | ✓ | ✓ | +| | Title | ✓ | ✓ | | ✓ | ✓ | +---------------------------+----------------------+--------+-------+-------+--------+-------+ | | Link | ✓ | ✓ | ✓ | ✓ | ✓ | +---------------------------+----------------------+--------+-------+-------+--------+-------+ @@ -124,9 +122,7 @@ Readers +===========================+======================+========+=======+=======+ | **Document Properties** | Standard | ✓ | | | +---------------------------+----------------------+--------+-------+-------+ -| | Extended | ✓ | | | -+---------------------------+----------------------+--------+-------+-------+ -| | UserDefined | ✓ | | | +| | Custom | ✓ | | | +---------------------------+----------------------+--------+-------+-------+ | **Element Type** | Text | ✓ | ✓ | | +---------------------------+----------------------+--------+-------+-------+ diff --git a/docs/src/documentation.md b/docs/src/documentation.md index 5b969687..ffa3edc3 100644 --- a/docs/src/documentation.md +++ b/docs/src/documentation.md @@ -78,12 +78,11 @@ Below are the supported features for each file formats. | Features | | DOCX | ODT | RTF | HTML | PDF | |-------------------------|--------------------|------|-----|-----|------|-----| -| **Document Properties** | Standard | ✓ | | | | | -| | Extended | ✓ | | | | | -| | UserDefined | ✓ | | | | | +| **Document Properties** | Standard | ✓ | ✓ | | | | +| | Custom | ✓ | ✓ | | | | | **Element Type** | Text | ✓ | ✓ | ✓ | ✓ | ✓ | | | Text Run | ✓ | ✓ | ✓ | ✓ | ✓ | -| | Title | ✓ | | | ✓ | ✓ | +| | Title | ✓ | ✓ | | ✓ | ✓ | | | Link | ✓ | ✓ | ✓ | ✓ | ✓ | | | Preserve Text | ✓ | | | | | | | Text Break | ✓ | ✓ | ✓ | ✓ | ✓ | @@ -111,8 +110,7 @@ Below are the supported features for each file formats. | Features | | DOCX | ODT | RTF | |-------------------------|--------------------|------|-----|-----| | **Document Properties** | Standard | ✓ | | | -| | Extended | ✓ | | | -| | UserDefined | ✓ | | | +| | Custom | ✓ | | | | **Element Type** | Text | ✓ | ✓ | | | | Text Run | ✓ | | | | | Title | ✓ | ✓ | | diff --git a/samples/resources/Sample_11_ReadWord2007.docx b/samples/resources/Sample_11_ReadWord2007.docx index a457c7a6..c9a50f48 100644 Binary files a/samples/resources/Sample_11_ReadWord2007.docx and b/samples/resources/Sample_11_ReadWord2007.docx differ diff --git a/samples/resources/Sample_24_ReadODText.odt b/samples/resources/Sample_24_ReadODText.odt index 9e18e619..a8e1b7a2 100644 Binary files a/samples/resources/Sample_24_ReadODText.odt and b/samples/resources/Sample_24_ReadODText.odt differ diff --git a/src/PhpWord/Writer/ODText/Element/Title.php b/src/PhpWord/Writer/ODText/Element/Title.php index 9d062a7f..d45f5e12 100644 --- a/src/PhpWord/Writer/ODText/Element/Title.php +++ b/src/PhpWord/Writer/ODText/Element/Title.php @@ -35,8 +35,9 @@ class Title extends AbstractElement return; } - $xmlWriter->startElement('text:p'); + $xmlWriter->startElement('text:h'); + $xmlWriter->writeAttribute('text:outline-level', $element->getDepth()); $xmlWriter->writeRaw($element->getText()); - $xmlWriter->endElement(); // text:p + $xmlWriter->endElement(); // text:h } } diff --git a/src/PhpWord/Writer/ODText/Part/Meta.php b/src/PhpWord/Writer/ODText/Part/Meta.php index 0d2a761a..8c6ad3a9 100644 --- a/src/PhpWord/Writer/ODText/Part/Meta.php +++ b/src/PhpWord/Writer/ODText/Part/Meta.php @@ -17,6 +17,8 @@ namespace PhpOffice\PhpWord\Writer\ODText\Part; +use PhpOffice\PhpWord\Shared\XMLWriter; + /** * ODText meta part writer: meta.xml */ @@ -42,27 +44,56 @@ class Meta extends AbstractPart $xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); $xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); $xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); - - // office:meta $xmlWriter->startElement('office:meta'); + + // Core properties $xmlWriter->writeElement('dc:creator', $docProps->getLastModifiedBy()); $xmlWriter->writeElement('dc:date', gmdate('Y-m-d\TH:i:s.000', $docProps->getModified())); $xmlWriter->writeElement('dc:description', $docProps->getDescription()); $xmlWriter->writeElement('dc:subject', $docProps->getSubject()); $xmlWriter->writeElement('dc:title', $docProps->getTitle()); + + // Extended properties + $xmlWriter->writeElement('meta:generator', 'PHPWord'); $xmlWriter->writeElement('meta:creation-date', gmdate('Y-m-d\TH:i:s.000', $docProps->getCreated())); $xmlWriter->writeElement('meta:initial-creator', $docProps->getCreator()); $xmlWriter->writeElement('meta:keyword', $docProps->getKeywords()); - // @todo : Where these properties are written ? - // $docProps->getCategory() - // $docProps->getCompany() + // Category, company, and manager should be put in meta namespace + $properties = array('Category', 'Company', 'Manager'); + foreach ($properties as $property) { + $method = "get{$property}"; + if ($docProps->$method() !== null) { + $this->writeCustomProperty($xmlWriter, $property, $docProps->$method()); + } + } - $xmlWriter->endElement(); + // Other custom properties + // @todo Check type. Currently all assumed as string + foreach ($docProps->getCustomProperties() as $property) { + $value = $docProps->getCustomPropertyValue($property); + $this->writeCustomProperty($xmlWriter, $property, $value); + } - $xmlWriter->endElement(); + $xmlWriter->endElement(); // office:meta + $xmlWriter->endElement(); // office:document-meta - // Return return $xmlWriter->getData(); } + + /** + * Write individual property + * + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param string $property + * @param string $value + * @param string $type + */ + private function writeCustomProperty(XMLWriter $xmlWriter, $property, $value, $type = null) + { + $xmlWriter->startElement('meta:user-defined'); + $xmlWriter->writeAttribute('meta:name', $property); + $xmlWriter->writeRaw($value); + $xmlWriter->endElement(); // meta:user-defined + } }