├── .github_changelog_generator ├── .php-cs-fixer.dist.php ├── CONTRIBUTING.md ├── COPYING ├── COPYING.LESSER ├── LICENSE ├── README.md ├── composer.json ├── mkdocs.yml ├── phpstan-baseline.neon ├── phpstan.neon.dist ├── phpword.ini.dist └── src └── PhpWord ├── Autoloader.php ├── Collection ├── AbstractCollection.php ├── Bookmarks.php ├── Charts.php ├── Comments.php ├── Endnotes.php ├── Footnotes.php └── Titles.php ├── ComplexType ├── FootnoteProperties.php ├── ProofState.php ├── RubyProperties.php ├── TblWidth.php └── TrackChangesView.php ├── Element ├── AbstractContainer.php ├── AbstractElement.php ├── Bookmark.php ├── Cell.php ├── Chart.php ├── CheckBox.php ├── Comment.php ├── Endnote.php ├── Field.php ├── Footer.php ├── Footnote.php ├── FormField.php ├── Formula.php ├── Header.php ├── Image.php ├── Line.php ├── Link.php ├── ListItem.php ├── ListItemRun.php ├── OLEObject.php ├── PageBreak.php ├── PreserveText.php ├── Row.php ├── Ruby.php ├── SDT.php ├── Section.php ├── Shape.php ├── TOC.php ├── Table.php ├── Text.php ├── TextBox.php ├── TextBreak.php ├── TextRun.php ├── Title.php └── TrackChange.php ├── Escaper ├── AbstractEscaper.php ├── EscaperInterface.php ├── RegExp.php ├── Rtf.php └── Xml.php ├── Exception ├── CopyFileException.php ├── CreateTemporaryFileException.php ├── Exception.php ├── InvalidImageException.php ├── InvalidObjectException.php ├── InvalidStyleException.php └── UnsupportedImageTypeException.php ├── IOFactory.php ├── Media.php ├── Metadata ├── Compatibility.php ├── DocInfo.php ├── Protection.php └── Settings.php ├── PhpWord.php ├── Reader ├── AbstractReader.php ├── HTML.php ├── MsDoc.php ├── ODText.php ├── ODText │ ├── AbstractPart.php │ ├── Content.php │ └── Meta.php ├── RTF.php ├── RTF │ └── Document.php ├── ReaderInterface.php ├── Word2007.php └── Word2007 │ ├── AbstractPart.php │ ├── Comments.php │ ├── DocPropsApp.php │ ├── DocPropsCore.php │ ├── DocPropsCustom.php │ ├── Document.php │ ├── Endnotes.php │ ├── Footnotes.php │ ├── Numbering.php │ ├── Settings.php │ └── Styles.php ├── Settings.php ├── Shared ├── AbstractEnum.php ├── Converter.php ├── Css.php ├── Drawing.php ├── Html.php ├── Microsoft │ └── PasswordEncoder.php ├── OLERead.php ├── PCLZip │ └── pclzip.lib.php ├── Text.php ├── Validate.php ├── XMLReader.php ├── XMLWriter.php └── ZipArchive.php ├── SimpleType ├── Border.php ├── DocProtect.php ├── Jc.php ├── JcTable.php ├── LineSpacingRule.php ├── NumberFormat.php ├── TblWidth.php ├── TextAlignment.php ├── VerticalJc.php └── Zoom.php ├── Style.php ├── Style ├── AbstractStyle.php ├── Border.php ├── Cell.php ├── Chart.php ├── Extrusion.php ├── Fill.php ├── Font.php ├── Frame.php ├── Image.php ├── Indentation.php ├── Language.php ├── Line.php ├── LineNumbering.php ├── ListItem.php ├── Numbering.php ├── NumberingLevel.php ├── Outline.php ├── Paper.php ├── Paragraph.php ├── Row.php ├── Section.php ├── Shading.php ├── Shadow.php ├── Shape.php ├── Spacing.php ├── TOC.php ├── Tab.php ├── Table.php ├── TablePosition.php └── TextBox.php ├── TemplateProcessor.php ├── Writer ├── AbstractWriter.php ├── EPub3.php ├── EPub3 │ ├── Element │ │ ├── AbstractElement.php │ │ ├── Image.php │ │ └── Text.php │ ├── Part.php │ ├── Part │ │ ├── AbstractPart.php │ │ ├── Content.php │ │ ├── ContentXhtml.php │ │ ├── Manifest.php │ │ ├── Meta.php │ │ ├── Mimetype.php │ │ └── Nav.php │ └── Style │ │ ├── AbstractStyle.php │ │ ├── Font.php │ │ ├── Paragraph.php │ │ └── Table.php ├── HTML.php ├── HTML │ ├── Element │ │ ├── AbstractElement.php │ │ ├── Bookmark.php │ │ ├── Container.php │ │ ├── Endnote.php │ │ ├── Footnote.php │ │ ├── Image.php │ │ ├── Link.php │ │ ├── ListItem.php │ │ ├── ListItemRun.php │ │ ├── PageBreak.php │ │ ├── Ruby.php │ │ ├── Table.php │ │ ├── Text.php │ │ ├── TextBreak.php │ │ ├── TextRun.php │ │ └── Title.php │ ├── Part │ │ ├── AbstractPart.php │ │ ├── Body.php │ │ └── Head.php │ └── Style │ │ ├── AbstractStyle.php │ │ ├── Font.php │ │ ├── Generic.php │ │ ├── Image.php │ │ ├── Paragraph.php │ │ └── Table.php ├── ODText.php ├── ODText │ ├── Element │ │ ├── AbstractElement.php │ │ ├── Container.php │ │ ├── Field.php │ │ ├── Formula.php │ │ ├── Image.php │ │ ├── Link.php │ │ ├── ListItemRun.php │ │ ├── PageBreak.php │ │ ├── Ruby.php │ │ ├── Table.php │ │ ├── Text.php │ │ ├── TextBreak.php │ │ ├── TextRun.php │ │ └── Title.php │ ├── Part │ │ ├── AbstractPart.php │ │ ├── Content.php │ │ ├── Manifest.php │ │ ├── Meta.php │ │ ├── Mimetype.php │ │ └── Styles.php │ └── Style │ │ ├── AbstractStyle.php │ │ ├── Font.php │ │ ├── Image.php │ │ ├── Numbering.php │ │ ├── Paragraph.php │ │ ├── Section.php │ │ └── Table.php ├── PDF.php ├── PDF │ ├── AbstractRenderer.php │ ├── DomPDF.php │ ├── MPDF.php │ └── TCPDF.php ├── RTF.php ├── RTF │ ├── Element │ │ ├── AbstractElement.php │ │ ├── Container.php │ │ ├── Field.php │ │ ├── Image.php │ │ ├── Link.php │ │ ├── ListItem.php │ │ ├── PageBreak.php │ │ ├── Ruby.php │ │ ├── Table.php │ │ ├── Text.php │ │ ├── TextBreak.php │ │ ├── TextRun.php │ │ └── Title.php │ ├── Part │ │ ├── AbstractPart.php │ │ ├── Document.php │ │ └── Header.php │ └── Style │ │ ├── AbstractStyle.php │ │ ├── Border.php │ │ ├── Font.php │ │ ├── Indentation.php │ │ ├── Paragraph.php │ │ ├── Section.php │ │ └── Tab.php ├── Word2007.php ├── Word2007 │ ├── Element │ │ ├── AbstractElement.php │ │ ├── Bookmark.php │ │ ├── Chart.php │ │ ├── CheckBox.php │ │ ├── Container.php │ │ ├── Endnote.php │ │ ├── Field.php │ │ ├── Footnote.php │ │ ├── FormField.php │ │ ├── Formula.php │ │ ├── Image.php │ │ ├── Line.php │ │ ├── Link.php │ │ ├── ListItem.php │ │ ├── ListItemRun.php │ │ ├── OLEObject.php │ │ ├── PageBreak.php │ │ ├── ParagraphAlignment.php │ │ ├── PreserveText.php │ │ ├── Ruby.php │ │ ├── SDT.php │ │ ├── Shape.php │ │ ├── TOC.php │ │ ├── Table.php │ │ ├── TableAlignment.php │ │ ├── Text.php │ │ ├── TextBox.php │ │ ├── TextBreak.php │ │ ├── TextRun.php │ │ └── Title.php │ ├── Part │ │ ├── AbstractPart.php │ │ ├── Chart.php │ │ ├── Comments.php │ │ ├── ContentTypes.php │ │ ├── DocPropsApp.php │ │ ├── DocPropsCore.php │ │ ├── DocPropsCustom.php │ │ ├── Document.php │ │ ├── Endnotes.php │ │ ├── FontTable.php │ │ ├── Footer.php │ │ ├── Footnotes.php │ │ ├── Header.php │ │ ├── Numbering.php │ │ ├── Rels.php │ │ ├── RelsDocument.php │ │ ├── RelsPart.php │ │ ├── Settings.php │ │ ├── Styles.php │ │ ├── Theme.php │ │ └── WebSettings.php │ └── Style │ │ ├── AbstractStyle.php │ │ ├── Cell.php │ │ ├── Extrusion.php │ │ ├── Fill.php │ │ ├── Font.php │ │ ├── Frame.php │ │ ├── Image.php │ │ ├── Indentation.php │ │ ├── Line.php │ │ ├── LineNumbering.php │ │ ├── MarginBorder.php │ │ ├── Outline.php │ │ ├── Paragraph.php │ │ ├── Row.php │ │ ├── Section.php │ │ ├── Shading.php │ │ ├── Shadow.php │ │ ├── Shape.php │ │ ├── Spacing.php │ │ ├── Tab.php │ │ ├── Table.php │ │ ├── TablePosition.php │ │ └── TextBox.php ├── WriterInterface.php └── WriterPartInterface.php └── resources ├── doc.png ├── ppt.png └── xls.png /.github_changelog_generator: -------------------------------------------------------------------------------- 1 | user=PHPOffice 2 | project=PHPWord 3 | 4 | since-tag=0.18.1 5 | future-release=0.18.2 6 | 7 | issues=false 8 | pulls=true 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | PHPWord, a pure PHP library for reading and writing word processing documents. 2 | 3 | Copyright (c) 2010-2025 PHPWord. 4 | 5 | PHPWord is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License version 3 as published by 7 | the Free Software Foundation. 8 | 9 | PHPWord is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License version 3 for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License version 3 15 | along with PHPWord. If not, see . 16 | -------------------------------------------------------------------------------- /phpstan.neon.dist: -------------------------------------------------------------------------------- 1 | includes: 2 | - phpstan-baseline.neon 3 | - vendor/phpstan/phpstan-phpunit/extension.neon 4 | - vendor/phpstan/phpstan-phpunit/rules.neon 5 | parameters: 6 | level: 7 7 | paths: 8 | - src/ 9 | - tests/ 10 | excludePaths: 11 | - */pclzip.lib.php 12 | - src/PhpWord/Shared/OLERead.php 13 | - src/PhpWord/Reader/MsDoc.php 14 | - src/PhpWord/Writer/PDF/MPDF.php 15 | bootstrapFiles: 16 | - tests/bootstrap.php 17 | ## <=PHP7.4 18 | reportUnmatchedIgnoredErrors: false 19 | treatPhpDocTypesAsCertain: false 20 | ignoreErrors: 21 | - 22 | identifier: missingType.iterableValue 23 | 24 | ## <=PHP7.4 25 | - 26 | message: '#Parameter \#1 \$argument of class ReflectionClass constructor expects class-string\|T of object, string given.#' 27 | path: src/PhpWord/Element/AbstractContainer.php 28 | - 29 | message: '#Parameter \#1 \$function of function call_user_func expects callable\(\): mixed, string given.#' 30 | path: src/PhpWord/Element/Image.php 31 | - 32 | message: '#Parameter \#1 \$argument of class ReflectionClass constructor expects class-string\|T of object, string given.#' 33 | path: src/PhpWord/IOFactory.php 34 | - 35 | message: '#Parameter \#1 \$function of function forward_static_call_array expects callable\(\): mixed, array{.+, string} given.#' 36 | path: src/PhpWord/PhpWord.php 37 | - 38 | message: '#Parameter \#1 \$function of function call_user_func_array expects callable\(\): mixed, array{\$this\(PhpOffice\\PhpWord\\Shared\\ZipArchive\)\|PclZip\|ZipArchive, mixed} given.#' 39 | path: src/PhpWord/Shared/ZipArchive.php 40 | - 41 | message: '#Parameter \#1 \$function of function call_user_func_array expects callable\(\): mixed, array{PhpOffice\\PhpWord\\Writer\\PDF\\AbstractRenderer, string} given.#' 42 | path: src/PhpWord/Writer/PDF.php 43 | - 44 | message: '#Parameter \#1 \$argument of class ReflectionClass constructor expects class-string\|object, class-string\|false given.#' 45 | path: tests/PhpWordTests/Style/AbstractStyleTest.php 46 | -------------------------------------------------------------------------------- /phpword.ini.dist: -------------------------------------------------------------------------------- 1 | ; Default config file for PHPWord 2 | ; Copy this file into phpword.ini and use Settings::loadConfig to load 3 | 4 | [General] 5 | 6 | compatibility = true 7 | zipClass = ZipArchive 8 | pdfRendererName = DomPDF 9 | pdfRendererPath = 10 | ; tempDir = "C:\PhpWordTemp" 11 | outputEscapingEnabled = false 12 | 13 | [Font] 14 | 15 | defaultFontName = Arial 16 | defaultFontSize = 10 17 | defaultFontColor = 000000 18 | 19 | [Paper] 20 | 21 | defaultPaper = "A4" 22 | -------------------------------------------------------------------------------- /src/PhpWord/Autoloader.php: -------------------------------------------------------------------------------- 1 | items; 45 | } 46 | 47 | /** 48 | * Get item by index. 49 | * 50 | * @return ?T 51 | */ 52 | public function getItem(int $index) 53 | { 54 | if (array_key_exists($index, $this->items)) { 55 | return $this->items[$index]; 56 | } 57 | 58 | return null; 59 | } 60 | 61 | /** 62 | * Set item. 63 | * 64 | * @param ?T $item 65 | */ 66 | public function setItem(int $index, $item): void 67 | { 68 | if (array_key_exists($index, $this->items)) { 69 | $this->items[$index] = $item; 70 | } 71 | } 72 | 73 | /** 74 | * Add new item. 75 | * 76 | * @param T $item 77 | */ 78 | public function addItem($item): int 79 | { 80 | $index = $this->countItems(); 81 | $this->items[$index] = $item; 82 | 83 | return $index; 84 | } 85 | 86 | /** 87 | * Get item count. 88 | */ 89 | public function countItems(): int 90 | { 91 | return count($this->items); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/PhpWord/Collection/Bookmarks.php: -------------------------------------------------------------------------------- 1 | 29 | */ 30 | class Bookmarks extends AbstractCollection 31 | { 32 | } 33 | -------------------------------------------------------------------------------- /src/PhpWord/Collection/Charts.php: -------------------------------------------------------------------------------- 1 | 29 | */ 30 | class Charts extends AbstractCollection 31 | { 32 | } 33 | -------------------------------------------------------------------------------- /src/PhpWord/Collection/Comments.php: -------------------------------------------------------------------------------- 1 | 29 | */ 30 | class Comments extends AbstractCollection 31 | { 32 | } 33 | -------------------------------------------------------------------------------- /src/PhpWord/Collection/Endnotes.php: -------------------------------------------------------------------------------- 1 | 29 | */ 30 | class Endnotes extends AbstractCollection 31 | { 32 | } 33 | -------------------------------------------------------------------------------- /src/PhpWord/Collection/Footnotes.php: -------------------------------------------------------------------------------- 1 | 29 | */ 30 | class Footnotes extends AbstractCollection 31 | { 32 | } 33 | -------------------------------------------------------------------------------- /src/PhpWord/Collection/Titles.php: -------------------------------------------------------------------------------- 1 | 29 | */ 30 | class Titles extends AbstractCollection 31 | { 32 | } 33 | -------------------------------------------------------------------------------- /src/PhpWord/ComplexType/TblWidth.php: -------------------------------------------------------------------------------- 1 | value = $value; 41 | TblWidthSimpleType::validate($type); 42 | $this->type = $type; 43 | } 44 | 45 | /** 46 | * @return string 47 | */ 48 | public function getType() 49 | { 50 | return $this->type; 51 | } 52 | 53 | /** 54 | * @return int 55 | */ 56 | public function getValue() 57 | { 58 | return $this->value; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/PhpWord/Element/Bookmark.php: -------------------------------------------------------------------------------- 1 | name = SharedText::toUTF8($name); 50 | } 51 | 52 | /** 53 | * Get Bookmark name. 54 | * 55 | * @return string 56 | */ 57 | public function getName() 58 | { 59 | return $this->name; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/PhpWord/Element/Cell.php: -------------------------------------------------------------------------------- 1 | width = $width; 56 | $this->style = $this->setNewStyle(new CellStyle(), $style, true); 57 | } 58 | 59 | /** 60 | * Get cell style. 61 | * 62 | * @return ?CellStyle 63 | */ 64 | public function getStyle() 65 | { 66 | return $this->style; 67 | } 68 | 69 | /** 70 | * Get cell width. 71 | * 72 | * @return ?int 73 | */ 74 | public function getWidth() 75 | { 76 | return $this->width; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/PhpWord/Element/CheckBox.php: -------------------------------------------------------------------------------- 1 | setName($name); 48 | parent::__construct($text, $fontStyle, $paragraphStyle); 49 | } 50 | 51 | /** 52 | * Set name content. 53 | * 54 | * @param string $name 55 | * 56 | * @return self 57 | */ 58 | public function setName($name) 59 | { 60 | $this->name = SharedText::toUTF8($name); 61 | 62 | return $this; 63 | } 64 | 65 | /** 66 | * Get name content. 67 | * 68 | * @return string 69 | */ 70 | public function getName() 71 | { 72 | return $this->name; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/PhpWord/Element/Endnote.php: -------------------------------------------------------------------------------- 1 | paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); 52 | $this->setDocPart($this->container); 53 | } 54 | 55 | /** 56 | * Get paragraph style. 57 | * 58 | * @return null|Paragraph|string 59 | */ 60 | public function getParagraphStyle() 61 | { 62 | return $this->paragraphStyle; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/PhpWord/Element/Formula.php: -------------------------------------------------------------------------------- 1 | setMath($math); 41 | } 42 | 43 | public function setMath(Math $math): self 44 | { 45 | $this->math = $math; 46 | 47 | return $this; 48 | } 49 | 50 | public function getMath(): Math 51 | { 52 | return $this->math; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/PhpWord/Element/Header.php: -------------------------------------------------------------------------------- 1 | addImage($src, $style, true); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/PhpWord/Element/Line.php: -------------------------------------------------------------------------------- 1 | style = $this->setNewStyle(new LineStyle(), $style); 43 | } 44 | 45 | /** 46 | * Get line style. 47 | * 48 | * @return ?LineStyle 49 | */ 50 | public function getStyle() 51 | { 52 | return $this->style; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/PhpWord/Element/ListItemRun.php: -------------------------------------------------------------------------------- 1 | depth = $depth; 57 | 58 | // Version >= 0.10.0 will pass numbering style name. Older version will use old method 59 | if (null !== $listStyle && is_string($listStyle)) { 60 | $this->style = new ListItemStyle($listStyle); 61 | } else { 62 | $this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true); 63 | } 64 | parent::__construct($paragraphStyle); 65 | } 66 | 67 | /** 68 | * Get ListItem style. 69 | * 70 | * @return ?ListItemStyle 71 | */ 72 | public function getStyle() 73 | { 74 | return $this->style; 75 | } 76 | 77 | /** 78 | * Get ListItem depth. 79 | * 80 | * @return int 81 | */ 82 | public function getDepth() 83 | { 84 | return $this->depth; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/PhpWord/Element/PageBreak.php: -------------------------------------------------------------------------------- 1 | setType($type); 53 | $this->style = $this->setNewStyle(new ShapeStyle(), $style); 54 | } 55 | 56 | /** 57 | * Get type. 58 | * 59 | * @return string 60 | */ 61 | public function getType() 62 | { 63 | return $this->type; 64 | } 65 | 66 | /** 67 | * Set pattern. 68 | * 69 | * @param string $value 70 | * 71 | * @return self 72 | */ 73 | public function setType($value = null) 74 | { 75 | $enum = ['arc', 'curve', 'line', 'polyline', 'rect', 'oval']; 76 | $this->type = $this->setEnumVal($value, $enum, null); 77 | 78 | return $this; 79 | } 80 | 81 | /** 82 | * Get shape style. 83 | * 84 | * @return ?ShapeStyle 85 | */ 86 | public function getStyle() 87 | { 88 | return $this->style; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/PhpWord/Element/TextBox.php: -------------------------------------------------------------------------------- 1 | style = $this->setNewStyle(new TextBoxStyle(), $style); 50 | } 51 | 52 | /** 53 | * Get textbox style. 54 | * 55 | * @return ?TextBoxStyle 56 | */ 57 | public function getStyle() 58 | { 59 | return $this->style; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/PhpWord/Escaper/AbstractEscaper.php: -------------------------------------------------------------------------------- 1 | escapeSingleValue($item); 40 | } 41 | } else { 42 | $input = $this->escapeSingleValue($input); 43 | } 44 | 45 | return $input; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/PhpWord/Escaper/EscaperInterface.php: -------------------------------------------------------------------------------- 1 | ooxmlVersion; 50 | } 51 | 52 | /** 53 | * Set OOXML version. 54 | * 55 | * @param int $value 56 | * 57 | * @return self 58 | */ 59 | public function setOoxmlVersion($value) 60 | { 61 | $this->ooxmlVersion = $value; 62 | 63 | return $this; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/PhpWord/Reader/HTML.php: -------------------------------------------------------------------------------- 1 | canRead($docFile)) { 44 | $section = $phpWord->addSection(); 45 | HTMLParser::addHtml($section, file_get_contents($docFile), true); 46 | } else { 47 | throw new Exception("Cannot read {$docFile}."); 48 | } 49 | 50 | return $phpWord; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/PhpWord/Reader/ODText/AbstractPart.php: -------------------------------------------------------------------------------- 1 | canRead($docFile)) { 44 | $doc = new Document(); 45 | $doc->rtf = file_get_contents($docFile); 46 | $doc->read($phpWord); 47 | } else { 48 | throw new Exception("Cannot read {$docFile}."); 49 | } 50 | 51 | return $phpWord; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/PhpWord/Reader/ReaderInterface.php: -------------------------------------------------------------------------------- 1 | getDomFromZip($this->docFile, $this->xmlFile); 26 | 27 | $comments = $phpWord->getComments(); 28 | 29 | $nodes = $xmlReader->getElements('*'); 30 | 31 | foreach ($nodes as $node) { 32 | $name = str_replace('w:', '', $node->nodeName); 33 | 34 | $author = $xmlReader->getAttribute('w:author', $node); 35 | $date = $xmlReader->getAttribute('w:date', $node); 36 | $initials = $xmlReader->getAttribute('w:initials', $node); 37 | 38 | $element = new Comment($author, new DateTime($date), $initials); 39 | 40 | $range = $this->getCommentReference($xmlReader->getAttribute('w:id', $node)); 41 | if ($range['start']) { 42 | $range['start']->setCommentRangeStart($element); 43 | } 44 | if ($range['end']) { 45 | $range['end']->setCommentRangeEnd($element); 46 | } 47 | 48 | $pNodes = $xmlReader->getElements('w:p/w:r', $node); 49 | foreach ($pNodes as $pNode) { 50 | $this->readRun($xmlReader, $pNode, $element, $this->collection); 51 | } 52 | 53 | $phpWord->getComments()->addItem($element); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/PhpWord/Reader/Word2007/DocPropsApp.php: -------------------------------------------------------------------------------- 1 | 'setCompany', 'Manager' => 'setManager']; 34 | 35 | /** 36 | * Callback functions. 37 | * 38 | * @var array 39 | */ 40 | protected $callbacks = []; 41 | } 42 | -------------------------------------------------------------------------------- /src/PhpWord/Reader/Word2007/DocPropsCustom.php: -------------------------------------------------------------------------------- 1 | getDomFromZip($this->docFile, $this->xmlFile); 39 | $docProps = $phpWord->getDocInfo(); 40 | 41 | $nodes = $xmlReader->getElements('*'); 42 | if ($nodes->length > 0) { 43 | foreach ($nodes as $node) { 44 | $propertyName = $xmlReader->getAttribute('name', $node); 45 | $attributeNode = $xmlReader->getElement('*', $node); 46 | $attributeType = $attributeNode->nodeName; 47 | $attributeValue = $attributeNode->nodeValue; 48 | $attributeValue = DocInfo::convertProperty($attributeValue, $attributeType); 49 | $attributeType = DocInfo::convertPropertyType($attributeType); 50 | $docProps->setCustomProperty($propertyName, $attributeValue, $attributeType); 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/PhpWord/Reader/Word2007/Endnotes.php: -------------------------------------------------------------------------------- 1 | setStyleByArray($style); 46 | } 47 | 48 | /** 49 | * Get color. 50 | * 51 | * @return string 52 | */ 53 | public function getColor() 54 | { 55 | return $this->color; 56 | } 57 | 58 | /** 59 | * Set color. 60 | * 61 | * @param string $value 62 | * 63 | * @return self 64 | */ 65 | public function setColor($value = null) 66 | { 67 | $this->color = $value; 68 | 69 | return $this; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/PhpWord/Style/Shadow.php: -------------------------------------------------------------------------------- 1 | setStyleByArray($style); 51 | } 52 | 53 | /** 54 | * Get color. 55 | * 56 | * @return string 57 | */ 58 | public function getColor() 59 | { 60 | return $this->color; 61 | } 62 | 63 | /** 64 | * Set color. 65 | * 66 | * @param string $value 67 | * 68 | * @return self 69 | */ 70 | public function setColor($value = null) 71 | { 72 | $this->color = $value; 73 | 74 | return $this; 75 | } 76 | 77 | /** 78 | * Get offset. 79 | * 80 | * @return string 81 | */ 82 | public function getOffset() 83 | { 84 | return $this->offset; 85 | } 86 | 87 | /** 88 | * Set offset. 89 | * 90 | * @param string $value 91 | * 92 | * @return self 93 | */ 94 | public function setOffset($value = null) 95 | { 96 | $this->offset = $value; 97 | 98 | return $this; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/EPub3/Element/AbstractElement.php: -------------------------------------------------------------------------------- 1 | getXmlWriter(); 18 | $xmlWriter->setIndent(false); 19 | $element = $this->getElement(); 20 | if (!$element instanceof ImageElement) { 21 | return; 22 | } 23 | $mediaIndex = $element->getMediaIndex(); 24 | $target = 'media/image' . $mediaIndex . '.' . $element->getImageExtension(); 25 | if (!$this->withoutP) { 26 | $xmlWriter->startElement('p'); 27 | } 28 | $xmlWriter->startElement('img'); 29 | $xmlWriter->writeAttribute('src', $target); 30 | $style = ''; 31 | if ($element->getStyle()->getWidth() !== null) { 32 | $style .= 'width:' . $element->getStyle()->getWidth() . 'px;'; 33 | } 34 | if ($element->getStyle()->getHeight() !== null) { 35 | $style .= 'height:' . $element->getStyle()->getHeight() . 'px;'; 36 | } 37 | if ($style !== '') { 38 | $xmlWriter->writeAttribute('style', $style); 39 | } 40 | $xmlWriter->endElement(); // img 41 | if (!$this->withoutP) { 42 | $xmlWriter->endElement(); // p 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/EPub3/Element/Text.php: -------------------------------------------------------------------------------- 1 | getXmlWriter(); 16 | $xmlWriter->setIndent(true); 17 | $xmlWriter->setIndentString(' '); 18 | $element = $this->getElement(); 19 | if (!$element instanceof \PhpOffice\PhpWord\Element\Text) { 20 | return; 21 | } 22 | 23 | $fontStyle = $element->getFontStyle(); 24 | $paragraphStyle = $element->getParagraphStyle(); 25 | 26 | if (!$this->withoutP) { 27 | $xmlWriter->startElement('p'); 28 | if (is_string($paragraphStyle) && $paragraphStyle !== '') { 29 | $xmlWriter->writeAttribute('class', $paragraphStyle); 30 | } 31 | } 32 | 33 | if (!empty($fontStyle)) { 34 | $xmlWriter->startElement('span'); 35 | if (is_string($fontStyle)) { 36 | $xmlWriter->writeAttribute('class', $fontStyle); 37 | } 38 | } 39 | 40 | $xmlWriter->text($element->getText()); 41 | 42 | if (!empty($fontStyle)) { 43 | $xmlWriter->endElement(); // span 44 | } 45 | 46 | if (!$this->withoutP) { 47 | $xmlWriter->endElement(); // p 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/EPub3/Part.php: -------------------------------------------------------------------------------- 1 | parentWriter = $writer; 42 | } 43 | 44 | /** 45 | * Get parent writer. 46 | */ 47 | public function getParentWriter(): AbstractWriter 48 | { 49 | return $this->parentWriter; 50 | } 51 | 52 | /** 53 | * Write part content. 54 | */ 55 | abstract public function write(): string; 56 | } 57 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/EPub3/Part/Manifest.php: -------------------------------------------------------------------------------- 1 | '; 32 | $content .= ''; 33 | $content .= ''; 34 | $content .= ''; 35 | $content .= ''; 36 | $content .= ''; 37 | 38 | return $content; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/EPub3/Part/Mimetype.php: -------------------------------------------------------------------------------- 1 | openMemory(); 13 | 14 | return $xmlWriter; 15 | } 16 | 17 | public function write(): string 18 | { 19 | $xmlWriter = $this->getXmlWriter(); 20 | 21 | $xmlWriter->startDocument('1.0', 'UTF-8'); 22 | $xmlWriter->startElement('html'); 23 | $xmlWriter->writeAttribute('xmlns', 'http://www.w3.org/1999/xhtml'); 24 | $xmlWriter->writeAttribute('xmlns:epub', 'http://www.idpf.org/2007/ops'); 25 | 26 | $xmlWriter->startElement('head'); 27 | $xmlWriter->writeElement('title', 'Navigation'); 28 | $xmlWriter->endElement(); // head 29 | 30 | $xmlWriter->startElement('body'); 31 | $xmlWriter->startElement('nav'); 32 | $xmlWriter->writeAttribute('epub:type', 'toc'); 33 | $xmlWriter->writeAttribute('id', 'toc'); 34 | 35 | // Add navigation items here if needed 36 | $xmlWriter->writeElement('h1', 'Table of Contents'); 37 | $xmlWriter->startElement('ol'); 38 | // Add at least one list item to satisfy EPUB 3.3 requirements 39 | $xmlWriter->startElement('li'); 40 | $xmlWriter->startElement('a'); 41 | $xmlWriter->writeAttribute('href', 'content.xhtml'); 42 | $xmlWriter->text('Content'); 43 | $xmlWriter->endElement(); // a 44 | $xmlWriter->endElement(); // li 45 | $xmlWriter->endElement(); // ol 46 | 47 | $xmlWriter->endElement(); // nav 48 | $xmlWriter->endElement(); // body 49 | $xmlWriter->endElement(); // html 50 | 51 | return $xmlWriter->outputMemory(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/EPub3/Style/AbstractStyle.php: -------------------------------------------------------------------------------- 1 | parentWriter = $writer; 49 | 50 | return $this; 51 | } 52 | 53 | /** 54 | * Set XML Writer. 55 | */ 56 | public function setXmlWriter(XMLWriter $writer): self 57 | { 58 | $this->xmlWriter = $writer; 59 | 60 | return $this; 61 | } 62 | 63 | /** 64 | * Get parent writer. 65 | */ 66 | public function getParentWriter(): AbstractWriter 67 | { 68 | return $this->parentWriter; 69 | } 70 | 71 | /** 72 | * Write style content. 73 | */ 74 | abstract public function write(): string; 75 | } 76 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/EPub3/Style/Font.php: -------------------------------------------------------------------------------- 1 | parentWriter = $parentWriter; 65 | $this->element = $element; 66 | $this->withoutP = $withoutP; 67 | } 68 | 69 | /** 70 | * Set without paragraph. 71 | * 72 | * @param bool $value 73 | */ 74 | public function setWithoutP($value): void 75 | { 76 | $this->withoutP = $value; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/HTML/Element/Bookmark.php: -------------------------------------------------------------------------------- 1 | element instanceof \PhpOffice\PhpWord\Element\Bookmark) { 36 | return ''; 37 | } 38 | 39 | $content = ''; 40 | $content .= $this->writeOpening(); 41 | $content .= "element->getName()}\"/>"; 42 | $content .= $this->writeClosing(); 43 | 44 | return $content; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/HTML/Element/Container.php: -------------------------------------------------------------------------------- 1 | element; 45 | if (!$container instanceof ContainerElement) { 46 | return ''; 47 | } 48 | $containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1); 49 | $withoutP = in_array($containerClass, ['TextRun', 'Footnote', 'Endnote']) ? true : false; 50 | $content = ''; 51 | 52 | $elements = $container->getElements(); 53 | foreach ($elements as $element) { 54 | $elementClass = get_class($element); 55 | $writerClass = str_replace('PhpOffice\\PhpWord\\Element', $this->namespace, $elementClass); 56 | if (class_exists($writerClass)) { 57 | /** @var AbstractElement $writer Type hint */ 58 | $writer = new $writerClass($this->parentWriter, $element, $withoutP); 59 | $content .= $writer->write(); 60 | } 61 | } 62 | 63 | return $content; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/HTML/Element/Endnote.php: -------------------------------------------------------------------------------- 1 | element instanceof \PhpOffice\PhpWord\Element\Footnote) { 43 | return ''; 44 | } 45 | /** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Type hint */ 46 | $parentWriter = $this->parentWriter; 47 | 48 | $noteId = count($parentWriter->getNotes()) + 1; 49 | $noteMark = $this->noteType . '-' . $this->element->getRelationId(); 50 | $content = "{$noteId}"; 51 | 52 | $parentWriter->addNote($noteId, $noteMark); 53 | 54 | return $content; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/HTML/Element/Image.php: -------------------------------------------------------------------------------- 1 | element instanceof ImageElement) { 39 | return ''; 40 | } 41 | $content = ''; 42 | $imageData = $this->element->getImageStringData(true); 43 | if ($imageData !== null) { 44 | $styleWriter = new ImageStyleWriter($this->element->getStyle()); 45 | $style = $styleWriter->write(); 46 | $imageData = 'data:' . $this->element->getImageType() . ';base64,' . $imageData; 47 | 48 | $content .= $this->writeOpening(); 49 | $content .= ""; 50 | $content .= $this->writeClosing(); 51 | } 52 | 53 | return $content; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/HTML/Element/Link.php: -------------------------------------------------------------------------------- 1 | element instanceof \PhpOffice\PhpWord\Element\Link) { 38 | return ''; 39 | } 40 | 41 | $prefix = $this->element->isInternal() ? '#' : ''; 42 | $content = $this->writeOpening(); 43 | $content .= "parentWriter->escapeHTML($this->element->getSource()) 45 | . '">' 46 | . $this->parentWriter->escapeHTML($this->element->getText()) 47 | . ''; 48 | $content .= $this->writeClosing(); 49 | 50 | return $content; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/HTML/Element/ListItem.php: -------------------------------------------------------------------------------- 1 | element instanceof \PhpOffice\PhpWord\Element\ListItem) { 38 | return ''; 39 | } 40 | 41 | $content = '' . $this->parentWriter->escapeHTML($this->element->getTextObject()->getText()) . '' . PHP_EOL; 42 | 43 | return $content; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/HTML/Element/ListItemRun.php: -------------------------------------------------------------------------------- 1 | element instanceof \PhpOffice\PhpWord\Element\ListItemRun) { 36 | return ''; 37 | } 38 | 39 | $writer = new Container($this->parentWriter, $this->element); 40 | $content = $writer->write() . PHP_EOL; 41 | 42 | return $content; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/HTML/Element/PageBreak.php: -------------------------------------------------------------------------------- 1 | parentWriter; 41 | if ($parentWriter instanceof TCPDF) { 42 | return ''; 43 | } 44 | if ($parentWriter->isPdf()) { 45 | return ''; 46 | } 47 | 48 | return ' ' . PHP_EOL; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/HTML/Element/TextBreak.php: -------------------------------------------------------------------------------- 1 | withoutP) { 36 | $content = '' . PHP_EOL; 37 | } else { 38 | $content = ' ' . PHP_EOL; 39 | } 40 | 41 | return $content; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/HTML/Element/TextRun.php: -------------------------------------------------------------------------------- 1 | writeOpening(); 38 | $writer = new Container($this->parentWriter, $this->element); 39 | $content .= $writer->write(); 40 | $content .= $this->writeClosing(); 41 | 42 | return $content; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/HTML/Element/Title.php: -------------------------------------------------------------------------------- 1 | element instanceof \PhpOffice\PhpWord\Element\Title) { 38 | return ''; 39 | } 40 | 41 | $tag = 'h' . $this->element->getDepth(); 42 | 43 | $text = $this->element->getText(); 44 | if (is_string($text)) { 45 | $text = $this->parentWriter->escapeHTML($text); 46 | } else { 47 | $writer = new Container($this->parentWriter, $text); 48 | $text = $writer->write(); 49 | } 50 | 51 | $content = "<{$tag}>{$text}{$tag}>" . PHP_EOL; 52 | 53 | return $content; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/HTML/Part/AbstractPart.php: -------------------------------------------------------------------------------- 1 | parentWriter = $writer; 42 | } 43 | 44 | /** 45 | * @return HTML 46 | */ 47 | public function getParentWriter() 48 | { 49 | if ($this->parentWriter !== null) { 50 | return $this->parentWriter; 51 | } 52 | 53 | throw new Exception('No parent WriterInterface assigned.'); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/HTML/Style/Generic.php: -------------------------------------------------------------------------------- 1 | getStyle(); 36 | $css = []; 37 | 38 | if (is_array($style) && !empty($style)) { 39 | $css = $style; 40 | } 41 | 42 | return $this->assembleCss($css); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/HTML/Style/Image.php: -------------------------------------------------------------------------------- 1 | getStyle(); 36 | if (!$style instanceof \PhpOffice\PhpWord\Style\Image) { 37 | return ''; 38 | } 39 | $css = []; 40 | 41 | $width = $style->getWidth(); 42 | $height = $style->getHeight(); 43 | $css['width'] = $this->getValueIf(is_numeric($width), $width . 'px'); 44 | $css['height'] = $this->getValueIf(is_numeric($height), $height . 'px'); 45 | 46 | return $this->assembleCss($css); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/ODText/Element/AbstractElement.php: -------------------------------------------------------------------------------- 1 | startElement('text:s'); 35 | $xmlWriter->writeAttributeIf($num > 1, 'text:c', "$num"); 36 | $xmlWriter->endElement(); 37 | $text = preg_replace('/^ +/', '', $text); 38 | } 39 | preg_match_all('/([\\s\\S]*?)(\\t| +| ?$)/', $text, $matches, PREG_SET_ORDER); 40 | foreach ($matches as $match) { 41 | $this->writeText($match[1]); 42 | if ($match[2] === '') { 43 | break; 44 | } elseif ($match[2] === "\t") { 45 | $xmlWriter->writeElement('text:tab'); 46 | } elseif ($match[2] === ' ') { 47 | $xmlWriter->writeElement('text:s'); 48 | 49 | break; 50 | } else { 51 | $num = strlen($match[2]); 52 | $xmlWriter->startElement('text:s'); 53 | $xmlWriter->writeAttributeIf($num > 1, 'text:c', "$num"); 54 | $xmlWriter->endElement(); 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/ODText/Element/Container.php: -------------------------------------------------------------------------------- 1 | 39 | */ 40 | protected $containerWithoutP = ['TextRun', 'Footnote', 'Endnote']; 41 | } 42 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/ODText/Element/Link.php: -------------------------------------------------------------------------------- 1 | getXmlWriter(); 34 | $element = $this->getElement(); 35 | if (!$element instanceof \PhpOffice\PhpWord\Element\Link) { 36 | return; 37 | } 38 | 39 | if (!$this->withoutP) { 40 | $xmlWriter->startElement('text:p'); // text:p 41 | } 42 | 43 | $xmlWriter->startElement('text:a'); 44 | $xmlWriter->writeAttribute('xlink:type', 'simple'); 45 | $xmlWriter->writeAttribute('xlink:href', ($element->isInternal() ? '#' : '') . $element->getSource()); 46 | $this->writeText($element->getText()); 47 | $xmlWriter->endElement(); // text:a 48 | 49 | if (!$this->withoutP) { 50 | $xmlWriter->endElement(); // text:p 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/ODText/Element/ListItemRun.php: -------------------------------------------------------------------------------- 1 | getElement(); 36 | if (!$element instanceof ListItemRunElement) { 37 | return; 38 | } 39 | $depth = $element->getDepth() + 1; 40 | 41 | $xmlWriter = $this->getXmlWriter(); 42 | 43 | for ($iDepth = 1; $iDepth <= $depth; ++$iDepth) { 44 | $xmlWriter->startElement('text:list'); 45 | $xmlWriter->writeAttribute('text:style-name', $element->getStyle()->getNumStyle()); 46 | $xmlWriter->startElement('text:list-item'); 47 | } 48 | 49 | $containerWriter = new Container($xmlWriter, $element, false); 50 | $containerWriter->write(); 51 | 52 | for ($iDepth = 1; $iDepth <= $depth; ++$iDepth) { 53 | $xmlWriter->endElement(); // text:list-item 54 | $xmlWriter->endElement(); // text:list 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/ODText/Element/PageBreak.php: -------------------------------------------------------------------------------- 1 | getXmlWriter(); 32 | 33 | $xmlWriter->startElement('text:p'); 34 | $xmlWriter->writeAttribute('text:style-name', 'PB'); 35 | $xmlWriter->endElement(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/ODText/Element/TextBreak.php: -------------------------------------------------------------------------------- 1 | getXmlWriter(); 34 | 35 | $xmlWriter->startElement('text:p'); 36 | $xmlWriter->writeAttribute('text:style-name', 'Standard'); 37 | $xmlWriter->endElement(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/ODText/Element/TextRun.php: -------------------------------------------------------------------------------- 1 | getXmlWriter(); 34 | $element = $this->getElement(); 35 | 36 | $xmlWriter->startElement('text:p'); 37 | /** @scrutinizer ignore-call */ 38 | $pStyle = $element->getParagraphStyle(); 39 | if (!is_string($pStyle)) { 40 | $pStyle = 'Normal'; 41 | } 42 | $xmlWriter->writeAttribute('text:style-name', $pStyle); 43 | 44 | $containerWriter = new Container($xmlWriter, $element); 45 | $containerWriter->write(); 46 | 47 | $xmlWriter->endElement(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/ODText/Part/Mimetype.php: -------------------------------------------------------------------------------- 1 | getStyle(); 35 | if (!$style instanceof \PhpOffice\PhpWord\Style\Image) { 36 | return; 37 | } 38 | $xmlWriter = $this->getXmlWriter(); 39 | 40 | $xmlWriter->startElement('style:style'); 41 | $xmlWriter->writeAttribute('style:name', $style->getStyleName()); 42 | $xmlWriter->writeAttribute('style:family', 'graphic'); 43 | $xmlWriter->writeAttribute('style:parent-style-name', 'Graphics'); 44 | $xmlWriter->startElement('style:graphic-properties'); 45 | $xmlWriter->writeAttribute('style:vertical-pos', 'top'); 46 | $xmlWriter->writeAttribute('style:vertical-rel', 'baseline'); 47 | $xmlWriter->endElement(); // style:graphic-properties 48 | $xmlWriter->endElement(); // style:style 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/ODText/Style/Section.php: -------------------------------------------------------------------------------- 1 | getStyle(); 35 | if (!$style instanceof \PhpOffice\PhpWord\Style\Section) { 36 | return; 37 | } 38 | $xmlWriter = $this->getXmlWriter(); 39 | 40 | $xmlWriter->startElement('style:style'); 41 | $xmlWriter->writeAttribute('style:name', $style->getStyleName()); 42 | $xmlWriter->writeAttribute('style:family', 'section'); 43 | $xmlWriter->startElement('style:section-properties'); 44 | 45 | $xmlWriter->startElement('style:columns'); 46 | $xmlWriter->writeAttribute('fo:column-count', $style->getColsNum()); 47 | $xmlWriter->endElement(); // style:columns 48 | 49 | $xmlWriter->endElement(); // style:section-properties 50 | $xmlWriter->endElement(); // style:style 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/PDF/DomPDF.php: -------------------------------------------------------------------------------- 1 | getFont()) { 49 | $options->set('defaultFont', $this->getFont()); 50 | } 51 | 52 | return new DompdfLib($options); 53 | } 54 | 55 | /** 56 | * Save PhpWord to file. 57 | */ 58 | public function save(string $filename): void 59 | { 60 | $fileHandle = parent::prepareForSave($filename); 61 | 62 | // PDF settings 63 | $paperSize = 'A4'; 64 | $orientation = 'portrait'; 65 | 66 | // Create PDF 67 | $pdf = $this->createExternalWriterInstance(); 68 | $pdf->setPaper(strtolower($paperSize), $orientation); 69 | $pdf->loadHtml(str_replace(PHP_EOL, '', $this->getContent())); 70 | $pdf->render(); 71 | 72 | // Write to file 73 | fwrite($fileHandle, $pdf->output()); 74 | 75 | parent::restoreStateAfterSave($fileHandle); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/RTF/Element/Container.php: -------------------------------------------------------------------------------- 1 | element; 45 | if (!$container instanceof ContainerElement) { 46 | return ''; 47 | } 48 | $containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1); 49 | $withoutP = in_array($containerClass, ['TextRun', 'Footnote', 'Endnote']) ? true : false; 50 | $content = ''; 51 | 52 | $elements = $container->getElements(); 53 | foreach ($elements as $element) { 54 | $elementClass = get_class($element); 55 | $writerClass = str_replace('PhpOffice\\PhpWord\\Element', $this->namespace, $elementClass); 56 | if (class_exists($writerClass)) { 57 | /** @var AbstractElement $writer Type hint */ 58 | $writer = new $writerClass($this->parentWriter, $element, $withoutP); 59 | $content .= $writer->write(); 60 | } 61 | } 62 | 63 | return $content; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/RTF/Element/Image.php: -------------------------------------------------------------------------------- 1 | element instanceof ImageElement) { 39 | return ''; 40 | } 41 | 42 | $this->getStyles(); 43 | $style = $this->element->getStyle(); 44 | 45 | $content = ''; 46 | $content .= $this->writeOpening(); 47 | $content .= '{\*\shppict {\pict'; 48 | $content .= '\pngblip\picscalex100\picscaley100'; 49 | $content .= '\picwgoal' . round(Converter::pixelToTwip($style->getWidth())); 50 | $content .= '\pichgoal' . round(Converter::pixelToTwip($style->getHeight())); 51 | $content .= PHP_EOL; 52 | $content .= $this->element->getImageStringData(); 53 | $content .= '}}'; 54 | $content .= $this->writeClosing(); 55 | 56 | return $content; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/RTF/Element/Link.php: -------------------------------------------------------------------------------- 1 | element instanceof \PhpOffice\PhpWord\Element\Link) { 36 | return ''; 37 | } 38 | 39 | $this->getStyles(); 40 | 41 | $content = ''; 42 | $content .= $this->writeOpening(); 43 | $content .= '{\field {\*\fldinst {HYPERLINK "' . $this->element->getSource() . '"}}{\\fldrslt {'; 44 | $content .= $this->writeFontStyle(); 45 | $content .= $this->writeText($this->element->getText()); 46 | $content .= '}}}'; 47 | $content .= $this->writeClosing(); 48 | 49 | return $content; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/RTF/Element/ListItem.php: -------------------------------------------------------------------------------- 1 | element; 36 | $elementClass = str_replace('\\Writer\\RTF', '', static::class); 37 | if (!$element instanceof $elementClass || !is_string($element->getBaseTextRun()->getText())) { 38 | return ''; 39 | } 40 | 41 | $this->getStyles(); 42 | 43 | $content = ''; 44 | $content .= $this->writeOpening(); 45 | $content .= '{'; 46 | $content .= $this->writeFontStyle(); 47 | $content .= $this->writeText($element->getBaseTextRun()->getText()); 48 | $rubyText = $element->getRubyTextRun()->getText(); 49 | if ($rubyText !== '') { 50 | $content .= ' ('; 51 | $content .= $this->writeText($rubyText); 52 | $content .= ')'; 53 | } 54 | $content .= '}'; 55 | $content .= $this->writeClosing(); 56 | 57 | return $content; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/RTF/Element/Text.php: -------------------------------------------------------------------------------- 1 | element; 37 | $elementClass = str_replace('\\Writer\\RTF', '', static::class); 38 | if (!$element instanceof $elementClass || !is_string($element->getText())) { 39 | return ''; 40 | } 41 | 42 | $this->getStyles(); 43 | 44 | $content = ''; 45 | $content .= $this->writeOpening(); 46 | $content .= '{'; 47 | $content .= $this->writeFontStyle(); 48 | $content .= $this->writeText($element->getText()); 49 | $content .= '}'; 50 | $content .= $this->writeClosing(); 51 | 52 | return $content; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/RTF/Element/TextBreak.php: -------------------------------------------------------------------------------- 1 | parentWriter; 37 | $parentWriter->setLastParagraphStyle(); 38 | 39 | return '\pard\par' . PHP_EOL; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/RTF/Element/TextRun.php: -------------------------------------------------------------------------------- 1 | parentWriter, $this->element); 36 | $this->getStyles(); 37 | 38 | $content = ''; 39 | $content .= $this->writeOpening(); 40 | $content .= '{'; 41 | $content .= $writer->write(); 42 | $content .= '}'; 43 | $content .= $this->writeClosing(); 44 | 45 | return $content; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/RTF/Part/AbstractPart.php: -------------------------------------------------------------------------------- 1 | escaper = new Rtf(); 43 | } 44 | 45 | /** 46 | * @return string 47 | */ 48 | abstract public function write(); 49 | 50 | /** 51 | * @param \PhpOffice\PhpWord\Writer\RTF $writer 52 | */ 53 | public function setParentWriter(?AbstractWriter $writer = null): void 54 | { 55 | $this->parentWriter = $writer; 56 | } 57 | 58 | /** 59 | * @return \PhpOffice\PhpWord\Writer\RTF 60 | */ 61 | public function getParentWriter() 62 | { 63 | if ($this->parentWriter !== null) { 64 | return $this->parentWriter; 65 | } 66 | 67 | throw new Exception('No parent WriterInterface assigned.'); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/RTF/Style/Indentation.php: -------------------------------------------------------------------------------- 1 | getStyle(); 36 | if (!$style instanceof \PhpOffice\PhpWord\Style\Indentation) { 37 | return ''; 38 | } 39 | 40 | $content = '\fi' . round($style->getFirstLine()); 41 | $content .= '\li' . round($style->getLeft()); 42 | $content .= '\ri' . round($style->getRight()); 43 | 44 | return $content . ' '; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/RTF/Style/Tab.php: -------------------------------------------------------------------------------- 1 | getStyle(); 34 | if (!$style instanceof \PhpOffice\PhpWord\Style\Tab) { 35 | return; 36 | } 37 | $tabs = [ 38 | \PhpOffice\PhpWord\Style\Tab::TAB_STOP_RIGHT => '\tqr', 39 | \PhpOffice\PhpWord\Style\Tab::TAB_STOP_CENTER => '\tqc', 40 | \PhpOffice\PhpWord\Style\Tab::TAB_STOP_DECIMAL => '\tqdec', 41 | ]; 42 | $content = ''; 43 | if (isset($tabs[$style->getType()])) { 44 | $content .= $tabs[$style->getType()]; 45 | } 46 | $content .= '\tx' . round($style->getPosition()); 47 | 48 | return $content; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Element/Bookmark.php: -------------------------------------------------------------------------------- 1 | getXmlWriter(); 34 | $element = $this->getElement(); 35 | if (!$element instanceof \PhpOffice\PhpWord\Element\Bookmark) { 36 | return; 37 | } 38 | 39 | $rId = $element->getRelationId(); 40 | 41 | $xmlWriter->startElement('w:bookmarkStart'); 42 | $xmlWriter->writeAttribute('w:id', $rId); 43 | $xmlWriter->writeAttribute('w:name', $element->getName()); 44 | $xmlWriter->endElement(); 45 | 46 | $xmlWriter->startElement('w:bookmarkEnd'); 47 | $xmlWriter->writeAttribute('w:id', $rId); 48 | $xmlWriter->endElement(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Element/Endnote.php: -------------------------------------------------------------------------------- 1 | getXmlWriter(); 41 | $element = $this->getElement(); 42 | if (!$element instanceof \PhpOffice\PhpWord\Element\Footnote) { 43 | return; 44 | } 45 | 46 | $this->startElementP(); 47 | 48 | $xmlWriter->startElement('w:r'); 49 | $xmlWriter->startElement('w:rPr'); 50 | $xmlWriter->startElement('w:rStyle'); 51 | $xmlWriter->writeAttribute('w:val', ucfirst($this->referenceType)); 52 | $xmlWriter->endElement(); // w:rStyle 53 | $xmlWriter->endElement(); // w:rPr 54 | $xmlWriter->startElement("w:{$this->referenceType}"); 55 | $xmlWriter->writeAttribute('w:id', $element->getRelationId() + 1); 56 | $xmlWriter->endElement(); // w:$referenceType 57 | $xmlWriter->endElement(); // w:r 58 | 59 | $this->endElementP(); // w:p 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Element/Formula.php: -------------------------------------------------------------------------------- 1 | getElement(); 35 | if (!$element instanceof FormulaElement) { 36 | return; 37 | } 38 | 39 | $this->startElementP(); 40 | 41 | $xmlWriter = $this->getXmlWriter(); 42 | 43 | $xmlWriter->startElement('w:r'); 44 | $xmlWriter->writeElement('w:rPr'); 45 | $xmlWriter->endElement(); 46 | 47 | $xmlWriter->writeRaw((new OfficeMathML())->write($element->getMath())); 48 | 49 | $this->endElementP(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Element/Link.php: -------------------------------------------------------------------------------- 1 | getXmlWriter(); 34 | $element = $this->getElement(); 35 | if (!$element instanceof \PhpOffice\PhpWord\Element\Link) { 36 | return; 37 | } 38 | 39 | $rId = $element->getRelationId() + ($element->isInSection() ? 6 : 0); 40 | 41 | $this->startElementP(); 42 | 43 | $xmlWriter->startElement('w:hyperlink'); 44 | if ($element->isInternal()) { 45 | $xmlWriter->writeAttribute('w:anchor', $element->getSource()); 46 | } else { 47 | $xmlWriter->writeAttribute('r:id', 'rId' . $rId); 48 | } 49 | $xmlWriter->writeAttribute('w:history', '1'); 50 | $xmlWriter->startElement('w:r'); 51 | 52 | $this->writeFontStyle(); 53 | 54 | $xmlWriter->startElement('w:t'); 55 | $xmlWriter->writeAttribute('xml:space', 'preserve'); 56 | $this->writeText($element->getText()); 57 | $xmlWriter->endElement(); // w:t 58 | $xmlWriter->endElement(); // w:r 59 | $xmlWriter->endElement(); // w:hyperlink 60 | 61 | $this->endElementP(); // w:p 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Element/ListItem.php: -------------------------------------------------------------------------------- 1 | getXmlWriter(); 36 | $element = $this->getElement(); 37 | if (!$element instanceof \PhpOffice\PhpWord\Element\ListItem) { 38 | return; 39 | } 40 | 41 | $textObject = $element->getTextObject(); 42 | 43 | $styleWriter = new ParagraphStyleWriter($xmlWriter, $textObject->getParagraphStyle()); 44 | $styleWriter->setWithoutPPR(true); 45 | $styleWriter->setIsInline(true); 46 | 47 | $xmlWriter->startElement('w:p'); 48 | 49 | $xmlWriter->startElement('w:pPr'); 50 | $styleWriter->write(); 51 | 52 | $xmlWriter->startElement('w:numPr'); 53 | $xmlWriter->startElement('w:ilvl'); 54 | $xmlWriter->writeAttribute('w:val', $element->getDepth()); 55 | $xmlWriter->endElement(); // w:ilvl 56 | $xmlWriter->startElement('w:numId'); 57 | $xmlWriter->writeAttribute('w:val', $element->getStyle()->getNumId()); 58 | $xmlWriter->endElement(); // w:numId 59 | $xmlWriter->endElement(); // w:numPr 60 | 61 | $xmlWriter->endElement(); // w:pPr 62 | 63 | $elementWriter = new Text($xmlWriter, $textObject, true); 64 | $elementWriter->write(); 65 | 66 | $xmlWriter->endElement(); // w:p 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Element/PageBreak.php: -------------------------------------------------------------------------------- 1 | getXmlWriter(); 36 | 37 | $xmlWriter->startElement('w:p'); 38 | $xmlWriter->startElement('w:r'); 39 | $xmlWriter->startElement('w:br'); 40 | $xmlWriter->writeAttribute('w:type', 'page'); 41 | $xmlWriter->endElement(); // w:br 42 | $xmlWriter->endElement(); // w:r 43 | $xmlWriter->endElement(); // w:p 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Element/ParagraphAlignment.php: -------------------------------------------------------------------------------- 1 | attributes['w:val'] = $value; 40 | } 41 | 42 | /** 43 | * @since 0.13.0 44 | * 45 | * @return string 46 | */ 47 | final public function getName() 48 | { 49 | return $this->name; 50 | } 51 | 52 | /** 53 | * @since 0.13.0 54 | * 55 | * @return string[] 56 | */ 57 | final public function getAttributes() 58 | { 59 | return $this->attributes; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Element/TableAlignment.php: -------------------------------------------------------------------------------- 1 | attributes['w:val'] = $value; 40 | } 41 | 42 | /** 43 | * @since 0.13.0 44 | * 45 | * @return string 46 | */ 47 | final public function getName() 48 | { 49 | return $this->name; 50 | } 51 | 52 | /** 53 | * @since 0.13.0 54 | * 55 | * @return string[] 56 | */ 57 | final public function getAttributes() 58 | { 59 | return $this->attributes; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Element/TextBreak.php: -------------------------------------------------------------------------------- 1 | getXmlWriter(); 34 | $element = $this->getElement(); 35 | if (!$element instanceof \PhpOffice\PhpWord\Element\TextBreak) { 36 | return; 37 | } 38 | 39 | if (!$this->withoutP) { 40 | $hasStyle = $element->hasStyle(); 41 | $this->startElementP(); 42 | 43 | if ($hasStyle) { 44 | $xmlWriter->startElement('w:pPr'); 45 | $this->writeFontStyle(); 46 | $xmlWriter->endElement(); // w:pPr 47 | } 48 | 49 | $this->endElementP(); // w:p 50 | } else { 51 | $xmlWriter->writeElement('w:br'); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Element/TextRun.php: -------------------------------------------------------------------------------- 1 | getXmlWriter(); 34 | $element = $this->getElement(); 35 | 36 | $this->startElementP(); 37 | 38 | $containerWriter = new Container($xmlWriter, $element); 39 | $containerWriter->write(); 40 | 41 | $this->endElementP(); // w:p 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Part/DocPropsApp.php: -------------------------------------------------------------------------------- 1 | getParentWriter()->getPhpWord(); 36 | $xmlWriter = $this->getXmlWriter(); 37 | $schema = 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties'; 38 | 39 | $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); 40 | $xmlWriter->startElement('Properties'); 41 | $xmlWriter->writeAttribute('xmlns', $schema); 42 | $xmlWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes'); 43 | 44 | $xmlWriter->writeElement('Application', 'PHPWord'); 45 | $xmlWriter->writeElement('Company', $phpWord->getDocInfo()->getCompany()); 46 | $xmlWriter->writeElement('Manager', $phpWord->getDocInfo()->getManager()); 47 | 48 | $xmlWriter->endElement(); // Properties 49 | 50 | return $xmlWriter->getData(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Part/Endnotes.php: -------------------------------------------------------------------------------- 1 | 'officeDocument/2006/relationships/styles', 37 | 'numbering.xml' => 'officeDocument/2006/relationships/numbering', 38 | 'settings.xml' => 'officeDocument/2006/relationships/settings', 39 | 'theme/theme1.xml' => 'officeDocument/2006/relationships/theme', 40 | 'webSettings.xml' => 'officeDocument/2006/relationships/webSettings', 41 | 'fontTable.xml' => 'officeDocument/2006/relationships/fontTable', 42 | ]; 43 | $xmlWriter = $this->getXmlWriter(); 44 | 45 | /** @var \PhpOffice\PhpWord\Writer\Word2007 $parentWriter Type hint */ 46 | $parentWriter = $this->getParentWriter(); 47 | $this->writeRels($xmlWriter, $xmlRels, $parentWriter->getRelationships()); 48 | 49 | return $xmlWriter->getData(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Part/RelsPart.php: -------------------------------------------------------------------------------- 1 | getXmlWriter(); 43 | $this->writeRels($xmlWriter, [], $this->media); 44 | 45 | return $xmlWriter->getData(); 46 | } 47 | 48 | /** 49 | * Set media. 50 | * 51 | * @param array $media 52 | * 53 | * @return self 54 | */ 55 | public function setMedia($media) 56 | { 57 | $this->media = $media; 58 | 59 | return $this; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Part/WebSettings.php: -------------------------------------------------------------------------------- 1 | '', 35 | ]; 36 | 37 | $xmlWriter = $this->getXmlWriter(); 38 | 39 | $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); 40 | $xmlWriter->startElement('w:webSettings'); 41 | $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); 42 | $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); 43 | 44 | foreach ($settings as $settingKey => $settingValue) { 45 | $this->writeSetting($xmlWriter, $settingKey, $settingValue); 46 | } 47 | 48 | $xmlWriter->endElement(); // w:settings 49 | 50 | return $xmlWriter->getData(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Style/Extrusion.php: -------------------------------------------------------------------------------- 1 | getStyle(); 34 | if (!$style instanceof \PhpOffice\PhpWord\Style\Extrusion) { 35 | return; 36 | } 37 | $xmlWriter = $this->getXmlWriter(); 38 | 39 | $xmlWriter->startElement('o:extrusion'); 40 | $xmlWriter->writeAttribute('on', 't'); 41 | $xmlWriter->writeAttributeIf($style->getType() !== null, 'type', $style->getType()); 42 | $xmlWriter->writeAttributeIf($style->getColor() !== null, 'color', $style->getColor()); 43 | $xmlWriter->endElement(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Style/Fill.php: -------------------------------------------------------------------------------- 1 | getStyle(); 34 | if (!$style instanceof \PhpOffice\PhpWord\Style\Fill) { 35 | return; 36 | } 37 | $xmlWriter = $this->getXmlWriter(); 38 | 39 | $xmlWriter->writeAttribute('on', 't'); 40 | $xmlWriter->writeAttributeIf($style->getColor() !== null, 'fillcolor', $style->getColor()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Style/Image.php: -------------------------------------------------------------------------------- 1 | getStyle(); 34 | if (!$style instanceof \PhpOffice\PhpWord\Style\Indentation) { 35 | return; 36 | } 37 | $xmlWriter = $this->getXmlWriter(); 38 | 39 | $xmlWriter->startElement('w:ind'); 40 | 41 | $xmlWriter->writeAttribute('w:left', $this->convertTwip($style->getLeft())); 42 | $xmlWriter->writeAttribute('w:right', $this->convertTwip($style->getRight())); 43 | 44 | $firstLine = $style->getFirstLine(); 45 | $xmlWriter->writeAttributeIf(null !== $firstLine, 'w:firstLine', $this->convertTwip($firstLine)); 46 | 47 | $firstLineChars = $style->getFirstLineChars(); 48 | $xmlWriter->writeAttributeIf(0 !== $firstLineChars, 'w:firstLineChars', $this->convertTwip($firstLineChars)); 49 | 50 | $hanging = $style->getHanging(); 51 | $xmlWriter->writeAttributeIf(null !== $hanging, 'w:hanging', $this->convertTwip($hanging)); 52 | 53 | $xmlWriter->endElement(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Style/LineNumbering.php: -------------------------------------------------------------------------------- 1 | getStyle(); 35 | if (!$style instanceof \PhpOffice\PhpWord\Style\LineNumbering) { 36 | return; 37 | } 38 | $xmlWriter = $this->getXmlWriter(); 39 | 40 | $xmlWriter->startElement('w:lnNumType'); 41 | $xmlWriter->writeAttribute('w:start', $style->getStart() - 1); 42 | $xmlWriter->writeAttribute('w:countBy', $style->getIncrement()); 43 | $xmlWriter->writeAttribute('w:distance', $style->getDistance()); 44 | $xmlWriter->writeAttribute('w:restart', $style->getRestart()); 45 | $xmlWriter->endElement(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Style/Outline.php: -------------------------------------------------------------------------------- 1 | getStyle(); 34 | if (!$style instanceof \PhpOffice\PhpWord\Style\Outline) { 35 | return; 36 | } 37 | $xmlWriter = $this->getXmlWriter(); 38 | 39 | $xmlWriter->startElement('v:stroke'); 40 | $xmlWriter->writeAttribute('on', 't'); 41 | $xmlWriter->writeAttributeIf($style->getColor() !== null, 'color', $style->getColor()); 42 | $xmlWriter->writeAttributeIf($style->getWeight() !== null, 'weight', $style->getWeight() . $style->getUnit()); 43 | $xmlWriter->writeAttributeIf($style->getDash() !== null, 'dashstyle', $style->getDash()); 44 | $xmlWriter->writeAttributeIf($style->getLine() !== null, 'linestyle', $style->getLine()); 45 | $xmlWriter->writeAttributeIf($style->getEndCap() !== null, 'endcap', $style->getEndCap()); 46 | $xmlWriter->writeAttributeIf($style->getStartArrow() !== null, 'startarrow', $style->getStartArrow()); 47 | $xmlWriter->writeAttributeIf($style->getEndArrow() !== null, 'endarrow', $style->getEndArrow()); 48 | $xmlWriter->endElement(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Style/Row.php: -------------------------------------------------------------------------------- 1 | getStyle(); 39 | if (!$style instanceof \PhpOffice\PhpWord\Style\Row) { 40 | return; 41 | } 42 | 43 | $xmlWriter = $this->getXmlWriter(); 44 | $xmlWriter->startElement('w:trPr'); 45 | 46 | if ($this->height !== null) { 47 | $xmlWriter->startElement('w:trHeight'); 48 | $xmlWriter->writeAttribute('w:val', $this->height); 49 | $xmlWriter->writeAttribute('w:hRule', ($style->isExactHeight() ? 'exact' : 'atLeast')); 50 | $xmlWriter->endElement(); 51 | } 52 | $xmlWriter->writeElementIf($style->isTblHeader(), 'w:tblHeader', 'w:val', '1'); 53 | $xmlWriter->writeElementIf($style->isCantSplit(), 'w:cantSplit', 'w:val', '1'); 54 | 55 | $xmlWriter->endElement(); // w:trPr 56 | } 57 | 58 | /** 59 | * Set height. 60 | * 61 | * @param int $value 62 | */ 63 | public function setHeight($value = null): void 64 | { 65 | $this->height = $value; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Style/Shading.php: -------------------------------------------------------------------------------- 1 | getStyle(); 34 | if (!$style instanceof \PhpOffice\PhpWord\Style\Shading) { 35 | return; 36 | } 37 | $xmlWriter = $this->getXmlWriter(); 38 | 39 | $xmlWriter->startElement('w:shd'); 40 | $xmlWriter->writeAttributeIf(null !== $style->getPattern(), 'w:val', $style->getPattern()); 41 | $xmlWriter->writeAttributeIf(null !== $style->getColor(), 'w:color', $style->getColor()); 42 | $xmlWriter->writeAttributeIf(null !== $style->getFill(), 'w:fill', $style->getFill()); 43 | $xmlWriter->endElement(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Style/Shadow.php: -------------------------------------------------------------------------------- 1 | getStyle(); 34 | if (!$style instanceof \PhpOffice\PhpWord\Style\Shadow) { 35 | return; 36 | } 37 | $xmlWriter = $this->getXmlWriter(); 38 | 39 | $xmlWriter->startElement('v:shadow'); 40 | $xmlWriter->writeAttribute('on', 't'); 41 | $xmlWriter->writeAttributeIf($style->getColor() !== null, 'color', $style->getColor()); 42 | $xmlWriter->writeAttributeIf($style->getOffset() !== null, 'offset', $style->getOffset()); 43 | $xmlWriter->endElement(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Style/Shape.php: -------------------------------------------------------------------------------- 1 | getStyle(); 34 | if (!$style instanceof \PhpOffice\PhpWord\Style\Shape) { 35 | return; 36 | } 37 | 38 | $xmlWriter = $this->getXmlWriter(); 39 | 40 | $childStyles = ['Frame', 'Fill', 'Outline', 'Shadow', 'Extrusion']; 41 | foreach ($childStyles as $childStyle) { 42 | $method = "get{$childStyle}"; 43 | $this->writeChildStyle($xmlWriter, $childStyle, $style->$method()); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Style/Spacing.php: -------------------------------------------------------------------------------- 1 | getStyle(); 34 | if (!$style instanceof \PhpOffice\PhpWord\Style\Spacing) { 35 | return; 36 | } 37 | $xmlWriter = $this->getXmlWriter(); 38 | 39 | $xmlWriter->startElement('w:spacing'); 40 | 41 | $before = $style->getBefore(); 42 | $xmlWriter->writeAttributeIf(null !== $before, 'w:before', $this->convertTwip($before)); 43 | 44 | $after = $style->getAfter(); 45 | $xmlWriter->writeAttributeIf(null !== $after, 'w:after', $this->convertTwip($after)); 46 | 47 | $line = $style->getLine(); 48 | //if linerule is auto, the spacing is supposed to include the height of the line itself, which is 240 twips 49 | if (null !== $line && 'auto' === $style->getLineRule()) { 50 | $line += \PhpOffice\PhpWord\Style\Paragraph::LINE_HEIGHT; 51 | } 52 | $xmlWriter->writeAttributeIf(null !== $line, 'w:line', $line); 53 | 54 | $xmlWriter->writeAttributeIf(null !== $line, 'w:lineRule', $style->getLineRule()); 55 | 56 | $xmlWriter->endElement(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Style/Tab.php: -------------------------------------------------------------------------------- 1 | getStyle(); 34 | if (!$style instanceof \PhpOffice\PhpWord\Style\Tab) { 35 | return; 36 | } 37 | $xmlWriter = $this->getXmlWriter(); 38 | 39 | $xmlWriter->startElement('w:tab'); 40 | $xmlWriter->writeAttribute('w:val', $style->getType()); 41 | $xmlWriter->writeAttribute('w:leader', $style->getLeader()); 42 | $xmlWriter->writeAttribute('w:pos', $this->convertTwip($style->getPosition())); 43 | $xmlWriter->endElement(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Style/TablePosition.php: -------------------------------------------------------------------------------- 1 | getStyle(); 32 | if (!$style instanceof \PhpOffice\PhpWord\Style\TablePosition) { 33 | return; 34 | } 35 | 36 | $values = []; 37 | $properties = [ 38 | 'leftFromText', 39 | 'rightFromText', 40 | 'topFromText', 41 | 'bottomFromText', 42 | 'vertAnchor', 43 | 'horzAnchor', 44 | 'tblpXSpec', 45 | 'tblpX', 46 | 'tblpYSpec', 47 | 'tblpY', 48 | ]; 49 | foreach ($properties as $property) { 50 | $method = 'get' . $property; 51 | if (method_exists($style, $method)) { 52 | $values[$property] = $style->$method(); 53 | } 54 | } 55 | $values = array_filter($values); 56 | 57 | if ($values) { 58 | $xmlWriter = $this->getXmlWriter(); 59 | $xmlWriter->startElement('w:tblpPr'); 60 | foreach ($values as $property => $value) { 61 | $xmlWriter->writeAttribute('w:' . $property, $value); 62 | } 63 | $xmlWriter->endElement(); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/Word2007/Style/TextBox.php: -------------------------------------------------------------------------------- 1 | getStyle(); 34 | if (!$style instanceof TextBoxStyle || !$style->hasInnerMargins()) { 35 | return; 36 | } 37 | 38 | $xmlWriter = $this->getXmlWriter(); 39 | $margins = implode(', ', $style->getInnerMargin()); 40 | 41 | $xmlWriter->writeAttribute('inset', $margins); 42 | } 43 | 44 | /** 45 | * Writer border. 46 | */ 47 | public function writeBorder(): void 48 | { 49 | $style = $this->getStyle(); 50 | if (!$style instanceof TextBoxStyle) { 51 | return; 52 | } 53 | $xmlWriter = $this->getXmlWriter(); 54 | 55 | $xmlWriter->startElement('v:stroke'); 56 | $xmlWriter->writeAttributeIf($style->getBorderSize() !== null, 'weight', $style->getBorderSize() . 'pt'); 57 | $xmlWriter->writeAttributeIf($style->getBorderColor() !== null, 'color', $style->getBorderColor()); 58 | $xmlWriter->endElement(); // v:stroke 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/PhpWord/Writer/WriterInterface.php: -------------------------------------------------------------------------------- 1 |
' . $this->parentWriter->escapeHTML($this->element->getTextObject()->getText()) . '