Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a multi page pdf to multiple pages using a single command

I want to convert multi page pdfs into single page images efficiently.

I already know how to do this one page at a time with imagemagick. For example,

convert x.pdf[2] x3.jpg 

will give me the 3rd page of the pdf as an image. So if I figure out how many pages are in the pdf using identify then I can loop through and convert all pages in the pdf to images. This method can however take a while. For example a 15 page pdf could take anywhere between 15-30 seconds.

According to answers that I have seen elsewhere (also on the imagemagick forums) the following imagemagick command should split a pdf into multiple images.

convert x.pdf x-%0d.jpg 

but all this ends up doing is creating the first page named x-0.jpg

As an alternative I have tried using pdftk with the burst capability. The problem I faced there is that burst does not work in all cases. It does for some pdf's and does not for some others.

Any suggestions on how to improve things would help.

My OS is Mac OSX Lion but I do need this working on CentOS 6 as well.

like image 375
Moiz Raja Avatar asked Jun 10 '13 13:06

Moiz Raja


People also ask

How to make a multi page PDF into one page?

Choose “Organize Pages” > “Split.” Choose how you want to split a single file or multiple files. Name and save: Click “Output Options” to decide where to save, what to name, and how to split your file. Split your PDF: Click “OK” and then “Split” to finish.


1 Answers

You're missing the quantity of digits. Use:

convert x.pdf x-%04d.jpg 

Where 4 means 4 digits will be show on the page count.

like image 164
beak42 Avatar answered Sep 21 '22 13:09

beak42