首页 > 在 Linux 中,如何通过命令使用 Chrome 打开 PDF 文件?

在 Linux 中,如何通过命令使用 Chrome 打开 PDF 文件?

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

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

谢谢!


要有pdf扩展
然后
chromium path (path是你pdf文件路径+文件名)


如果你用Linux,用下我这个脚本:

#! /bin/bash

chrome_command="google-chrome"

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

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

# if the file exist, open the file with chrome
if [ -z "$absolute_path" ]; then
    echo "$1 does not exist!"
    exit 1
else
    file_url="file://$absolute_path"
    $chrome_command "$file_url"
fi
  1. 你把这个脚本存为 chrome-file,
  2. 赋予它执行权限: chmod +x chrome-file
  3. 然后把它放入一个可执行的路径,如: sudo cp chrome-file /usr/local/bin
  4. 然后,你就可以用 chrome-file <file>,只需给出文件的相对路径,就可以在chrome中打开文件了, 支持的文件类型包括html, pdf, txt, 图片等。
  5. 如果你指定的文件不存在,命令会告诉你文件不存在。

Try it!

【热门文章】
【热门文章】