Page 1 of 1

Generate tiles for all pages of multi-page PDF

Posted: 2019-10-14T08:21:56-07:00
by martink
Hi

Apologies if this is a common question; I can't seem to find this in the forums.

I'm trying to generate tiles for all pages of a PDF, and to name them according to the tile coordinates (the format should be something like <page_number>-<tile_column_number>-<tile_row_number>.jpg). So far I've come up with

Code: Select all

convert -density 300 input.pdf -colorspace RGB -flatten -quality 95 -crop 256x256 -set filename:f "0-%[fx:floor(page.x/256)]-%[fx:floor(page.y/256)]" '%[filename:f].jpg'
Sadly, this only generates tiles for the first page of the PDF - hence the leading '0-' in the output filename. Any ideas for how I could generate tiles for all pages in the PDF and name them approrpriately?

Thanks!

Re: Generate tiles for all pages of multi-page PDF

Posted: 2019-10-14T08:52:33-07:00
by snibgo
You "-flatten" all the pages together.

Re: Generate tiles for all pages of multi-page PDF

Posted: 2019-10-14T09:57:53-07:00
by martink
Thank you for the quick reply. I have experimented with positioning the -flatten argument in various positions in the above command, but I seem to get either one output tile in total or a set of tiles from the first page of the document; not all tiles from all pages.

Also, how do I reference the page number in the output file name?

Re: Generate tiles for all pages of multi-page PDF

Posted: 2019-10-14T10:28:23-07:00
by snibgo
martink wrote:I have experimented with positioning the -flatten argument in various positions in the above command, ...
Why? You don't want to flatten the pages together, do you?. See http://www.imagemagick.org/script/comma ... hp#flatten

For percent-escapes, see http://www.imagemagick.org/script/escape.php . Instead of "0", use "%s". For example:

Code: Select all

magick in.pdf -crop 256x256 -set filename:f "%s-%[fx:floor(page.x/256)]-%[fx:floor(page.y/256)]" xxxx_%[filename:f].jpg

Re: Generate tiles for all pages of multi-page PDF

Posted: 2019-10-14T11:06:56-07:00
by martink
That does the trick. Thank you so much!