linux中打开pdf文件
In our Linux system, If we have a large PDF file, we may want to reduce it’s size. We shall look at different ways to reduce PDF size or compress PDF files in Linux in this tutorial.
在我们的Linux系统中,如果我们有一个很大的PDF文件,我们可能想减小它的大小。 在本教程中,我们将探讨在Linux中减小PDF大小或压缩PDF文件的不同方法。
Let’s find out some Command Line and GUI methods to deal with this problem.
让我们找出一些命令行和GUI方法来解决此问题。
命令行实用程序,可在Linux中减少PDF文件的大小 (Command Line Utilities to Reduce PDF File Size in Linux)
1.使用GhostScript (1. Using GhostScript)
We can use the ghostscript
command line utility in Linux to compress PDFs.
我们可以在Linux中使用ghostscript
命令行实用程序来压缩PDF。
If the command is not available in your machine, you can install it using your package manager.
如果该命令在您的计算机中不可用,则可以使用软件包管理器进行安装。
For example, in Ubuntu, you can use apt
:
例如,在Ubuntu中,您可以使用apt
:
sudo apt install ghostscript
You can use this magic command to compress PDFs to a readable quality.
您可以使用此魔术命令将PDF压缩到可读的质量。
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
Here, replace output.pdf
and input.pdf
accordingly.
在此,相应地替换output.pdf
和input.pdf
。
The various tweaks to the -dPDFSETTINGS
option are provided in the table below. Use them according to your need.
下表提供了-dPDFSETTINGS
选项的各种调整。 根据需要使用它们。
-dPDFSETTINGS Option | Description |
-dPDFSETTINGS=/screen | Has a lower quality and smaller size. (72 dpi) |
-dPDFSETTINGS=/ebook | Has a better quality, but has a slightly larger size (150 dpi) |
-dPDFSETTINGS=/prepress | Output is of a higher size and quality (300 dpi) |
-dPDFSETTINGS=/printer | Output is of a printer type quality (300 dpi) |
-dPDFSETTINGS=/default | Selects the output which is useful for multiple purposes. Can cause large PDFS. |
-dPDFSETTINGS选项 | 描述 |
-dPDFSETTINGS=/screen | 具有较低的质量和较小的尺寸。 ( 72像素 ) |
-dPDFSETTINGS=/ebook | 质量较好,但尺寸稍大( 150 dpi ) |
-dPDFSETTINGS=/prepress | 输出的尺寸和质量更高( 300 dpi ) |
-dPDFSETTINGS=/printer | 输出的是打印机类型的质量( 300 dpi ) |
-dPDFSETTINGS=/default | 选择对多种用途有用的输出。 可能会导致大型PDFS。 |
I have used the above command to achieve a compression from 73MB to 14MB!
我用上面的命令来实现压缩从73MB到14MB!

2.使用ps2pdf (2. Use ps2pdf)
This command ps2pdf
converts a PDF to PS and then again back, compressing it efficiently as a result.
此命令ps2pdf
将PDF转换为PS,然后再次转换回PS,从而有效地对其进行压缩。
It may not always work, but it can give very good results.
它可能并不总是有效,但可以带来很好的效果。
Format:
格式 :
ps2pdf input.pdf output.pdf
It is recommended that you use the -dPDFSETTINGS=/ebooks
setting to get the best performance, as ebooks have the best size for readability and also are small enough in size.
建议使用-dPDFSETTINGS=/ebooks
设置以获得最佳性能,因为电子书具有最佳的可读性,而且尺寸也足够小。
ps2pdf -dPDFSETTINGS=/ebook input.pdf output.pdf
I have tried this on a 73MB PDF and it had the same results as the ghostscript
command, the compressed PDF having only 14MB!
我已经在73MB的 PDF上进行了尝试 ,它的结果与ghostscript
命令相同,压缩后的PDF只有14MB !

用于在Linux中减少PDF文件大小的GUI实用程序 (GUI Utilities to Reduce PDF File Size in Linux)
If you are uncomfortable with using command line tools, there is a GUI alternative as well.
如果您对使用命令行工具感到不舒服,也可以选择使用GUI。
致密化 (Densify)
This is a GUI front end to ghostscript
, which can be installed in any Linux distribution, since it uses Python3
and it’s GTK
modules.
这是ghostscript
的GUI前端,可以将它安装在任何Linux发行版中,因为它使用的是Python3
及其GTK
模块。
This package is called Densify, and is available here(Link to github).
这个包叫做Densify ,可以在这里找到(链接到github)。
I have created a simple bash
script to do all the necessary work. Run this bash script as root, to link and download necessary files.
我创建了一个简单的bash
脚本来完成所有必要的工作。 以超级用户身份运行此bash脚本,以链接和下载必要的文件。
#!/bin/bash
#- HELPER SCRIPT FOR DENSIFY
#- original package https://github.com/hkdb/Densify
#- script author Vijay Ramachandran
#- site https://journaldev.com
#-
# Go to your home directory (preferred)
cd $HOME
# Download the package
git clone https://github.com/hkdb/Densify
cd Densify
# Queue must be changed to queue in the file.
# Will not work otherwise
sed -i 's/Queue/queue/g' $PWD/densify
# Create the symlink to /opt
sudo ln -s $PWD /opt/Densify
# Perform the install
cd /opt/Densify
sudo chmod 755 install.sh
sudo ./install.sh
# Export to PATH
if [ $SHELL == "/bin/zsh" ]; then
if test -f $HOME/.zshrc; then
echo 'export PATH=/opt/Densify:$PATH' >> $HOME/.zshrc
source $HOME/.zshrc
else
echo "No zshrc Found! Please create a zsh config file and try again"
fi
else
if [ $SHELL == "/bin/bash" ]; then
if test -f $HOME/.bashrc; then
echo 'export PATH=/opt/Densify:$PATH' >> $HOME/.bashrc
source $HOME/.bashrc
else
if test -f $HOME/.bash_profile; then
echo 'export PATH=/opt/Densify:$PATH' >> $HOME/.bash_profile
source $HOME/.bash_profile
else
echo "No bashrc Found! Please create a bash config file and try again"
fi
fi
else
echo "Default Shell is not zsh or bash. Please add /opt/Densify to your PATH"
fi
fi
If there are no errors, you are good to go! Simply type the below command from opt/densify
to invoke the GUI, or open it from your dashboard.
如果没有错误,那就很好了! 只需在opt/densify
键入以下命令以调用GUI,或从仪表板中将其打开。
densify

You can now compress as many PDF files as you need, using a GUI!
现在,您可以使用GUI压缩所需数量的PDF文件!
参考资料 (References)
- StackOverflow question on reducing PDF size 关于减少PDF大小的StackOverflow问题
翻译自: https://www.journaldev.com/34668/reduce-pdf-file-size-in-linux
linux中打开pdf文件