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
|
- 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
|
- 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
|
- 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
|
- 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
|
- 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
|
- Config: Ability to use a config file to store various common settings - @ivanlanin GH-200
|
||||||
- ODT: Enable inline font style in TextRun - @ivanlanin
|
- ODT Writer: Enable inline font style in TextRun - @ivanlanin
|
||||||
- ODT: Enable underline, strike/doublestrike, smallcaps/allcaps, superscript/subscript font style - @ivanlanin
|
- ODT Writer: Enable underline, strike/doublestrike, smallcaps/allcaps, superscript/subscript font style - @ivanlanin
|
||||||
- ODT: Enable section and column - @ivanlanin
|
- ODT Writer: Enable section and column - @ivanlanin
|
||||||
- PDF: Add TCPDF and mPDF as optional PDF renderer library - @ivanlanin
|
- PDF Writer: Add TCPDF and mPDF as optional PDF renderer library - @ivanlanin
|
||||||
|
- ODT Writer: Enable title element and custom document properties - @ivanlanin
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,17 +61,15 @@ Writers
|
||||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||||
| Features | | DOCX | ODT | RTF | HTML | PDF |
|
| Features | | DOCX | ODT | RTF | HTML | PDF |
|
||||||
+===========================+======================+========+=======+=======+========+=======+
|
+===========================+======================+========+=======+=======+========+=======+
|
||||||
| **Document Properties** | Standard | ✓ | | | | |
|
| **Document Properties** | Standard | ✓ | ✓ | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||||
| | Extended | ✓ | | | | |
|
| | Custom | ✓ | ✓ | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
|
||||||
| | UserDefined | ✓ | | | | |
|
|
||||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||||
| **Element Type** | Text | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| **Element Type** | Text | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||||
| | Text Run | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| | Text Run | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||||
| | Title | ✓ | | | ✓ | ✓ |
|
| | Title | ✓ | ✓ | | ✓ | ✓ |
|
||||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||||
| | Link | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| | Link | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||||
|
|
@ -124,9 +122,7 @@ Readers
|
||||||
+===========================+======================+========+=======+=======+
|
+===========================+======================+========+=======+=======+
|
||||||
| **Document Properties** | Standard | ✓ | | |
|
| **Document Properties** | Standard | ✓ | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+
|
||||||
| | Extended | ✓ | | |
|
| | Custom | ✓ | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+
|
|
||||||
| | UserDefined | ✓ | | |
|
|
||||||
+---------------------------+----------------------+--------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+
|
||||||
| **Element Type** | Text | ✓ | ✓ | |
|
| **Element Type** | Text | ✓ | ✓ | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+
|
||||||
|
|
|
||||||
|
|
@ -78,12 +78,11 @@ Below are the supported features for each file formats.
|
||||||
|
|
||||||
| Features | | DOCX | ODT | RTF | HTML | PDF |
|
| Features | | DOCX | ODT | RTF | HTML | PDF |
|
||||||
|-------------------------|--------------------|------|-----|-----|------|-----|
|
|-------------------------|--------------------|------|-----|-----|------|-----|
|
||||||
| **Document Properties** | Standard | ✓ | | | | |
|
| **Document Properties** | Standard | ✓ | ✓ | | | |
|
||||||
| | Extended | ✓ | | | | |
|
| | Custom | ✓ | ✓ | | | |
|
||||||
| | UserDefined | ✓ | | | | |
|
|
||||||
| **Element Type** | Text | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| **Element Type** | Text | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
| | Text Run | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| | Text Run | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
| | Title | ✓ | | | ✓ | ✓ |
|
| | Title | ✓ | ✓ | | ✓ | ✓ |
|
||||||
| | Link | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| | Link | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
| | Preserve Text | ✓ | | | | |
|
| | Preserve Text | ✓ | | | | |
|
||||||
| | Text Break | ✓ | ✓ | ✓ | ✓ | ✓ |
|
| | Text Break | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
|
|
@ -111,8 +110,7 @@ Below are the supported features for each file formats.
|
||||||
| Features | | DOCX | ODT | RTF |
|
| Features | | DOCX | ODT | RTF |
|
||||||
|-------------------------|--------------------|------|-----|-----|
|
|-------------------------|--------------------|------|-----|-----|
|
||||||
| **Document Properties** | Standard | ✓ | | |
|
| **Document Properties** | Standard | ✓ | | |
|
||||||
| | Extended | ✓ | | |
|
| | Custom | ✓ | | |
|
||||||
| | UserDefined | ✓ | | |
|
|
||||||
| **Element Type** | Text | ✓ | ✓ | |
|
| **Element Type** | Text | ✓ | ✓ | |
|
||||||
| | Text Run | ✓ | | |
|
| | Text Run | ✓ | | |
|
||||||
| | Title | ✓ | ✓ | |
|
| | Title | ✓ | ✓ | |
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -35,8 +35,9 @@ class Title extends AbstractElement
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$xmlWriter->startElement('text:p');
|
$xmlWriter->startElement('text:h');
|
||||||
|
$xmlWriter->writeAttribute('text:outline-level', $element->getDepth());
|
||||||
$xmlWriter->writeRaw($element->getText());
|
$xmlWriter->writeRaw($element->getText());
|
||||||
$xmlWriter->endElement(); // text:p
|
$xmlWriter->endElement(); // text:h
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer\ODText\Part;
|
namespace PhpOffice\PhpWord\Writer\ODText\Part;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ODText meta part writer: meta.xml
|
* 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:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
|
||||||
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
|
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
|
||||||
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
|
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
|
||||||
|
|
||||||
// office:meta
|
|
||||||
$xmlWriter->startElement('office:meta');
|
$xmlWriter->startElement('office:meta');
|
||||||
|
|
||||||
|
// Core properties
|
||||||
$xmlWriter->writeElement('dc:creator', $docProps->getLastModifiedBy());
|
$xmlWriter->writeElement('dc:creator', $docProps->getLastModifiedBy());
|
||||||
$xmlWriter->writeElement('dc:date', gmdate('Y-m-d\TH:i:s.000', $docProps->getModified()));
|
$xmlWriter->writeElement('dc:date', gmdate('Y-m-d\TH:i:s.000', $docProps->getModified()));
|
||||||
$xmlWriter->writeElement('dc:description', $docProps->getDescription());
|
$xmlWriter->writeElement('dc:description', $docProps->getDescription());
|
||||||
$xmlWriter->writeElement('dc:subject', $docProps->getSubject());
|
$xmlWriter->writeElement('dc:subject', $docProps->getSubject());
|
||||||
$xmlWriter->writeElement('dc:title', $docProps->getTitle());
|
$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:creation-date', gmdate('Y-m-d\TH:i:s.000', $docProps->getCreated()));
|
||||||
$xmlWriter->writeElement('meta:initial-creator', $docProps->getCreator());
|
$xmlWriter->writeElement('meta:initial-creator', $docProps->getCreator());
|
||||||
$xmlWriter->writeElement('meta:keyword', $docProps->getKeywords());
|
$xmlWriter->writeElement('meta:keyword', $docProps->getKeywords());
|
||||||
|
|
||||||
// @todo : Where these properties are written ?
|
// Category, company, and manager should be put in meta namespace
|
||||||
// $docProps->getCategory()
|
$properties = array('Category', 'Company', 'Manager');
|
||||||
// $docProps->getCompany()
|
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();
|
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