public function writeHeaderFooterRels($_relsCollection) { require_once __DIR__ . '/../../Shared/XMLWriter.php'; // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_MEMORY); } // XML header $objWriter->startDocument('1.0', 'UTF-8', 'yes'); // Relationships $objWriter->startElement('Relationships'); $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); // Relationships to Images / Embeddings / Headers / Footers foreach ($_relsCollection as $relation) { $relationType = $relation['type']; $relationName = $relation['target']; $relationId = $relation['rID']; $this->_writeRelationship($objWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName); } $objWriter->endElement(); // Return return $objWriter->getData(); }
public function writeRelationships(Document_Word_Writer $pPHPWord = null) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_MEMORY); } // XML header $objWriter->startDocument('1.0', 'UTF-8', 'yes'); // Relationships $objWriter->startElement('Relationships'); $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); $relationId = 1; // Relationship word/document.xml $this->_writeRelationship($objWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument', 'word/document.xml'); // Relationship docProps/core.xml $this->_writeRelationship($objWriter, ++$relationId, 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties', 'docProps/core.xml'); // Relationship docProps/app.xml $this->_writeRelationship($objWriter, ++$relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties', 'docProps/app.xml'); $objWriter->endElement(); // Return return $objWriter->getData(); }
public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $_cFtrs) { require_once __DIR__ . '/../../Shared/XMLWriter.php'; // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_MEMORY); } // XML header $objWriter->startDocument('1.0', 'UTF-8', 'yes'); // Types $objWriter->startElement('Types'); $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types'); // Rels $this->_writeDefaultContentType($objWriter, 'rels', 'application/vnd.openxmlformats-package.relationships+xml'); // XML $this->_writeDefaultContentType($objWriter, 'xml', 'application/xml'); // Add media content-types foreach ($_imageTypes as $key => $value) { $this->_writeDefaultContentType($objWriter, $key, $value); } // Add embedding content-types if (count($_objectTypes) > 0) { $this->_writeDefaultContentType($objWriter, 'bin', 'application/vnd.openxmlformats-officedocument.oleObject'); } // DocProps $this->_writeOverrideContentType($objWriter, '/docProps/app.xml', 'application/vnd.openxmlformats-officedocument.extended-properties+xml'); $this->_writeOverrideContentType($objWriter, '/docProps/core.xml', 'application/vnd.openxmlformats-package.core-properties+xml'); // Document $this->_writeOverrideContentType($objWriter, '/word/document.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'); // Styles $this->_writeOverrideContentType($objWriter, '/word/styles.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml'); // Numbering $this->_writeOverrideContentType($objWriter, '/word/numbering.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml'); // Settings $this->_writeOverrideContentType($objWriter, '/word/settings.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml'); // Theme1 $this->_writeOverrideContentType($objWriter, '/word/theme/theme1.xml', 'application/vnd.openxmlformats-officedocument.theme+xml'); // WebSettings $this->_writeOverrideContentType($objWriter, '/word/webSettings.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml'); // Font Table $this->_writeOverrideContentType($objWriter, '/word/fontTable.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml'); for ($i = 1; $i <= $_cHdrs; $i++) { $this->_writeOverrideContentType($objWriter, '/word/header' . $i . '.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml'); } for ($i = 1; $i <= $_cFtrs; $i++) { $this->_writeOverrideContentType($objWriter, '/word/footer' . $i . '.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'); } $objWriter->endElement(); // Return return $objWriter->getData(); }
public function writeHeader(Document_Word_Writer_Section_Header $header) { require_once __DIR__ . '/../../Shared/XMLWriter.php'; // Create XML writer if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_MEMORY); } // XML header $objWriter->startDocument('1.0', 'UTF-8', 'yes'); $objWriter->startElement('w:hdr'); $objWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006'); $objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $objWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math'); $objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); $objWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'); $objWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word'); $objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $objWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml'); $_elements = $header->getElements(); foreach ($_elements as $element) { if ($element instanceof Document_Word_Writer_Section_Text) { $this->_writeText($objWriter, $element); } elseif ($element instanceof Document_Word_Writer_Section_TextRun) { $this->_writeTextRun($objWriter, $element); } elseif ($element instanceof Document_Word_Writer_Section_TextBreak) { $this->_writeTextBreak($objWriter); } elseif ($element instanceof Document_Word_Writer_Section_Table) { $this->_writeTable($objWriter, $element); } elseif ($element instanceof Document_Word_Writer_Section_Image || $element instanceof Document_Word_Writer_Section_MemoryImage) { if (!$element->getIsWatermark()) { $this->_writeImage($objWriter, $element); } else { $this->_writeWatermark($objWriter, $element); } } elseif ($element instanceof Document_Word_Writer_Section_Footer_PreserveText) { $this->_writePreserveText($objWriter, $element, true); } } $objWriter->endElement(); // Return return $objWriter->getData(); }
public function writeStyles(Document_Word_Writer $pPHPWord = null) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_MEMORY); } $this->_document = $pPHPWord; // XML header $objWriter->startDocument('1.0', 'UTF-8', 'yes'); $objWriter->startElement('w:styles'); $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); // Write DocDefaults $this->_writeDocDefaults($objWriter); // Write Style Definitions require_once __DIR__ . '/../../Style.php'; $styles = Document_Word_Writer_Style::getStyles(); if (count($styles) > 0) { foreach ($styles as $styleName => $style) { if ($style instanceof Document_Word_Writer_Style_Font) { $paragraphStyle = $style->getParagraphStyle(); $styleType = $style->getStyleType(); $type = $styleType == 'title' ? 'paragraph' : 'character'; if (!is_null($paragraphStyle)) { $type = 'paragraph'; } $objWriter->startElement('w:style'); $objWriter->writeAttribute('w:type', $type); if ($styleType == 'title') { $arrStyle = explode('_', $styleName); $styleId = 'Heading' . $arrStyle[1]; $styleName = 'heading ' . $arrStyle[1]; $styleLink = 'Heading' . $arrStyle[1] . 'Char'; $objWriter->writeAttribute('w:styleId', $styleId); $objWriter->startElement('w:link'); $objWriter->writeAttribute('w:val', $styleLink); $objWriter->endElement(); } $objWriter->startElement('w:name'); $objWriter->writeAttribute('w:val', $styleName); $objWriter->endElement(); if (!is_null($paragraphStyle)) { // print_r($paragraphStyle);exit; $this->_writeParagraphStyle($objWriter, $paragraphStyle); } $this->_writeTextStyle($objWriter, $style); $objWriter->endElement(); } elseif ($style instanceof Document_Word_Writer_Style_Paragraph) { $objWriter->startElement('w:style'); $objWriter->writeAttribute('w:type', 'paragraph'); $objWriter->writeAttribute('w:customStyle', '1'); $objWriter->writeAttribute('w:styleId', $styleName); $objWriter->startElement('w:name'); $objWriter->writeAttribute('w:val', $styleName); $objWriter->endElement(); $this->_writeParagraphStyle($objWriter, $style); $objWriter->endElement(); } elseif ($style instanceof Document_Word_Writer_Style_TableFull) { $objWriter->startElement('w:style'); $objWriter->writeAttribute('w:type', 'table'); $objWriter->writeAttribute('w:customStyle', '1'); $objWriter->writeAttribute('w:styleId', $styleName); $objWriter->startElement('w:name'); $objWriter->writeAttribute('w:val', $styleName); $objWriter->endElement(); $objWriter->startElement('w:uiPriority'); $objWriter->writeAttribute('w:val', '99'); $objWriter->endElement(); $this->_writeFullTableStyle($objWriter, $style); $objWriter->endElement(); } } } $objWriter->endElement(); // w:styles // Return return $objWriter->getData(); }
public function writeDocPropsCore(Document_Word_Writer $pPHPWord = null) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_MEMORY); } // XML header $objWriter->startDocument('1.0', 'UTF-8', 'yes'); // cp:coreProperties $objWriter->startElement('cp:coreProperties'); $objWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties'); $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $objWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/'); $objWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/'); $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); // dc:creator $objWriter->writeElement('dc:creator', $pPHPWord->getProperties()->getCreator()); // cp:lastModifiedBy $objWriter->writeElement('cp:lastModifiedBy', $pPHPWord->getProperties()->getLastModifiedBy()); // dcterms:created $objWriter->startElement('dcterms:created'); $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); $objWriter->writeRaw(date(DATE_W3C, $pPHPWord->getProperties()->getCreated())); $objWriter->endElement(); // dcterms:modified $objWriter->startElement('dcterms:modified'); $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); $objWriter->writeRaw(date(DATE_W3C, $pPHPWord->getProperties()->getModified())); $objWriter->endElement(); // dc:title $objWriter->writeElement('dc:title', $pPHPWord->getProperties()->getTitle()); // dc:description $objWriter->writeElement('dc:description', $pPHPWord->getProperties()->getDescription()); // dc:subject $objWriter->writeElement('dc:subject', $pPHPWord->getProperties()->getSubject()); // cp:keywords $objWriter->writeElement('cp:keywords', $pPHPWord->getProperties()->getKeywords()); // cp:category $objWriter->writeElement('cp:category', $pPHPWord->getProperties()->getCategory()); $objWriter->endElement(); // Return return $objWriter->getData(); }
public function writeDocument(Document_Word_Writer $pPHPWord = null) { // Create XML writer if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { $objWriter = new Document_Word_Writer_Shared_XMLWriter(Document_Word_Writer_Shared_XMLWriter::STORAGE_MEMORY); } // XML header $objWriter->startDocument('1.0', 'UTF-8', 'yes'); // w:document $objWriter->startElement('w:document'); $objWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006'); $objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $objWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math'); $objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); $objWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'); $objWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word'); $objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $objWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml'); $objWriter->startElement('w:body'); $_sections = $pPHPWord->getSections(); $countSections = count($_sections); $pSection = 0; if ($countSections < 1) { $_sections = array(); } foreach ($_sections as $section) { $pSection++; $_elements = $section->getElements(); foreach ($_elements as $element) { if ($element instanceof Document_Word_Writer_Section_Text) { $this->_writeText($objWriter, $element); } elseif ($element instanceof Document_Word_Writer_Section_TextRun) { $this->_writeTextRun($objWriter, $element); } elseif ($element instanceof Document_Word_Writer_Section_Link) { $this->_writeLink($objWriter, $element); } elseif ($element instanceof Document_Word_Writer_Section_Title) { $this->_writeTitle($objWriter, $element); } elseif ($element instanceof Document_Word_Writer_Section_TextBreak) { $this->_writeTextBreak($objWriter); } elseif ($element instanceof Document_Word_Writer_Section_PageBreak) { $this->_writePageBreak($objWriter); } elseif ($element instanceof Document_Word_Writer_Section_Table) { $this->_writeTable($objWriter, $element); } elseif ($element instanceof Document_Word_Writer_Section_ListItem) { $this->_writeListItem($objWriter, $element); } elseif ($element instanceof Document_Word_Writer_Section_Image || $element instanceof Document_Word_Writer_Section_MemoryImage) { $this->_writeImage($objWriter, $element); } elseif ($element instanceof Document_Word_Writer_Section_Object) { $this->_writeObject($objWriter, $element); } elseif ($element instanceof Document_Word_Writer_TOC) { $this->_writeTOC($objWriter); } } if ($pSection == $countSections) { $this->_writeEndSection($objWriter, $section); } else { $this->_writeSection($objWriter, $section); } } $objWriter->endElement(); // End w:body $objWriter->endElement(); // End w:document // Return return $objWriter->getData(); }