command-line - 在 Linux 中,如何通过命令使用 Chrome 打开 PDF 文件?
ringa_lee
ringa_lee 2017-04-17 11:26:00
0
2
700

Chrome 内置 PDF 浏览功能,在下便打算把它首选为默认 PDF 阅读器,但是在虚拟终端里不知要执行怎样的命令才能通过 Chrome 打开当前目录下的任意 PDF 文件。

假设当前工作目录下有 example.pdf 且 Chrome 的启动命令为 google-chrome,当执行命令 google-chrome example.pdf 时,Chrome 能启动且会新建窗口并尝试载入,但其地址栏是 http://example.pdf/,并非理想的 file:///path/to/example.pdf/

谢谢!

ringa_lee
ringa_lee

ringa_lee

reply all(2)
阿神

If you use Linux, use this script of mine:

#! /bin/bash

chrome_command="google-chrome"

if [ $# -ne 1 ]; then
    echo "Usage: rrreee <pdf-file>"
    exit 1
fi

# get the absolute path of the file
absolute_path=`readlink -e ""`

# if the file exist, open the file with chrome
if [ -z "$absolute_path" ]; then
    echo " does not exist!"
    exit 1
else
    file_url="file://$absolute_path"
    $chrome_command "$file_url"
fi
  1. You save this script as chrome-file,
  2. Give it execution permissions: chmod +x chrome-file,
  3. Then put it into an executable path, such as: sudo cp chrome-file /usr/local/bin.
  4. Then, you can use chrome-file <file> to open the file in chrome by simply giving the relative path to the file. Supported file types include html, pdf, txt, pictures, etc.
  5. If the file you specify does not exist, the command will tell you that the file does not exist.

Try it!

大家讲道理

You need to have pdf extension
and then
chromium path (path is your pdf file path + file name)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template