CBR to PDF

 

Convert CBR to PDF

Either go to the original repo or get it from the AUR

yay -S cbr2pdf-git

To use it, run

cbr2pdf -i /path/to/all/cbr/files/ -o /path/to/output/directory

Convert all CBR to CBZ

Create a file called rar2zip.sh containing the following from Terence Eden:

#!/bin/bash
echo "Converting RARs to ZIPs"

# Separate files using ␜ http://graphemica.com/%E2%90%9C.
IFS="␜"

# Use RAM disk for temporary files.
WORKDIR="/dev/shm/"

# Set name for the temp dir. This directory will be created under WORKDIR
TEMPDIR="rar2zip"

# Run using "./rar2zip.sh /full/path/to/files/"
# If no directory is specified, then use the current working directory (".").

if test -z $1; then
   SOURCEDIR=`pwd`
else
   SOURCEDIR="$1"
fi

echo "Using $SOURCEDIR"

# Create an temporary directory to work in.
cd $WORKDIR
mkdir $TEMPDIR
cd $TEMPDIR

# Find all the .rar files in the specified directory.
# Using -iname means it will find .rar .RAR .RaR etc.
# "-printf "%p␜" will cause the file names to be separated by the ␜ symbol,
# rather than the default newline.

for OLDFILE in `find $SOURCEDIR -iname "*.rar" -printf "%p␜"`; do

   # Get the file name without the extension
   BASENAME=`basename "${OLDFILE%.*}"`

   # Path for the file. The ".zip" file will be moved there.
   DIRNAME=`dirname $OLDFILE`

   # Name of the .zip file
   NEWNAME="$BASENAME.zip"

   # Create a temporary folder for unRARed files
   echo "Extracting $OLDFILE"
   mkdir "$BASENAME"
   7z x "$OLDFILE" -O"$BASENAME"
   cd "$BASENAME"

   # Zip the files with maximum compression
   7z a -tzip -mx=9 "$NEWNAME" *
   # Alternative. MUCH SLOWER, but better compression
   # 7z a -mm=Deflate -mfb=258 -mpass=15 -r "$NEWNAME" *

   # Move the new .zip to the directory containing the original ".rar" file
   mv "$NEWNAME" $DIRNAME/"$NEWNAME"

   # Delete the temporary directory
   cd $WORKDIR
   rm -r "$BASENAME"

   # OPTIONAL. Delete the RAR file
   # cd $DIRNAME
   # rm "$OLDFILE"

done

# Delete the temporary directory
cd $WORKDIR
rm -r $TEMPDIR

echo "Conversion Done"

And also create a script containing:

mkdir tmp
cp *.cbr tmp
cd tmp

for f in *
do
    mv -- "$f" "${f%.cbr}.rar"
done

cp ../rar2zip.sh .

bash rar2zip.sh

for file in *.zip
do
    mv -- "$file" "${file%.zip}.cbz"
done

Run the second script, and this will create a tmp folder with all of the newly converted CBZ

Rescale the PDFs to Letter or A4

Go to tavinus/pdfScale, and get the pdfScale.sh file. Then, use the following flags (suggested):

  • -r to resize. E.g.: -r letter
  • -s to scale. E.g.: -s 0.9

And run this through every file:

# resize_all_pdfs.sh
for f in ./*.pdf
do
  ./pdfScale.sh -v -r letter -s 0.9 "$f"
done

This should resize all of the pdfs so that they can be printed on a standard US printer. By default, it will rotate the pages appropriately.

Merge all PDFs

yay -S pdftk

Catenate the PDFs together

pdftk *.pdf cat output full_collection.pdf