mirror of https://gitlab.com/curben/blog
post(pdf-compress): rename original file
This commit is contained in:
parent
d4fefb225f
commit
1b77cdd383
|
@ -53,10 +53,14 @@ Use the following script to compress all PDFs in a folder.
|
|||
|
||||
Usage: `sh pdfcompress.sh 'target folder'`
|
||||
|
||||
*If `'target folder'` is not specified, defaults to current directory.*
|
||||
|
||||
```bash
|
||||
#!/bin/sh
|
||||
|
||||
cd "$1"
|
||||
if [ -n "$1" ]; then
|
||||
cd "$1"
|
||||
fi
|
||||
|
||||
for i in *.pdf; do
|
||||
[ -f "$i" ] || break
|
||||
|
@ -64,8 +68,7 @@ for i in *.pdf; do
|
|||
# Skip compressed PDFs
|
||||
echo "$i" | grep --quiet ".compressed.pdf"
|
||||
|
||||
if [ $? = 1 ]
|
||||
then
|
||||
if [ $? = 1 ]; then
|
||||
gs \
|
||||
-sOutputFile="${i%.*}.compressed.pdf" \
|
||||
-sDEVICE=pdfwrite \
|
||||
|
@ -80,5 +83,36 @@ for i in *.pdf; do
|
|||
done
|
||||
```
|
||||
|
||||
If you prefer to use the original filename as the compressed version and rename the original uncompressed's to "*.original.pdf",
|
||||
|
||||
*Following script doesn't skip previously compressed PDFs*
|
||||
|
||||
```bash
|
||||
#!/bin/sh
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
cd "$1"
|
||||
fi
|
||||
|
||||
for i in *.pdf; do
|
||||
[ -f "$i" ] || break
|
||||
|
||||
# Rename original file to *.original.pdf
|
||||
original="${i%.*}.original.pdf"
|
||||
mv "$i" "$original"
|
||||
|
||||
gs \
|
||||
-sOutputFile="$i" \
|
||||
-sDEVICE=pdfwrite \
|
||||
-dPDFSETTINGS=/ebook \
|
||||
-sColorConversionStrategy=Gray \
|
||||
-sColorConversionStrategyForImages=/Gray \
|
||||
-dProcessColorModel=/DeviceGray \
|
||||
-dCompatibilityLevel=1.4 \
|
||||
-dNOPAUSE -dBATCH -dQUIET \
|
||||
"$original"
|
||||
done
|
||||
```
|
||||
|
||||
<br/><br/>
|
||||
Source: [Internal Pointers](https://www.internalpointers.com/post/compress-pdf-file-ghostscript-linux), [firstdoit](https://gist.github.com/firstdoit/6390547), [ahmed-musallam](https://gist.github.com/ahmed-musallam/27de7d7c5ac68ecbd1ed65b6b48416f9), [Ghostscript Docs](https://ghostscript.com/doc/current/Ps2pdf.htm)
|
||||
|
|
Loading…
Reference in New Issue