【问题标题】:Missing image in pdf generated by html-pdfhtml-pdf生成的pdf中缺少图像
【发布时间】:2020-05-19 20:06:42
【问题描述】:

我正在使用 HTML-pdf 库将 HTML 页面转换为 pdf。我得到了 pdf 上的动态部分,但据报道该图像丢失了。我尝试使用一次性的所有方法,但是,图像没有出现在生成的 pdf 中。我该怎么办?下面是我的 HTML 模板:

<head>
    <title>Certificate</title>
    <!-- <link rel="stylesheet" href="../stuff/certificate.css"> -->
    <style>
        html,
body {
      height: 100%;
      width: 100%;
      }


img{
    height: 100%;
    width: 100%;
    margin:0px;
    }

    #name{
    margin-top:-420px;
    margin-left: 60px;
    }

  p{
    font-size:40px;
    color:black;
    font-weight:400;
    text-align: center;
  }
</style>
</head>
<body>
    <img src="../stuff/certificate.jpg">
    <div id="name"><p><%=name%></p></div>
</body>
</html>

我按照自己的意愿获得了名称,但是图像根本没有出现。请帮忙。与 html 相比,该图像位于不同的文件夹中。

【问题讨论】:

  • 您是否尝试按照GitHub repository中的示例进行操作?
  • 是的,我把img的src改成了"",但是也失败了。

标签: html css node.js image html-pdf


【解决方案1】:

尝试使用JS library that detect when images have been loaded.

你可以这样使用它:

<script src="https://npmcdn.com/imagesloaded@4.1/imagesloaded.pkgd.min.js"></script>

<script type="text/javascript">
  imagesLoaded(document.body, function() {
    window.print();
  });
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-27
    • 2015-09-26
    • 2014-05-02
    • 2022-10-05
    • 2015-07-17
    • 2018-09-24
    • 1970-01-01
    相关资源
    最近更新 更多