如何使用javascript在embed / iframe中打印pdf [英] how to print pdf inside embed/iframe using javascript

查看:2280
本文介绍了如何使用javascript在embed / iframe中打印pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我再次。不幸的是,我们公司不想购买弹性纸。对我不好我必须找到一个替代方法,如何在嵌入标签/ iframe中打印pdf。

Me again. Unluckily our company does not want to buy the flexpaper. Bad for me I have to find an alternative on how to print the pdf inside embed tag / iframe.

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

For my first question, i have the following code :

<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的打印工作(ie或firefox) )。我的问题是当我更改pdf的src属性时,此代码不起作用。 pdf的来源来自不同的网络目录请参阅下面的示例

When I try to trigger the printTrigger function thru a button, printing of pdf works (either ie or firefox). My problem is when I change the src property of the pdf this code does not work. the source of the pdf comes from a different web directory see example below

<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中查看?或者这是不可能的,因为来自不同网站的dir / pdf来自apsx?

intead of viewing the pdf inside the iframe, the browser asks if I want to open or save it. Can some please tell me how to force the pdf to view inside the iframe? or this is impossible because there are from different web dir / pdf comes from an apsx?

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

For my second question can someone please help me the alternative code for printWithDialog that will work in firefox?

非常感谢!

希望听到你们的意见!

推荐答案

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

I believe your problem is that the browser is not identifying the resource as a PDF so you should set the content type header to application/pdf.

这篇关于如何使用javascript在embed / iframe中打印pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆