ODT Writer: Enable title element and custom document properties
This commit is contained in:
parent
0360f8e290
commit
930d8de462
13
CHANGELOG.md
13
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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 | ✓ | ✓ | |
|
||||
+---------------------------+----------------------+--------+-------+-------+
|
||||
|
|
|
|||
|
|
@ -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 | ✓ | ✓ | |
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue