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

docx 文档里有图片的话 显示错位了 #249

Open
Mrmore opened this issue Mar 18, 2024 · 6 comments
Open

docx 文档里有图片的话 显示错位了 #249

Mrmore opened this issue Mar 18, 2024 · 6 comments

Comments

@Mrmore
Copy link

Mrmore commented Mar 18, 2024

"@vue-office/docx": "^1.6.0",
老大我又来了 这次是 docx 的问题
567
化肥运行部召开2024年3月份培训例会.docx

@Mrmore
Copy link
Author

Mrmore commented Mar 18, 2024

@501351981 是不是 npm install docx-preview 库的问题呢

@501351981
Copy link
Owner

嗯呢 是的,这个我也解决不了

@Mrmore
Copy link
Author

Mrmore commented Mar 20, 2024

@501351981 感谢呢 我还发现一个问题 在 VolodymyrBaydalka/docxjs#102 我也提出这个问题了,感兴趣可以看一下 谢谢呢

@pingan8787
Copy link

pingan8787 commented Mar 22, 2024

我也遇到相同问题,我解决的方法是将页面 pt 单位全部改成 px(也可以指定某个元素下的所有单位),然后将 img 的宽度和高度改成 100%,方法比较暴力,但是目前使用是没有问题。代码如下:

  const resetStyle = () => {
    const elements = document.querySelectorAll('[style*="pt"]');
    for (const element of elements) {
      const style = element.getAttribute('style');
      if (!!style) {
        element.setAttribute('style', style.replace(/pt/g, 'px'));
      }
    }
  };
img {
  width: 100% !important;
  height: 100% !important;
}

@Mrmore
Copy link
Author

Mrmore commented Mar 22, 2024

@pingan8787 我试试看您的代码 , 我又发现了一个新问题 不知道您遇到没 是docx 里源数据 出现的<w:ind w:left="31680" w:hanging="414" w:hangingChars="150"/> w:left="31680" 但是word 软件 里看格式没问题,但是源 xml 就有个w:left="31680" 导致 库 解析后 就 看不到···· 暴力解决去掉 或者 改小 我都觉得不合适
集团公司“三基”工作宣贯推进会经验交流材料.docx 目录那个

@Mrmore
Copy link
Author

Mrmore commented Mar 22, 2024

@pingan8787 感谢这个帖子也回复了 还有 docxjs 那边也回复了 图片这个问题,word 重写 改改 图片 如果 渲染 出来是DIV包裹 图片 就不会错误, 如果是 svg 下 包裹 img 就会 找不准 位置 补充 说明一下 我试了一下 代码 好像不行 您可以试一下我这个文档 https://github.com/501351981/vue-office/files/14634757/2024.3.docx 如果用您的代码 没问题,那就是我写的有问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants