Deprecated: Return type of Requests_Cookie_Jar::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /homepages/3/d206872806/htdocs/patolin.com.2019/wp-includes/Requests/Cookie/Jar.php on line 63

Deprecated: Return type of Requests_Cookie_Jar::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /homepages/3/d206872806/htdocs/patolin.com.2019/wp-includes/Requests/Cookie/Jar.php on line 73

Deprecated: Return type of Requests_Cookie_Jar::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /homepages/3/d206872806/htdocs/patolin.com.2019/wp-includes/Requests/Cookie/Jar.php on line 89

Deprecated: Return type of Requests_Cookie_Jar::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /homepages/3/d206872806/htdocs/patolin.com.2019/wp-includes/Requests/Cookie/Jar.php on line 102

Deprecated: Return type of Requests_Cookie_Jar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /homepages/3/d206872806/htdocs/patolin.com.2019/wp-includes/Requests/Cookie/Jar.php on line 111

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /homepages/3/d206872806/htdocs/patolin.com.2019/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 40

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /homepages/3/d206872806/htdocs/patolin.com.2019/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 51

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /homepages/3/d206872806/htdocs/patolin.com.2019/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 68

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /homepages/3/d206872806/htdocs/patolin.com.2019/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 82

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /homepages/3/d206872806/htdocs/patolin.com.2019/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 91
Cómo convertir (miles de) archivos pdf a escala de gris, con un solo comando – patolin.com

Cómo convertir (miles de) archivos pdf a escala de gris, con un solo comando

Existen ocasiones en las que debemos automatizar tareas en nuestras labores diarias, y me ocurrió que debía convertir cerca de 4000 archivos PDF de color a escala de gris.

Utilizando bash (bajo linux, o utilizando la interfaz de Linux que provee Windows 10), podemos crear un par de scripts que nos ayuden a automatizar esta tarea.

Primero debemos crear en la carpeta donde tengamos almacenados los PDFs, un archivo que se va a llamar “conviertegris.sh” que contendrá el siguiente código:

#!/bin/bash
gs -sOutputFile=pdfgris.pdf -sDEVICE=pdfwrite -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray -dCompatibiltyLevel=1.4 -dNOPAUSE -dBATCH $@

y luego le daremos permisos de ejecución mediante el siguiente comando en la consola

chmod +x conviertegris.sh

Si tuvieramos un solo archivo PDF que quisieramos convertirlo a escala de gris. podríamos utilizar el script de la siguiente manera:

./conviertegris.sh miPDFaColor.pdf

y esto nos generará un nuevo archivo pdf llamado pdfgris.pdf que contendrá la versión en gris de nuestro archivo original.

Ahora, para automatizar este proceso para todos nuestros PDFs, vamos a crear otro script que se va a llamar “conviertelote.sh”, que contendrá el siguiente código:

#!/bin/bash
find ./ -name "*.pdf" | sed 's|./||' > listapdf.txt
mkdir pdfgris
for file in $( < list .txt); do ./conviertegris.sh "$file"; mv pdfgris.pdf ./pdfgris/"$file"; done
rm listapdf.txt

Al ejecutar este script mediante el comando bash conviertelote.sh, empezaremos a ver que el proceso arranca y dentro de la carpeta pdfgris empezaremos a ver nuestros archivos convertidos.

Con esto, y luego de un par de horas, habremos terminado la tarea, sin tener que pasar por el suplicio de abrir cada archivo en un editor de PDFs y guardarlos en escala de gris, ahorrándonos muchisimo tiempo y trabajo.


Posted

in

, ,

by

Tags:

Comments

Deja un comentario