PHPWord和图像的宽度

时间:2018-01-24 07:54:23

标签: phpword

    $phpWord = new PhpWord();
    $section = $phpWord->addSection();
    \PhpOffice\PhpWord\Shared\Html::addHtml($section, '<table style="width:100%"><tr><td><img src="https://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg" style="width: 20px;"/></td><td>text</td></tr></table>');

    $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
    $objWriter->save($docx);

在这种情况下,PhpWord显示全尺寸图像,并忽略图像宽度

如何修复?

1 个答案:

答案 0 :(得分:0)

HTML解析器似乎不了解css样式。 将宽度作为属性传递

的工作原理是什么
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
\PhpOffice\PhpWord\Shared\Html::addHtml($section, '<table style="width:100%"><tr><td><img src="https://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg" width="200"/></td><td>text</td></tr></table>');

上面的代码对我有用。至少用0.14,用Word 2016打开word文档。