【问题标题】:how to print pdf inside embed/iframe using javascript如何使用 javascript 在 embed/iframe 中打印 pdf
【发布时间】:2011-11-21 14:17:27
【问题描述】:

又是我。不幸的是,我们公司不想购买柔版纸。对我不利,我必须找到一种替代方法来在嵌入标签/iframe 中打印 pdf。

对于我的第一个问题,我有以下代码:

<script>
    function printTrigger(elementId) {
       var getMyFrame = document.getElementById(elementId);
       getMyFrame.focus();
       getMyFrame.contentWindow.print();
    }
</script>

使用 iframe :

<iframe id="mypdf" src="data/sampledocument.pdf" width="60%" style="height:10em"align="right">

当我尝试通过按钮触发 printTrigger 功能时,打印 pdf 作品(即或 firefox)。我的问题是当我更改 pdf 的 src 属性时,此代码不起作用。 pdf 的来源来自不同的 web 目录参见下面的示例

<iframe id="mypdf" src="../../ViewPDF.aspx?filetype=r3fileserver&amp;nameoffile=Certificate/2011\2011010000035-preview.pdf" width="60%"
style="height:10em" align="right">

在 iframe 中查看 pdf 后,浏览器会询问我是否要打开或保存它。有人可以告诉我如何强制 pdf 在 iframe 内查看吗?或者这是不可能的,因为有来自不同的 web dir / pdf 来自 apsx?

对于我的第二个问题,有人可以帮我提供可在 firefox 中使用的 printWithDialog 替代代码吗?

非常感谢!

希望收到你们的来信!

【问题讨论】:

  • 请分别发布多个问题;你会得到更好的回应。
  • 您是否通过 ViewPDF 为 pdf(应用程序/pdf)发送了正确的 mimeType?
  • @maerics - 对不起。我怎样才能删除这个帖子?

标签: javascript pdf iframe embed


【解决方案1】:

我认为您的问题是浏览器没有将资源识别为 PDF,因此您应该将内容类型标头设置为 application/pdf。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-19
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多