├── .gitignore ├── Makefile ├── wordx.sh ├── fast.c ├── README.md └── pdf2pdf.sh /.gitignore: -------------------------------------------------------------------------------- 1 | fastpdf 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-O2 2 | all: fastpdf 3 | 4 | fastpdf: fast.c 5 | g++ fast.c -o fastpdf 6 | 7 | clean: 8 | rm -f fastpdf 9 | -------------------------------------------------------------------------------- /wordx.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #wordx.sh 4 | 5 | for file in "$@" 6 | do 7 | if file --mime-type "$file" | grep -q msword$; then 8 | echo "Converting $file" 9 | 10 | # important, update time-stamp 11 | mv $file "$file"x 12 | echo -e 'Conversion completed.\n' 13 | 14 | else 15 | echo -e "Warning: Cannot convert $file, not of type .doc\n" 16 | fi 17 | 18 | done 19 | -------------------------------------------------------------------------------- /fast.c: -------------------------------------------------------------------------------- 1 | using namespace std; 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | 8 | usleep(833333); 9 | cout << "### (20%)\r" << std::flush; 10 | usleep(833333); 11 | cout << "###### (40%)\r" << std::flush; 12 | usleep(833333); 13 | cout << "######### (60%)\r" << std::flush; 14 | usleep(833333); 15 | cout << "############## (80%)\r" << std::flush; 16 | usleep(833333); 17 | cout << "################## (100%)\r" << std::flush; 18 | cout << "\n"; 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pdf2pdf 2 | This software performs the magical pdf-to-pdf conversion popular in academic journal submission sites. 3 | 4 | New speedup in version 2. Still runs in O(1) time, but now ~15% faster! 5 | Version 2 now requires you compile the C++ code fast.c thusly: 6 | 7 | `g++ fast.c -o fastpdf`. 8 | 9 | Requires imagemagick. It can probably be installed like this: 10 | 11 | - macOS: `brew install imagemagick` 12 | - Ubuntu: `sudo apt-get install imagemagick` 13 | 14 | ## Usage 15 | `bash pdf2pdf.sh pdf_filename1 pdf_filename2 ...` 16 | 17 | The software first checks whether each file is actually a pdf file, and then converts the pdf files into slightly worse pdf's. It skips any files that are not pdf. 18 | 19 | So, the following will convert all pdf files in the current folder: 20 | `bash pdf2pdf.sh *` 21 | 22 | ## Output 23 | Each listed pdf file will be converted to a lower-resolution pdf saved as "RandomNumber.pdf" in the current working directory. 24 | 25 | -------------------------------------------------------------------------------- /pdf2pdf.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #pdf2pdf.sh 4 | if test $# -eq 0 ; then 5 | echo "Error: pdf required for conversion to pdf" 6 | exit 1 7 | fi 8 | 9 | numerrors=0 10 | 11 | for file in "$@" 12 | do 13 | if file --mime-type "$file" | grep -q pdf$; then 14 | echo "Converting $file" 15 | 16 | if [ -f ./fastpdf ]; then 17 | if [ -x "$(command -v parallel)" ]; then 18 | # Use 500 processes for the conversion 19 | parallel ./fastpdf ::: `seq 1 1 500` 20 | else 21 | ./fastpdf 22 | fi 23 | else 24 | echo "File fastpdf does not exist. Please compile (see readme)." 25 | break; 26 | fi 27 | 28 | # important, update time-stamp 29 | touch "${file}" 30 | 31 | # rasterize and subtly degrade quality 32 | outfile=4.pdf 33 | convert -density 95 "${file}" -quality 95 $outfile 34 | 35 | echo -e "Conversion to ${outfile} completed.\n" 36 | 37 | else 38 | echo -e "Warning: Cannot convert $file, not of type pdf\n" 39 | numerrors=`expr 1 + $numerrors` 40 | fi 41 | 42 | done 43 | 44 | exit $numerrors 45 | --------------------------------------------------------------------------------