DEV Community

hub
hub

Posted on

1

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 !

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay