Convertir cbr ó cbz en pdf: cbr2pdf

Seguimos con los comics a vueltas, antes de seguir quiero aclarar que el script que presento a continuación no es mío sino de pixatintes, así que como no quiero perderlo comparto el hallazgo con vosotros como mirror. Para instalarlo -en Linux- tan solo descomprímelo en ~/.gnome2/nautilus-scripts/ y dale permisos de ejecución al script. Una vez echo ésto aparecerá en el menú contextual de Gnome.

Para usarlo sitúate encima de un cbr/cbz, botón derecho, scripts, cbr2pdf y automágicamente aparecerá un pdf en el mismo directorio que el archivo origen. Os dejo con el código fuente... Ojo: Depende de unrar, unzip, imagemagick y pdftk, funciona tanto con cbr como con cbz:
#!/bin/bash

# cbr2pdf
# Convert cbr/cbz files to pdf.
#
# pixatintes@gmail.com 
#
#		28.04.2009 : v0.30b	
# Install
# 		Put on ~/.gnome2/nautilus-scripts/
#		In a console : chmod +x ~/.gnome2/nautilus-scripts/cdr2pdf
# Dependency
#		unrar
#		unzip
#		ImageMagick
#		pdftk
#		
version="0.30b"
#########################################################################
#!/bin/bash

	###### Default = English #####
	title="Cbr2Pdf "$version""
	pleasesel="Please select a file."
	noselec=""$title" convert cbr/cbz files. "$pleasesel""
	select="Select a format:"
	Standard="No resize images" 
	Standard_grey="Convert to Grey-scale without resize images"
	Iliad="Resize images for Irex Iliad (XGA-768x1024)"
	Iliad_grey="Convert to Grey-scale and resize images for Irex Iliad (XGA-768x1024)"
	Sony="Resize images for Sony eBook Reader (VGA-600x800)"
	Sony_grey="Convert to Grey-scale and resize images for Sony eBook Reader (VGA-600x800)"
	warning="Warning"
	proceed="is already exist. Overwrite?"
	conversion="Converting files.."
	end="Complete :P"

case $LANG in
	######## Spanish ########
	ca* )
	title="Cbr2Pdf "$version""
	pleasesel="Sel·leccina almenys un arxiu."
	noselec=""$title" converteix cbr/cbz arxius. "$pleasesel""
	select="Sel·lecciona un format:"
	Standard="No escalar les imatges" 
	Standard_grey="Convertir a grisos sense escalar les imatges" 
	Iliad="Escalar les imatges per Irex Iliad (XGA-768x1024)"
	Iliad_grey="Convertir a grisos i escalar les imatges per Irex Iliad (XGA-768x1024)"
	Sony="Escalar les imatges per Sony eBook Reader (VGA-600x800)"
	Sony_grey="Convertir a grisos i escalar les imatges per Sony eBook Reader (VGA-600x800)"
	warning="Warning"
	proceed="ja existeix. Sobreescriure?"
	conversion="Convertint arxius.."
	end="Complert :P"
esac

#################################################
#	FUNCIONS

c_RotateAutoPage() # funció girar pagines en vertical.
{
while [ $# -gt 0 ]; do
		w=`identify -format "%[fx:w]" $1`		
		h=`identify -format "%[fx:h]" $1`		
		if [ $w -gt $h ]
		then 
		convert $1 -rotate 270 "$1"
		fi	
	shift

done
}

ext() # funció "convert file"
{
	#### Extreure cbr/cbz arxius a ~/tempcbr/

	O=`echo "$1" | sed 's/\.\w*$/''/'`	

	if [ "`file -b "$1" | grep 'RAR'`" != 0 ]
	then
		mkdir tempcbr
		unrar e -y "$1" tempcbr/
	fi

	if [ "`file -b "$1" | grep 'Zip'`" != 0 ]
	then
		unzip "$1" -d tempcbr/
	fi

	c_RotateAutoPage tempcbr/*g tempcbr/*G tempcbr/*/*g tempcbr/*/*G tempcbr/*/*f tempcbr/*/*F

	#### Crear pdf

	if [ "$2" = "Standard" ]
	then # Standard
		convert tempcbr/*g tempcbr/*G tempcbr/*/*g tempcbr/*/*G tempcbr/*/*f tempcbr/*/*F "$O"_.pdf
	fi

	if [ "$2" = "Standard_grey" ]
	then # Standard
		convert -modulate 100,0 tempcbr/*g tempcbr/*G tempcbr/*/*g tempcbr/*/*G tempcbr/*/*f tempcbr/*/*F "$O"_.pdf
	fi

	if [ "$2" = "Iliad" ]
	then # Iliad
		convert -resize 768x1024 tempcbr/*g tempcbr/*G tempcbr/*/*g tempcbr/*/*G tempcbr/*/*f tempcbr/*/*F "$O"_.pdf
	fi

	if [ "$2" = "Iliad_grey" ]
	then # Iliad
		convert -resize 768x1024 -modulate 100,0 tempcbr/*g tempcbr/*G tempcbr/*/*g tempcbr/*/*G tempcbr/*/*f tempcbr/*/*F "$O"_.pdf
	fi

	if [ "$2" = "Sony" ]
	then # sony
		convert -resize 600x800 tempcbr/*g tempcbr/*G tempcbr/*/*g tempcbr/*/*G tempcbr/*/*f tempcbr/*/*F "$O"_.pdf
	fi

	if [ "$2" = "Sony_grey" ]
	then # sony
		convert -resize 600x800 -modulate 100,0 tempcbr/*g tempcbr/*G tempcbr/*/*g tempcbr/*/*G tempcbr/*/*f tempcbr/*/*F "$O"_.pdf
	fi

	##### borrar temp directori ~/tempcbr/
	rm -R tempcbr
}

IFS=$'\t\n'

#### No hi ha fitxers sel. ###
			
if [ $# -eq 0 ]; then
	zenity --error --title="$warning" --text="$noselec"
	exit 1
fi		

######## Finetra principal ########
while [ ! "$formatout" ] # Preguntar el format de sortida
do	
	formatout=`zenity --list --title="$title" --text="$select" --width=680 --height=270 --column="Format" --column="Description" Standard "$Standard" Standard_grey "$Standard_grey" Iliad "$Iliad" Iliad_grey "$Iliad_grey" Sony "$Sony" Sony_grey "$Sony_grey"`

	[ $? -ne 0 ] && exit 2 # Cancelar
done

(while [ $# -gt 0 ]; do
	for i in $formatout; do
		O=`echo "$1" | sed 's/\.\w*$/'.pdf'/'`			
		while `true`; do
			########## Mirar si el fitxer existeix, sobreescriu ? ##########
			if [ "`ls "$O" | grep -v "^ls"`" != "" ]
			then
				if !(`gdialog --title "$warning" --yesno "$O $proceed" 200 100`)
				then
					break
				fi
			fi
			ext "$1" "$formatout" # Convertir
			
			pdftk "$O"_.pdf output "$O".pdf
			rm "$O"_.pdf
		break
		shift
		done
	done
	shift
done


echo "# "$end"" ; sleep 1
) |
#### Barra de progrés ####
zenity --progress --percentage=0 --title="$title" --text="$conversion" --pulsate --width=400 

About the author

Óscar
has doubledaddy super powers, father of Hugo and Nico, husband of Marta, *nix user, Djangonaut and open source passionate.