Hi Guys,
to convert say a range of say the 1st to 5th page of a multipage pdf into single images is fairly straight forward using:
convert file.pdf[1-5] file.jpg
But how do i convert say the 5th to the last page when i dont know the number of pages in the pdf? Is there a way of doing this easily or i need to find the number of pages?
I hope someone can help. I've been trying multiple ways but to no avail. Thank you in advance.
Windows XP
ImageMagick-6.8.1-9-Q16-x86-dll
converting PDF nth to last page
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: converting PDF nth to last page
Code: Select all
convert file.pdf[5--1] file.jpg
The -1 is the last image in the sequence. see http://www.imagemagick.org/Usage/basics/#list_ops
Re: converting PDF nth to last page
To do fifth to last, you'd actually have to specify file.pdf[4--1] -- with file.pdf[5--1] you'd get sixth to last page.fmw42 wrote:Code: Select all
convert file.pdf[5--1] file.jpg
The -1 is the last image in the sequence. see http://www.imagemagick.org/Usage/basics/#list_ops
Re: converting PDF nth to last page
Actually, page counting is zero-based. So 1st to 5th page will require to use [0-4].arpeggio wrote:
to convert say a range of say the 1st to 5th page of a multipage pdf into single images is fairly straight forward using:
convert file.pdf[1-5] file.jpg
[1-5] will give you the second to sixth page.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: converting PDF nth to last page
User pipitas is correct. The indices are zero base. I had assumed you were actually wanting index 5 to last. It really depends upon what you meant.
Re: converting PDF nth to last page
Hi guys,
Thank you very much for this. (Zero based, yes my bad!)
When i try: convert file.pdf[0-4] file.jpg, It Works fine.
But
When I try: convert file.pdf[4--1] file.jpg, i get, No pages will be processed (FirstPage > LastPage).
That is, Python says that because 5 is greater than -1, it doesnt understand. very strange.
Any ideas? Thank you in advance.
Thank you very much for this. (Zero based, yes my bad!)
When i try: convert file.pdf[0-4] file.jpg, It Works fine.
But
When I try: convert file.pdf[4--1] file.jpg, i get, No pages will be processed (FirstPage > LastPage).
That is, Python says that because 5 is greater than -1, it doesnt understand. very strange.
Any ideas? Thank you in advance.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: converting PDF nth to last page
That is a python issue. IM works fine. Try in commandline mode without python:
This works fine for me:
# create multipage image
# select 4 to last
This works fine for me:
# create multipage image
Code: Select all
convert rose: rose: rose: rose: rose: rose: rose: rose: rose: rose: rose: rose: rose.gif
identify rose.gif
rose.gif[0] GIF 70x46 70x46+0+0 8-bit sRGB 256c 40.4KB 0.000u 0:00.000
rose.gif[1] GIF 70x46 70x46+0+0 8-bit sRGB 256c 40.4KB 0.000u 0:00.000
rose.gif[2] GIF 70x46 70x46+0+0 8-bit sRGB 256c 40.4KB 0.000u 0:00.000
rose.gif[3] GIF 70x46 70x46+0+0 8-bit sRGB 256c 40.4KB 0.000u 0:00.000
rose.gif[4] GIF 70x46 70x46+0+0 8-bit sRGB 256c 40.4KB 0.000u 0:00.000
rose.gif[5] GIF 70x46 70x46+0+0 8-bit sRGB 256c 40.4KB 0.000u 0:00.000
rose.gif[6] GIF 70x46 70x46+0+0 8-bit sRGB 256c 40.4KB 0.000u 0:00.000
rose.gif[7] GIF 70x46 70x46+0+0 8-bit sRGB 256c 40.4KB 0.000u 0:00.000
rose.gif[8] GIF 70x46 70x46+0+0 8-bit sRGB 256c 40.4KB 0.000u 0:00.000
rose.gif[9] GIF 70x46 70x46+0+0 8-bit sRGB 256c 40.4KB 0.000u 0:00.000
rose.gif[10] GIF 70x46 70x46+0+0 8-bit sRGB 256c 40.4KB 0.000u 0:00.000
rose.gif[11] GIF 70x46 70x46+0+0 8-bit sRGB 256c 40.4KB 0.000u 0:00.000
Code: Select all
convert rose.gif[4--1] rose2.gif
identify rose2.gif
rose2.gif[0] GIF 70x46 70x46+0+0 8-bit sRGB 256c 27.2KB 0.000u 0:00.000
rose2.gif[1] GIF 70x46 70x46+0+0 8-bit sRGB 256c 27.2KB 0.000u 0:00.000
rose2.gif[2] GIF 70x46 70x46+0+0 8-bit sRGB 256c 27.2KB 0.000u 0:00.000
rose2.gif[3] GIF 70x46 70x46+0+0 8-bit sRGB 256c 27.2KB 0.000u 0:00.000
rose2.gif[4] GIF 70x46 70x46+0+0 8-bit sRGB 256c 27.2KB 0.000u 0:00.000
rose2.gif[5] GIF 70x46 70x46+0+0 8-bit sRGB 256c 27.2KB 0.000u 0:00.000
rose2.gif[6] GIF 70x46 70x46+0+0 8-bit sRGB 256c 27.2KB 0.000u 0:00.000
rose2.gif[7] GIF 70x46 70x46+0+0 8-bit sRGB 256c 27.2KB 0.000u 0:00.000