Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using addHtml function, the width of the image is not measured in pt #2589

Open
xfstu opened this issue Mar 20, 2024 · 0 comments
Open

Comments

@xfstu
Copy link

xfstu commented Mar 20, 2024

Describe the Bug

Hi, hello. When I tried to convert HTML to docx, I found that the width of the image was not the expected width. So, I decompressed the docx and opened document.xml. I found that the width of the image is pixels (px), which makes the document see different image widths when opened on computers with different resolutions. So I tried to search for documents and the internet, but only saw that the unit of image width written in the development document was pt. So I looked up the source code of PHPWord and found that in PhpOffice\PhpWord\Shared\Html, the units for width and height in lines 903 and 909 are UNIT-PX. Why is it that the unit in the source code is UNIT-PX instead of UNIT-PT (as stated in the development documentation, the unit is pt)? Is there any other consideration for writing this way? Or can this be considered a bug?
Also, I would like to know how to set the width of an image to the width of A4 paper. My English level is not very good. Thank you for taking the time to read my question. Thank you very much for your help!

Steps to Reproduce

php

<?php
require __DIR__ . '/vendor/autoload.php';

use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\Html;
$word = new PhpWord();
$content = $word->addSection();
$html = new Html();
$html::addHtml($content, "<p style='color:#FF4400'>test</p><p><img src='http://domain.com/20240320213223.jpg' width='449.25pt'/></p>", false, true);
$word->save('test.docx');

Expected Behavior

Expected: The width of the image is 449.25pt.

Current Behavior

The content of document.xml:

<v:shape type="#_x0000_t75" stroked="f" style="width:904px; height:574px;...

I omitted some of the code, and what is expected here is "<v: shape type=" # _x0000_t75 "stroke=" f "style=" width: 449.25pt; "; Height: 574pt “

Context

Please fill in your environment information:

  • PHP Version:7.4
  • PHPWord Version:1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant