如何使用 Asp.net 禁用谷歌浏览器的"Chrome PDF Viewer"



由于一些不可避免的原因我需要禁用Google Chrome的"Chrome PDF查看器"并启用adob PDF查看器。我想通过C#和asp.net代码来实现这一点我知道这是不可能的,因为这与客户端机器上的更改设置有关,但如果用户想禁用默认查看器,我准备请求用户的许可。

这项工作背后的原因是,由于Chrome的默认阅读器,我在iTextSharp中创建的所有PDF在谷歌Chrome中都无法正常运行。并不是所有的用户都可以手动找到和禁用插件,因此我希望它是由代码完成的。我需要知道如何禁用默认的PDF查看器。一旦这样,我的问题就会自动解决。请给我任何关于代码的建议

只要您将pdf嵌入到html文件中,以下内容可能对您有用
尝试将嵌入的type更改为type="application/vnd.adobe.pdfxml",我知道这不是你的服务,但当我在普通pdf上尝试时,插件没有阻塞,并使用Adobes插件显示pdf,而无需禁用默认(Chromes)阅读器
我不得不在一个有点旧的Adobe插件版本上测试这一点,因为我正在拨号,所以我不想下载一个50多岁的meg文件来进行测试;)。所以你应该在最新的插件上测试它
希望它对你有用。

编辑:
这是一个如何让pdf占据全屏的示例页面,就像你直接指向文件一样
http://pdfobject.com/markup/examples/full-browser-window.html
…这也是我测试的页面。

谷歌chrome插件不会改变编程方式,所以只需像弹出消息一样通知客户端即可

<script type="text/javascript">
function CheckPlugin()
{
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
function findPlugin(ext) {
var thisExt, findExt;
for (var n = 0; n < navigator.plugins.length; n++) {
//alert("n value"+ navigator.plugins.length);
for (var m = 0; m < navigator.plugins[n].length; m++) {
//alert("m length:"+navigator.plugins[n].length);
thisExt = navigator.plugins[n][m].description.toLowerCase();
// alert("this exten"+thisExt);
findExt = thisExt.substring(0, thisExt.indexOf(" "));
//alert("findexes"+findExt);
if (findExt == ext)
return (true);
}
}
return (false);
}
if (is_chrome ==true) {
//alert("chrome browser");
if (findPlugin("acrobat")) {
//alert("Adobe Acrobat pdf viewer");
return true;
}
else {
alert("please disable the chrome pdf viewer and enable the Adobe Acrobat PDF viewer n Please follow the steps:n 1.Open the new tab 'chrome://plugins/' type the Address. n 2. Click the Enable link in 'Adobe Acrobat' field. n 3. click the Disable link in 'Chrome PDF Viewer'. n 4. Close the tab and you can open the PDf files in chrome browser.");
return false;
}
}
else {
//alert("not chrome");
}
}
</script>

在超链接中这样写

<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="~/PDFFiles/AGENCY PROFILE APP.pdf" onclick="return CheckPlugin();">Agency profile app</asp:HyperLink>

我认为这更有帮助。

我使用iTextSharp,当Chrome PDF和Adobe都启用时,Chrome会引发问题。提交按钮会将FDF数据发送回服务器,即使表单指定将数据发送为XFDF。将ContentType设置为"application/vnd.adobe.pdfxml"解决了这个问题。

感谢PAEz。

最新更新