node.js 如何在 Chromium 中打开 PDF 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15067645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 13:41:47  来源:igfitidea点击:

How To Open PDF Files Inside Chromium?

javascriptnode.jsgoogle-chromechromiumappjs

提问by Sankar V

I'm using nodejs and chromium for my desktop app. The problem is that I can't open pdf files in chromium. So I googled and found that most of the answers are related to mozplugger plugin. I installed the plugin as mentioned in the below link:

我正在为我的桌面应用程序使用 nodejs 和 Chrome。问题是我无法在 Chrome 中打开 pdf 文件。于是我google了一下,发现大部分答案都与mozplugger插件有关。我安装了以下链接中提到的插件:

http://www.tootips.com/2013/01/how-to-open-pdf-files-inside-chromium.html

http://www.tootips.com/2013/01/how-to-open-pdf-files-inside-chromium.html

Now I'm getting an error message : "Mozplugger: M4 parsing of config generated error" when I try to open pdf file in chromium. How can I resolve this error?

现在,当我尝试在Chrome中打开 pdf 文件时,我收到一条错误消息:“ Mozplugger:M4 解析配置生成错误”。我该如何解决这个错误?

Please help me!

请帮我!

采纳答案by Sankar V

In Linux I think we need mozplugger plugin for viewing pdf files. I just removed and installed mozplugger again (Reference links: http://www.tootips.com/2013/01/how-to-open-pdf-files-inside-chromium.html, http://mozplugger.mozdev.org/) and now it seems to work.

在 Linux 中,我认为我们需要 mozplugger 插件来查看 pdf 文件。我只是删除并重新安装mozplugger(参考链接:http://www.tootips.com/2013/01/how-to-open-pdf-files-inside-chromium.htmlhttp://mozplugger.mozdev.org /) 现在它似乎可以工作了。

In windows we need to install a system pdf reader like acrobat (http://www.adobe.com/in/products/reader.html), as chromium downloads and displays pdf with system PDF viewer (Reference link: http://code.google.com/p/chromium/wiki/ChromiumBrowserVsGoogleChrome).

在 Windows 中,我们需要安装一个系统 pdf 阅读器,如 acrobat ( http://www.adobe.com/in/products/reader.html),因为 Chromium 下载并使用系统 PDF 查看器显示 pdf (参考链接:http:// code.google.com/p/chromium/wiki/ChromiumBrowserVsGoogleChrome)。

An alternative solution is to open the pdf link in default browser with help of node.js using below script.

另一种解决方案是在 node.js 的帮助下使用以下脚本在默认浏览器中打开 pdf 链接。

Install the node.js open module:

安装 node.js 打开模块:

$ npm install open

use:

用:

var open = require('open');
open('http://www.google.com', function (err) {
  if (err) throw err;
  console.log('The user closed the browser');
});

Reference link: How to use nodejs to open default browser and navigate to a specific URL

参考链接:如何使用 nodejs 打开默认浏览器并导航到特定 URL

回答by redbmk

If you look at this Ask Ubunutuquestionyou'll see you can actually use Chrome's PDF viewer with Chromium.

如果您查看此Ask Ubunutu问题,您会发现实际上可以将 Chrome 的 PDF 查看器与 Chromium 结合使用。

Chrome has a nice PDF plugin that lets you open in the page, but it's not open source so it's not included with Chromium. You could install Chrome and symlink the plugin, then whenever you update Chrome you would also get that updated in Chromium. Alternatively, you could copy the plugin over to Chromium, and uninstall Chrome, but you won't receive updates that way.

Chrome 有一个不错的 PDF 插件,可以让你在页面中打开,但它不是开源的,所以它不包含在 Chromium 中。你可以安装 Chrome 并符号链接插件,然后每当你更新 Chrome 时,你也会在 Chromium 中更新。或者,您可以将插件复制到 Chromium,然后卸载 Chrome,但您不会以这种方式收到更新。

回答by sihorton

Have you tried using PDFjs as a totally javascript based alternative solution?

您是否尝试过使用 PDFjs 作为完全基于 javascript 的替代解决方案?

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

It is relatively new but works on many different examples, maybe it is good enough for your application.

它相对较新,但适用于许多不同的示例,也许它对您的应用程序来说已经足够了。

回答by Han Tuzun

You can use this extension by Google: ExtensionDocs PDF/PowerPoint Viewerwhich also allows you to open docx, ppt, rar and many more file types.

您可以使用 Google 提供的此扩展程序:ExtensionDocs PDF/PowerPoint Viewer,它还允许您打开 docx、ppt、rar 和更多文件类型。

回答by Vladimir

Google recently announcedthat Google Chrome PDF Viewer goes to open source. It means that in near future Chromium browser and Chromium OS users can soon enjoy the Chrome PDF viewer, without any workarounds!

谷歌最近宣布谷歌 Chrome PDF 查看器开源。这意味着在不久的将来,Chromium 浏览器和 Chromium OS 用户可以很快享受 Chrome PDF 查看器,无需任何解决方法!

See PDFium project web page at https://code.google.com/p/pdfium/

请参阅https://code.google.com/p/pdfium/ 上的PDFium 项目网页