Skip to content

Commit cc1d40f

Browse files
committed
now using pdfsizeopt to decrease the size of the book pdf
1 parent ae21e98 commit cc1d40f

File tree

5 files changed

+59
-3
lines changed

5 files changed

+59
-3
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Your feedback would help us to improve the book.
1313
## 2. License
1414
This book is released under the Attribution-NonCommercial-ShareAlike 4.0 International license (CC BY‑NC‑SA 4.0), see [http://creativecommons.org/licenses/by-nc-sa/4.0/](http://creativecommons.org/licenses/by-nc-sa/4.0/) for a summary.
1515

16+
We statically include the [pdfsizeopt](https://github.com/pts/pdfsizeopt) tool to compress the book pdf file.
17+
This tool is excluded from the license mentioned above; it is under the GNU GENERAL PUBLIC LICENSE Version 2, June 1991 and the copyright belongs to its authors.
18+
1619
## 3. Contact
1720
If you have any questions or suggestions, please contact
1821
Prof. Dr. [Thomas Weise](http://iao.hfuu.edu.cn/5) (汤卫思教授)

scripts/filterPdf.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash -
22

3-
# This script filters a PDF file and attempts to include as many fonts as possible.
3+
# This script filters a PDF file using ghostscript and attempts to include as many fonts as possible.
44

55
# strict error handling
66
set -o pipefail # trace ERR through pipes

scripts/pdfsizeopt.sh

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash -
2+
3+
# This script applies the pdfsizeopt compressor to a pdf.
4+
# The pdfsizeopt compressor is open source and available at https://github.com/pts/pdfsizeopt.
5+
# We include it here in a single archive.
6+
7+
# strict error handling
8+
set -o pipefail # trace ERR through pipes
9+
set -o errtrace # trace ERR through 'time command' and other functions
10+
set -o nounset # set -u : exit the script if you try to use an uninitialized variable
11+
set -o errexit # set -e : exit the script if any statement returns a non-true return value
12+
13+
scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
14+
echo "Script directory is '$scriptDir'."
15+
16+
currentDir="$(pwd)"
17+
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): We are working in directory: '$currentDir'."
18+
19+
fileIn="$(readlink -f "$1")"
20+
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): The full input document path is '$fileIn'."
21+
22+
fileOut="$2"
23+
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): We will filter the input document '$fileIn' to '$fileOut'."
24+
25+
tempDir="$(mktemp -d)"
26+
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): We will use the temporary directory '$tempDir'."
27+
28+
cd "$tempDir"
29+
30+
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): Unpacking pdfsizeopt to '$tempDir'."
31+
tar -C "$tempDir" -xf "$scriptDir/pdfsizeopt.tar.xz"
32+
pdfsizeoptdir="$tempDir/pdfsizeopt"
33+
chmod 777 -R "$pdfsizeoptdir"
34+
35+
export PATH="$pdfsizeoptdir:$PATH"
36+
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): PATH is now '$PATH'."
37+
38+
pdfsizeopttemp="$pdfsizeoptdir/pdft"
39+
mkdir "$pdfsizeopttemp"
40+
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): pdfsizeopt will use temp dir '$pdfsizeopttemp'."
41+
42+
"$pdfsizeoptdir/pdfsizeopt.single" --do-double-check-type1c-output=yes --tmp-dir="$pdfsizeopttemp" "$fileIn" "$fileOut"
43+
44+
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): Now deleting temporary directory '$tempDir'."
45+
rm -rf "$tempDir"
46+
47+
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): Successfully finished filtering '$fileIn' to '$fileOut using pdfsizeopt."

scripts/pdfsizeopt.tar.xz

8.66 MB
Binary file not shown.

scripts/website.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ echo "$(date +'%0Y-%0m-%0d %0R:%0S'): First, we make sure that '$websiteDir' is
3030
rm -rf "$websiteDir" || true
3131
mkdir -p "$websiteDir"
3232

33-
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): Filtering the book into the website directory."
34-
"$scriptDir/filterPdf.sh" "$currentDir/book.pdf" "$websiteDir/programmingWithPython.pdf"
33+
# ghostscriptTemp="$(mktemp)"
34+
# echo "$(date +'%0Y-%0m-%0d %0R:%0S'): First filtering the book to a temp file '$ghostscriptTemp'."
35+
# "$scriptDir/filterPdf.sh" "$currentDir/book.pdf" "$ghostscriptTemp"
36+
# echo "$(date +'%0Y-%0m-%0d %0R:%0S'): Now compressing the book to the website directory."
37+
# "$scriptDir/pdfsizeopt.sh" "$ghostscriptTemp" "$websiteDir/programmingWithPython.pdf"
38+
# rm "$ghostscriptTemp"
39+
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): Compressing the book from '$currentDir/book.pdf' to '$websiteDir/programmingWithPython.pdf' using pdfsizeopt."
40+
"$scriptDir/pdfsizeopt.sh" "$currentDir/book.pdf" "$websiteDir/programmingWithPython.pdf"
3541

3642
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): Put the LICENSE.md file into the website directory."
3743
licenseFile="$currentDir/LICENSE.md"

0 commit comments

Comments
 (0)