Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion src/PhpWord/Reader/Word2007/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,32 @@ protected function readParagraph(XMLReader $xmlReader, DOMElement $domNode, $par
}
$parent->addPreserveText(htmlspecialchars($textContent, ENT_QUOTES, 'UTF-8'), $fontStyle, $paragraphStyle);

return;
} elseif ($xmlReader->elementExists('w:r/w:pict/v:shape/v:textbox', $domNode)) {
//textbox
$shapeStyle=null;
$styleVal = $xmlReader->getAttribute('style', $domNode, 'w:r/w:pict/v:shape');
if ($styleVal!=null){
$shapeStyle=[];
foreach (explode(';', $styleVal) as $attribute){
if (!empty($attribute)){
[$attributeKey,$attributeVal] = explode(':',$attribute);
$attributeKey = str_replace('-', ' ', $attributeKey);
$attributeKey = ucwords($attributeKey);
$attributeKey = str_replace(' ', '', $attributeKey);
$attributeVal = preg_replace('/\s*pt\s*/', '', $attributeVal);
$shapeStyle[$attributeKey]=$attributeVal;
}
}
}
if (is_array($paragraphStyle) && count($paragraphStyle)>0){
$shapeStyle = array_merge($shapeStyle, $paragraphStyle);
}
$textBox = $parent->addTextBox($shapeStyle);
$nodes = $xmlReader->getElements('w:r/w:pict/v:shape/v:textbox/w:txbxContent/*', $domNode);
foreach ($nodes as $node){
$this->readParagraph($xmlReader,$node,$textBox,$docPart);
}
return;
}

Expand Down Expand Up @@ -509,6 +535,21 @@ protected function readRunChild(XMLReader $xmlReader, DOMElement $node, Abstract
$endnote = $parent->addEndnote();
$endnote->setRelationId($wId);
} elseif ($node->nodeName == 'w:pict') {
$shapeStyle=null;
$styleVal = $xmlReader->getAttribute('style', $node, 'v:shape');
if ($styleVal!=null){
$shapeStyle=[];
foreach (explode(';', $styleVal) as $attribute){
if (!empty($attribute)){
[$attributeKey,$attributeVal] = explode(':',$attribute);
$attributeKey = str_replace('-', ' ', $attributeKey);
$attributeKey = ucwords($attributeKey);
$attributeKey = str_replace(' ', '', $attributeKey);
$attributeVal = preg_replace('/\s*pt\s*/', '', $attributeVal);
$shapeStyle[$attributeKey]=$attributeVal;
}
}
}
// Image
$rId = $xmlReader->getAttribute('r:id', $node, 'v:shape/v:imagedata');
$target = $this->getMediaTarget($docPart, $rId);
Expand All @@ -518,7 +559,7 @@ protected function readRunChild(XMLReader $xmlReader, DOMElement $node, Abstract
} else {
$imageSource = "zip://{$this->docFile}#{$target}";
}
$parent->addImage($imageSource);
$parent->addImage($imageSource,$shapeStyle);
}
} elseif ($node->nodeName == 'w:drawing') {
// Office 2011 Image
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Writer/AbstractWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ protected function addFileToPackage($zipPackage, $source, $target): void

$zip = new ZipArchive();
if ($zip->open($zipFilename) !== false) {
if ($zip->locateName($imageFilename)) {
if ($zip->locateName($imageFilename) !== false) {
$zip->extractTo($this->getTempDir(), $imageFilename);
$actualSource = $this->getTempDir() . DIRECTORY_SEPARATOR . $imageFilename;
}
Expand Down
Loading