DEV Community

hub
hub

Posted on

convert 400 PDF into JPG with command line in Linux with a batch command

well i have a entire folder of nearly 400 pdf files that had gotten accidentally scanned into pdf files instead of jpg. I have been looking for a way to correct this and everyone says use Linux, All I need is a simple command to make this convert the contents of the entire folder; all the pdf files are in just one folder.

i think that this might be appropiate

```find -type f -name '*.pdf' -exec pdftoppm -jpeg {} {} \;




and supsequently i use this to separate the files and put them into a separate folder:



Enter fullscreen mode Exit fullscreen mode

mkdir jpg_files && mv *.jpg jpg_files/




and besides this we can do this with python:




Enter fullscreen mode Exit fullscreen mode

!/usr/bin/python3

import sys
from pdf2image import convert_from_bytes

images = convert_from_bytes(open(sys.argv[1], "rb").read())
for i in range(len(images))
images[i].save(f"page-{i}.jpg")





With this test document I see:


well i guess that we can go like this in pyvips as:



Enter fullscreen mode Exit fullscreen mode

!/usr/bin/python3

import sys
import pyvips

image = pyvips.Image.new_from_file(sys.argv[1])
for i in range(image.get('n-pages')):
image = pyvips.Image.new_from_file(filename, page=i)
image.write_to_file(f"page-{i}.jpg")

```
Enter fullscreen mode Exit fullscreen mode

any ideas !

Top comments (0)