简体   繁体   English

如何通过程序(例如HTML,JS,PHP)更改浏览器的pdf查看器?

[英]How to change the browsers' pdf viewer through program (e.g. HTML, JS, PHP )?

Goal : A browser base pdf viewer that has zoom and drag/ pan function (better if allow hiding the save function) to replace the browser default one 目标:具有缩放和拖动/平移功能的浏览器基础pdf查看器(如果允许隐藏保存功能,则更好)替换浏览器默认值

Problem : all browser (exclude old IE) has their own build in pdf viewer, that without dragging/pan function 问题:所有浏览器(不包括旧的IE)在pdf查看器中都有自己的构建,没有拖动/平移功能

Currently this code use default pdf viewer: 目前此代码使用默认的pdf查看器:

<object id = 'zoomPage' type='application/pdf' data= '1.pdf'>
   <p>The PDF can not display
   </p>
</object>

Is it possible to force all browser (Chrome , FireFox , IE8+) using the adobe reader to open pdf file using javascript / jquery / html /php? 是否可以使用adobe reader强制所有浏览器(Chrome,FireFox,IE8 +)使用javascript / jquery / html / php打开pdf文件? Or are there any web base pdf viewer has the functions mentioned above? 或者有任何网络基础pdf查看器具有上述功能?

Note: 注意:

For the first approach : 对于第一种方法:

I found the way eg content-disposition : attachment 我找到了例如内容处理的方式:附件

but it only change the behavior from viewing to download the pdf , not changing the preference in opening the pdf file 但它只会改变从查看下载pdf的行为,而不是更改打开pdf文件的首选项

For approach 2: (Which I recommend) Check out: 方法2 :(我推荐)查看:

https://github.com/mozilla/pdf.js/

PDF.js is Portable Document Format (PDF) viewer that is built with HTML5. PDF.js是使用HTML5构建的可移植文档格式(PDF)查看器。

PDF.js is community-driven and supported by Mozilla Labs. PDF.js由社区驱动,并由Mozilla Labs提供支持。 Our goal is to create a general-purpose, web standards-based platform for parsing and rendering PDFs. 我们的目标是创建一个通用的,基于Web标准的平台,用于解析和呈现PDF。

EDIT: For your speed needs, check the discussion on the other options here: Recommended way to embed PDF in HTML? 编辑:为了您的速度需求,请在此处查看其他选项的讨论: 在HTML中嵌入PDF的推荐方法? and see if the other options fit your requirements. 并查看其他选项是否符合您的要求。

Approach 1 is inherently dicey due to security reasons 由于安全原因,方法1本身就是冒险的

The only way you can force it client-side is by supplying the alternative...such as pdf.js, zoho, google pdf viewer, scribd, etc (there are many). 你可以强制客户端的唯一方法是提供替代方案......例如pdf.js,zoho,google pdf viewer,scribd等(有很多)。 I'm not sure if Adobe provides an in-browser pdf viewer like you're expecting. 我不确定Adobe是否提供了您期望的浏览器内pdf查看器。

The default pdf viewer is kept in a variable found in about:config that can only be changed by the user. 默认的pdf查看器保存在about:config中的变量中,该变量只能由用户更改。

Is it possible to force all browser (Chrome , FireFox , IE8+) using the adobe reader to open pdf file using javascript / jquery / html /php? 是否可以使用adobe reader强制所有浏览器(Chrome,FireFox,IE8 +)使用javascript / jquery / html / php打开pdf文件?

You could try this by using an iframe pointing to the pdf file. 您可以通过使用指向pdf文件的iframe来尝试此操作。 The browser will automatically open the pdf file using a pdf reader software on client machine. 浏览器将使用客户端计算机上的pdf阅读器软件自动打开pdf文件。 Like this: 像这样:

<iframe src="yourpdffile" style="width:100%;height:500px"></iframe>

you can't force something on the client for a security issue, but you can check with something like this . 你不能强迫客户端出现安全问题,但你可以检查一下这样的事情 My previous sentence follows by the experience that I have on browsers and coding but maybe I can say something wrong. 我之前的句子遵循我在浏览器和编码方面的经验,但也许我可以说错了。

  1. You can control if there's Adobe Reader using javascript and a code that check if there is the Reader installed with a script like this (I've used these lines months ago and they work) 你可以控制,如果有ADOBE READER使用JavaScript和检查是否有与像脚本安装阅读器代码这个 (我这些线路个月前使用,他们的工作)

  2. Try to use this plugin that maybe is for you pourpose (the first sentence link). 尝试使用这个插件,可能是你的pourpose(第一句话链接)。

You can also use google docs viewer to achieve this functionality. 您还可以使用google docs viewer来实现此功能。

Just refer this link : https://docs.google.com/viewer 请参阅以下链接: https//docs.google.com/viewer

You can get the iframe url and put it in your site. 您可以获取iframe网址并将其放入您的网站。

<iframe src="http://docs.google.com/viewer?url=http%3A%2F%2Fwww.yoursite.com%2Fpdf%2Ftest.pdf&embedded=true" width="600" height="780" style="border: none;"></iframe>

please note that the value of the url parameter in the src is url encoded . 请注意, src url参数的valueurl encoded

Check out the JS Fiddle example here 在这里查看JS Fiddle示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不访问 HTML 的情况下拆分 HTML 页面,例如使用 split.js? - How to split a HTML page without access to the HTML, e.g. using split.js? 如何在特定的JavaScript代码中加载外部HTML页面? 例如,在JS函数中 - How to load an external HTML page within a specific JavaScript code? E.g. Within a JS function 如何更改网站上的滚动行为(例如速度、加速度)? - How to change scroll behavior (e.g. speed, acceleration) on website? 如何在 Google Forms 上使用编程逻辑(例如 JS)? - How to use programming logic (e.g. JS) on Google Forms? 如何在Node.js中从客户端调用服务器端功能(例如html button onclick)? - How to call a server side function from client side (e.g. html button onclick) in Node.js? 浏览器中是否有任何类型的可访问性标题,例如手语 - Is there any kind of accessibility headers in browsers e.g. sign language CKEditor:编辑模板(例如PHP,JSP,ASP等…,即非标准HTML) - CKEditor: Editing templates (e.g. PHP, JSP, ASP, … i.e. non-standard HTML) 修复了无法在旧版移动浏览器上渲染的图像 - Fixed image not rendering on older mobile browsers e.g. blackberry Rails 5-以js或其他格式(例如PDF)呈现表单提交结果 - Rails 5 - Rendering form submission results as js or some other format (e.g. PDF) 如何在移动浏览器的网站上添加pdf查看器 - How to add pdf viewer to website for mobile browsers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM