Page 1 of 1
converting PDF nth to last page
Posted: 2015-07-05T07:10:47-07:00
by arpeggio
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
Re: converting PDF nth to last page
Posted: 2015-07-05T10:12:17-07:00
by fmw42
Re: converting PDF nth to last page
Posted: 2015-07-05T11:46:15-07:00
by pipitas
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.
Re: converting PDF nth to last page
Posted: 2015-07-05T11:48:41-07:00
by pipitas
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
Actually, page counting is zero-based. So 1st to 5th page will require to use
[0-4].
[1-5] will give you the second to sixth page.
Re: converting PDF nth to last page
Posted: 2015-07-05T15:41:01-07:00
by fmw42
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
Posted: 2015-07-05T23:54:24-07:00
by arpeggio
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.
Re: converting PDF nth to last page
Posted: 2015-07-06T08:17:23-07:00
by fmw42
That is a python issue. IM works fine. Try in commandline mode without python:
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
# select 4 to last
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