linux中打开pdf文件_在Linux中减少PDF文件大小

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.pdfinput.pdf

The various tweaks to the -dPDFSETTINGS option are provided in the table below. Use them according to your need.

下表提供了-dPDFSETTINGS选项的各种调整。 根据需要使用它们。

-dPDFSETTINGS OptionDescription
-dPDFSETTINGS=/screenHas a lower quality and smaller size. (72 dpi)
-dPDFSETTINGS=/ebookHas a better quality, but has a slightly larger size (150 dpi)
-dPDFSETTINGS=/prepressOutput is of a higher size and quality (300 dpi)
-dPDFSETTINGS=/printerOutput is of a printer type quality (300 dpi)
-dPDFSETTINGS=/defaultSelects 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!

我用上面的命令来实现压缩从73MB14MB!

Ghostscript Reduce Pdf Size
Ghostscript Reduce Pdf Size
Ghostscript缩小Pdf大小


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

Ps2pdf Reduce Pdf Size
Ps2pdf Reduce Pdf Size
Ps2pdf缩小Pdf大小


用于在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
Densify Gui Utility
Densify Gui Utility
致密Gui Utility

You can now compress as many PDF files as you need, using a GUI!

现在,您可以使用GUI压缩所需数量的PDF文件!



参考资料 (References)



翻译自: https://www.journaldev.com/34668/reduce-pdf-file-size-in-linux

linux中打开pdf文件

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值