我看到 LibreOffice Draw 应该能够打开一个 pdf 并使用更改质量和 DPI 分辨率的选项将其导出。但是我拥有的高分辨率扫描 pdf 在这个应用程序中没有正确打开(只导入第一页)所以我想找到一个更专业的应用程序。
此时我并没有要求命令行选项(我的 pdf 文件太大了,我以这种方式尝试的所有方法都失败了)。
Glu*_*ate 12
鹦鹉螺脚本
代码
我已经能够使用这个 Nautilus 脚本成功地调整我的 PDF 的大小:
#! /bin/bash
# AUTHOR: (c) Ricardo Ferreira, oriolpont -- modified in accordance to https://askubuntu.com/q/280618/81372
# NAME: Compress PDF 1.4.2
# DESCRIPTION: A nice Nautilus script with a GUI to compress and optimize PDF files
# REQUIRES: ghostscript, poppler-utils, zenity, sed, python-notify (optional)
# LICENSE: GNU GPL v3 (http://www.gnu.org/licenses/gpl.html)
# WEBSITE: https://launchpad.net/compress-pdf
VERSION="1.4.2"
COMPRESSPDF_BATCH_ABORT_ERR=115
# Messages
# English (en-US)
error_nofiles="No file selected."
error_noquality="No optimization level selected."
error_ghostscript="PDF Compress requires the ghostscript package, which is not installed. Please install it and try again."
error_nopdf="At least one of the selected file(s) is not a valid PDF archive."
label_filename="Save PDF as..."
label_level="Please choose an optimization level below."
optimization_level="Optimization Level"
level_default="Default" # apparently close to High Quality
level_screen="Screen-view only (72dpi)"
level_low="Low Quality (150dpi)"
level_high="High Quality (300dpi)"
level_color="High Quality (Color Preserving) (300dpi)"
job_done="has been successfully compressed"
filename_suffix="_opt"
label_suffix="Choose the suffix for the filenames."
warning_overwrite="That will overwrite the original pdf files."
case $LANG in
pt* )
# Portuguese (pt-PT)
error_nofiles="Nenhum ficheiro seleccionado."
error_noquality="Nenhum nível de optimização escolhido."
error_ghostscript="O PDF Compress necessita do pacote ghostscript, que não está instalado. Por favor instale-o e tente novamente."
error_nopdf="O ficheiro seleccionado não é um ficheiro PDF válido."
label_filename="Guardar PDF como..."
label_level="Por favor escolha um nível de optimização abaixo."
optimization_level="Nível de Optimização"
level_default="Normal"
level_screen="Visualização no Ecrã"
level_low="Baixa Qualidade"
level_high="Alta Qualidade"
level_color="Alta Qualidade (Preservação de Cores)"
job_done="foi comprimido com sucesso"
filename_suffix="-otimizado";;
es* )
# Spanish (es-AR) by Eduardo Battaglia
error_nofiles="Ningún archivo seleccionado."
error_noquality="Ningún nivel de optimización escogido."
error_ghostscript="Compress PDF necesita el paquete ghostscript, que no está instalado. Por favor instálelo e intente nuevamente."
label_filename="Guardar PDF como..."
label_level="Por favor escoja un nivel de optimización debajo."
optimization_level="Nivel de Optimización"
level_default="Normal"
level_screen="Sólo visualización"
level_low="Baja calidad"
level_high="Alta calidad"
level_color="Alta calidad (Preservación de Colores)"
filename_suffix="-optimizado";;
cs*)
# Czech (cz-CZ) by Martin Pavlík
error_nofiles="Nebyl vybrán žádný soubor."
error_noquality="Nebyla zvolena úrove? optimalizace."
error_ghostscript="PDF Compress vyžaduje balí?ek ghostscript, který není nainstalován. Nainstalujte jej prosím a opakujte akci."
label_filename="Uložit PDF jako..."
label_level="Prosím vyberte úrove? optimalizace z níže uvedených."
optimization_level="Úrove? optimalizace"
level_default="Výchozí"
level_screen="Pouze pro ?tení na obrazovce"
level_low="Nízká kvalita"
level_high="Vysoká kvalita"
level_color="Vysoká kvalita (se zachováním barev)"
filename_suffix="-optimalizované";;
fr*)
# French (fr-FR) by Astromb
error_nofiles="Aucun fichier sélectionné"
error_noquality="Aucun niveau d'optimisation sélectionné"
error_ghostscript="PDF Compress a besoin du paquet ghostscript, mais il n'est pas installé. Merci de l'installer et d'essayer à nouveau."
error_nopdf="Le fichier que vous avez sélectionné n'est pas un PDF valide."
label_filename="Sauvegarder le PDF sous..."
label_level="Merci de choisir, ci-dessous, un niveau d'optimisation."
optimization_level="Niveau d'optimisation"
level_default="Défaut"
level_screen="Affichage à l'écran"
level_low="Basse qualité"
level_high="Haute qualité"
level_color="Haute qualité (Couleurs préservées)"
filename_suffix="-optimisé";;
zh_CN*)
# Simplified Chinese (zh_CN) by TualatriX Chou
error_nofiles="???????"
error_noquality="?????????"
error_ghostscript="PDF????ghostscript??????????????????????"
error_nopdf="????????????PDF??"
label_filename="???PDF..."
label_level="??????????"
optimization_level="????"
level_default="??"
level_screen="???????"
level_low="???"
level_high="???"
level_color="??????? "
filename_suffix="-??";;
ar*)
# Arabic (ar) by Mohammed hasan Taha
error_nofiles="?? ??? ?????? ???"
error_noquality="?? ??? ?????? ???? ?????"
error_ghostscript="??? ??????? ????? ???? ghostscript package ??? ???? ??????? ?? ????? ????????"
error_nopdf="????? ???? ?? ??????? ??? ??? pdf ????"
label_filename="??? ????? ????"
label_level="?????? ?????? ???? ?????"
optimization_level="???? ?????"
level_default="???????"
level_screen="??? ?????? ???(?????? ?????? ???????)"
level_low="???? ??????"
level_high="???? ??????"
level_color="???? ????? ???"
filename_suffix="-??????";;
ml_IN*)
# Malayalam (ml_IN) by Hrishikesh K B
error_nofiles="??? ????? ????????????????????."
error_noquality="?????? ??????????????? ?????? ????????????????????."
error_ghostscript="?? ?? ??? ???????????? ???????? ???????????? ???????? ?????????. ? ???????? ????????????? ??????? ???? ?????? ??????? ??????????."
error_nopdf="???????????? ????? ??????? ??? ??????? ?????????? ????."
label_filename="??????? ??????? ????????????..."
label_level="?????? ???? ??????? ??? ??????????????? ?????? ??????????????."
optimization_level="??????????????? ?????? "
level_default="???????????"
level_screen="??????????? ??????? ?????? "
level_low="?????? ???????"
level_high="????? ??????? "
level_color="????? ??????? (???? ????????????????????)";;
he*)
# Hebrew (he-IL) by Yaron (from Launchpad question)
error_nofiles="?? ???? ?? ????."
error_noquality="?? ????? ??? ??????."
error_ghostscript="?????? PDF Compress ????? ?? ?????? ghostscript, ????? ??????. ?? ?????? ???? ?????? ???."
error_nopdf="????? ????? ???? ?????? PDF ????."
label_filename="????? ?? PDF ???..."
label_level="?? ????? ?? ??? ?????? ????."
optimization_level="??? ??????"
level_default="???? ????"
level_screen="?????? ??? ????"
level_low="????? ?????"
level_high="????? ?????"
level_color="????? ????? (????? ????)"
job_done="?????? ??????? ??????";;
esac
# Check if Zenity is installed
if ! ZENITY=$(which zenity)
then
echo "error: Compress PDF $VERSION needs zenity to run." # maybe we could translate this someday
exit 1
fi
# Check if Ghostscript is installed
if ! GS=$(which gs)
then
$ZENITY --error --title="Compress PDF $VERSION" --text="$error_ghostscript"
exit 1
fi
# Check if the user has selected any files
# if [ "x$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" = "x" -o "$#" = "0" ] # we double check. Remove the first part if you plan to manually invoke the script
if [ "$#" = "0" ] # removed nautilus specific variable to make the script compatible with other file managers
then
$ZENITY --error --title="Compress PDF $VERSION" --text="$error_nofiles"
exit 1
fi
# Check if we can properly parse the arguments
INPUT=("$@")
N=("$#")
if [ "${#INPUT[@]}" != "$N" ] # comparing the number of arguments the script is given with what it can count
then
$ZENITY --error --title="Compress PDF $VERSION" # if we arrive here, there is something very messed
exit 1
fi
# Check if all the arguments are proper PDF files
for ARG in "$@"
do
IS_PDF=$(file --brief --mime-type "$ARG" | grep -i "/pdf") # ignoring case for 'pdf'; as far as I know, the slash before (sth/pdf) is universal mimetype output. In most cases we can even expect 'application/pdf' (portability issues?).
if [ "x$IS_PDF" = x ]; then NOT_PDF=1; break; fi
done
if [ "x$NOT_PDF" != x ]
then
$ZENITY --error --title="Compress PDF $VERSION" --text="$error_nopdf"
exit 1
fi
# Everything is OK. We can go on.
# Ask the user to select an output format
selected_level=$($ZENITY --list --title="Compress PDF "$VERSION"" --text "$label_level" --radiolist --column "" --column "$optimization_level" TRUE "$level_default" FALSE "$level_screen" FALSE "$level_low" FALSE "$level_high" FALSE "$level_color" --height 250 --width 400)
if [ "$?" != "0" -o "x$selected_level" = x ]; then exit 1; fi
# Select the optimization level to use
case $selected_level in
"$level_default")
COMP_COMMAND="/default"
;;
"$level_screen")
COMP_COMMAND="/screen"
;;
"$level_low")
COMP_COMMAND="/ebook"
;;
"$level_high")
COMP_COMMAND="/printer"
;;
"$level_color")
COMP_COMMAND="/prepress"
;;
esac
# Choose output filename(s)
if [ $# -eq 1 ]
then
pdf_file=$(basename "$1")
suggested_filename=${pdf_file%.*}${filename_suffix}.${pdf_file##*.}
output_filename=$($ZENITY --file-selection --save --confirm-overwrite --filename="$PWD/$suggested_filename" --title="$label_filename")
if [ "$?" != "0" -o "x$output_filename" = x ]; then exit 1; fi
else
filename_suffix=$($ZENITY --entry --title="Compress PDF $VERSION" --text="$label_suffix" --entry-text="$filename_suffix")
if [ "$?" != "0" ]; then exit 1; fi
if [ "x$filename_suffix" = x ]
then if ! $ZENITY --warning --title="Compress PDF $VERSION" --text="$warning_overwrite"; then exit 1; fi
fi
case "$filename_suffix" in */*) $ZENITY --error --title="Compress PDF $VERSION"; exit 1; esac # Check if the specified suffix is legal (we use 'case' instead of 'if' to directly use asterisk * globbing -- and avoid [[...]] for portability)
fi
# Finally, we process the files
for arg in "$@" # this processing is partly inspired by Edouard Saintesprit's patch from Compress PDF page at Launchpad
do
if [ $# -ne 1 ]
then
pdf_file=$(basename "$arg")
output_filename=${pdf_file%.*}${filename_suffix}.${pdf_file##*.}
fi
output_name=$(basename "$output_filename")
temp_pdfmarks=tmp-compresspdf-$output_name-pdfmarks
temp_filename=tmp-compresspdf-$output_name
if [ -e $temp_pdfmarks -o -e $temp_filename ]; then $ZENITY --error --title="Compress PDF $VERSION"; exit 1; fi
# Extract metadata from the original PDF. This is not a crucial functionality, but maybe we could warn if pdfinfo or sed are not available
pdfinfo "$arg" | sed -e 's/^ *//;s/ *$//;s/ \{1,\}/ /g' -e 's/^/ \//' -e '/CreationDate/,$d' -e 's/$/)/' -e 's/: / (/' > "$temp_pdfmarks"
if ! grep /Title "$temp_pdfmarks"; then echo ' /Title ()' >> "$temp_pdfmarks"; fi # Warning: if the pdf has not defined a Title:, ghostscript makes a fontname become the title.
# echo -e 0a'\n'' /Title ()''\n'.'\n'w | ed afile # use to prepend instead of append
sed -i '1s/^ /[/' "$temp_pdfmarks"
sed -i '/:)$/d' "$temp_pdfmarks"
echo " /DOCINFO pdfmark" >> "$temp_pdfmarks"
# Execute ghostscript while showing a progress bar
(
$GS -sDEVICE=pdfwrite -dPDFSETTINGS=$COMP_COMMAND -dColorConversionStrategy=/LeaveColorUnchanged -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -dSAFER -sOutputFile="$temp_filename" "$arg" "$temp_pdfmarks" & echo -e "$!\n"
# we output the pid so that it passes the pipe; the explicit linefeed starts the zenity progressbar pulsation
) | ( # the pipes create implicit subshells; marking them explicitly
read PIPED_PID
if $ZENITY --progress --pulsate --auto-close --title="Compress PDF $VERSION"
then
rm "$temp_pdfmarks"
mv -f "$temp_filename" "$output_filename" & # we go on to the next file as fast as possible (this subprocess survives the end of the script, so it is even safer)
notify-send "Compress PDF" "$output_name $job_done"
else
kill $PIPED_PID
rm "$temp_pdfmarks"
rm "$temp_filename"
exit $COMPRESSPDF_BATCH_ABORT_ERR # Warning: it exits the subshell but not the script
fi
)
if [ "$?" = "$COMPRESSPDF_BATCH_ABORT_ERR" ]; then break; fi # to break the loop in case we abort (zenity fails)
done
Run Code Online (Sandbox Code Playgroud)
原始来源:https : //launchpad.net/compress-pdf
脚本基于oriolpont 的这个分支,并根据cipricus 的建议进行了修改。
Oriolpont 的修订版进行了多项改进:
- Yaron 的希伯来语翻译
- 基于 Edouard Saintesprit 更改的多文件支持
- 其他几个 bash 调整使脚本更安全(PID 临时文件、GS 的安全模式、更多的初始检查)
截屏
选项
zenity GUI 对话框中提供的选项对应于以下ghostscript
设置:
dPDFSETTINGS=/screen
(仅屏幕视图质量,72 dpi 图像)dPDFSETTINGS=/ebook
(低质量,150 dpi 图像)dPDFSETTINGS=/printer
(高质量,300 dpi 图像)dPDFSETTINGS=/prepress
(高质量、保色、300 dpi imgs)dPDFSETTINGS=/default
(几乎与 /screen 相同)网站上的更多选项和微调:http : //milan.kupcevic.net/ghostscript-ps-pdf/
您可以在此处找到有关所用选项的更多信息。Oriolpont 的README提供了有关根据您的需要自定义脚本的更多详细信息。
安装
该脚本依赖于许多包。您可以通过以下方式安装它们:
sudo apt-get install ghostscript poppler-utils zenity
Run Code Online (Sandbox Code Playgroud)
如果您不知道如何安装 Nautilus 脚本,请按照本指南进行操作:
在备用桌面环境上安装
该脚本不依赖于任何自定义 Nautilus 变量,并且可以与几乎所有支持自定义菜单操作的文件管理器一起使用。请参阅您的文件管理器手册以了解如何安装您的脚本。XFCE 用户可以在这里找到一个很好的教程。
当然,您也可以从命令行启动脚本。基本用法:
compresspdf "filename.pdf"
Run Code Online (Sandbox Code Playgroud)
私酒
概述
使用Moonshiner(ghostscript 的 GUI 前端)可以实现对 PDF 输出的更高级控制。
安装
官方存储库中不提供 Moonshiner。不幸的是,我也找不到官方 PPA。只有这个私人 PPA 有一段时间没有更新了。此处.deb
可用的存档应该适用于最近的 Ubuntu 修订版,但不要相信我的话。
据我所知,安装 Moonshiner 的最安全方法是直接从其来源。为此,首先下载最新版本:
svn co https://moonshiner.svn.sourceforge.net/svnroot/moonshiner/trunk moonshiner_svn
cd $HOME/moonshiner_svn/
Run Code Online (Sandbox Code Playgroud)
Moonshiner 依赖于 Python、PyGTK 和 Ghostscript。如果满足这些依赖项(它们应该在 Ubuntu 上安装),您可以继续安装应用程序:
sudo python setup.py install
Run Code Online (Sandbox Code Playgroud)
或者使用python的数据包管理工具(sudo apt-get install python-pip
):
python setup.py sdist
sudo pip install $HOME/moonshiner_svn/dist/moonshiner-1.1svn.tar.gz
Run Code Online (Sandbox Code Playgroud)
卸载 Moonshiner 轻而易举pip
:
sudo pip uninstall moonshiner
Run Code Online (Sandbox Code Playgroud)
如果您使用第一种安装方法,则必须手动删除所有已安装的文件。
用法
安装后,您应该能够从仪表板或您首选的应用程序启动器启动 Moonshiner。GUI 是不言自明的。要修改 PDF,您只需将文件拖放到界面上,更改所需的设置并点击Go Moonshining!.
“图像”选项卡下的三个独立调节器允许您根据自己的意愿微调 DPI 和质量设置:
我不会在这里深入探讨其他设置,但我鼓励您查阅官方文档以了解您可能遇到的任何问题。
自定义图标
我不太喜欢 Moonshiner 的图标,所以我创建了一个我自己的:
您可以在此处下载 SVG 。该图标基于梦幻般的Faenza图标集,并在相同的许可证 (GNU/GPL) 下发布。
归档时间: |
|
查看次数: |
10655 次 |
最近记录: |