-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ghostscript to compress PDF output on RTD
- Loading branch information
1 parent
eef780c
commit 1aa20c6
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Compresses the PDF output using ghostscript on Read the Docs. | ||
|
||
OUTPUT_FILENAME="gm0.pdf" | ||
DPI=300 | ||
PDF_DIR="$READTHEDOCS_OUTPUT/pdf" | ||
|
||
# Check if the PDF build is enabled based on if the PDF output directory exists | ||
if [ -d "$PDF_DIR" ]; then | ||
existing_pdf=$(ls "$PDF_DIR") | ||
|
||
# actually compress the PDF | ||
gs -sDEVICE=pdfwrite \ | ||
-dCompatibilityLevel=1.4 \ | ||
-dPDFSETTINGS=/ebook \ | ||
-dNOPAUSE \ | ||
-dBATCH -dColorImageResolution="$DPI" \ | ||
-sOutputFile="$PDF_DIR/$OUTPUT_FILENAME" "$PDF_DIR/$existing_pdf" | ||
|
||
# readthedocs expects only one PDF output in the directory | ||
# see https://docs.readthedocs.io/en/stable/reference/environment-variables.html#envvar-READTHEDOCS_OUTPUT | ||
rm "$PDF_DIR/$existing_pdf" | ||
fi |