Generate tiles for all pages of multi-page PDF

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
martink
Posts: 3
Joined: 2019-10-14T15:12:10+00:00
Authentication code: 1152

Generate tiles for all pages of multi-page PDF

Post 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!
snibgo
Posts: 12159
Joined: 2010-01-24T06:01:33+00:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

You "-flatten" all the pages together.
snibgo's IM pages: im.snibgo.com
martink
Posts: 3
Joined: 2019-10-14T15:12:10+00:00
Authentication code: 1152

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

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-24T06:01:33+00:00
Authentication code: 1151
Location: England, UK

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

Post 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
snibgo's IM pages: im.snibgo.com
martink
Posts: 3
Joined: 2019-10-14T15:12:10+00:00
Authentication code: 1152

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

Post by martink »

That does the trick. Thank you so much!
Post Reply