【问题标题】:Fire print handler of embed html element嵌入 html 元素的触发打印处理程序
【发布时间】:2015-08-03 11:36:40
【问题描述】:

我得到一个 pdf 作为 base64 字符串,用作嵌入 html 元素的来源。

<embed id="pdf-embed" src="data:application/pdf;base64,B64STR"></embed>

它是由浏览器通过其 pdf 视图插件打开的,但我怎样才能开始在 javascript 中打印此 pdf 文档?

例如:

$('document').ready(function() {
    $('#pdf-embed').print();
});

此代码不起作用,因为似乎 embed 没有它的打印功能。

【问题讨论】:

    标签: javascript html pdf embed


    【解决方案1】:

    如果有人遇到和我一样的问题:

    我使用 dompdf 生成 pdf 并触发打印处理程序,您必须在 pdf 的 html 字符串中添加 print()。

    所以你的 html 会像这个例子一样:

    <html>
    <head>..</head>
    <body>
      <h1>Hello world!</h1>
      <script type="text/javascript">print();</script>
    </body>
    </html>
    

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多