search

Home  >  Q&A  >  body text

command-line - 在 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/

谢谢!

ringa_leeringa_lee2786 days ago702

reply all(2)I'll reply

  • 阿神

    阿神2017-04-17 11:28:00

    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!

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 11:28:00

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

    reply
    0
  • Cancelreply