Forum moved here!

Home / Sumatrapdf commandline usage to get thumbnail



is there a trick to get a thumbnail for an pdf like when it is created by sumatrapdf if i use the commanline option “-print-dialog”. I want to avoid the sideway with an image library to get an thumbnail.

I want to display the thumbnail in a custom print gui where i select the right printer and settings dependend on how the pdf-file is named.


Explorer Preview thumbnails cant be “created” by command line

SumatraPDF builds small (usually top half page) PNG thumbnails for its start-up front page screen, (that could be triggered via open/close file and collect new image from cache folder) but those would probably be of little value, and you would need to rename from the hashed coded name. More trouble than its worth.

The best tool would probably be IrfanView where you can script to open pdf at page# then save at a predefined size and format.

The way that SumatraPDF can help is to allow viewing files, so that you can see which page you want to thumbnail, then send that filename and page number to a command line script or list of files and pages that can then call another task to create the thumbnail.
So here I sent the whole filename to IrfanView with the coverpage as the target, Actually IrfanView explorer does a better job showing thumbnails for saving if it then opens that folder.


Thanks for answer.
I use imagemagik then, here is a explantation if someone needs it too:


For anyone wanting to do similar from within SumatraPDF you need to include a negative shift by 1 in page number. The reason is as seen in the example given that page 3 in a pdf is always shown counted from base 1 but counts as image 2 from internal base 0 by imagemagick. So a cover page is entered as filename.pdf[0] thus we would call with “%1[0]”

convert \
-density 600 \ # make it high density so the resized image looks OK
example_051.pdf[2] \ # use [X] to specify the page number page 3 in this case.
-resize x150 \ # resize to a height of 150 keeping the width ratio the same
-flatten \ # flatten the image so that the transparent areas aren't blacked out
out.jpg \ # the name of the output image. 

I have some issues with the above imagemagick command, First it seemed to take forever on a large file, then the output was NOT flagged as 600x600 which actually is useless for thumbnail production as the 150 is the key value.

It is easier to use the compatible single MuTools.exe from here (SumatraPDF uses the MuPDF library)

In this case the CommandLine to get a similar quality PNG thumbnail from inside SumatraPDF ExternalViewers becomes
mutool draw -o "%1-page%04d.png" -r 96 -h 150 "%1" %p

So from viewing the cover page in example,pdf, I then very quickly get a 150 high thumbnail alongside called example-page0001.png.

Note MuTool will generate higher quality PNG rather than lossy jpg, you can of course change the resolution to -r anything (NOT recommended) to get what appears to be a smaller size of screen compatible output, but the actual file size of 150 pixels high is as here the one used (Resolution value is ignored). Resolution is only used by some other apps so it depends on downstream intended usage.
For comparison the png file size is about 50% larger but that could be compressed without change in quality (I normally don’t recommend such compression) Here I have scaled both up 400% for screen view.
Jpg on left Png on right, not the best example for comparison but I consider the left is inferior.


@iconberg as a result of your query, I have updated my Export / Save page(s) as PNG Image(s) script that can be added into SumatraPDF

It can be used on the desktop to drag and drop a file OR as intended be used from inside SumatraPDF with many more file types than just PDF such as cbz, epub, FB2 or zip etc. however you may find page numbers can vary unless you are using FixedPageUI (Toggle ebook UI)

If you wish to try it then unlike imagemagic it needs just one 35MB mutool.exe and in your case you need to change towards the end from draw -r 96 -o to draw -r 96 -h 150 -o
Note -h 150 can be any pixel height value you wish.


Just an update that whilst working on extended indexing I had reason to play with some aspects of thumbnails and have updated my notes at MyNotes/AppNotes/SumatraPDF at master · GitHubRulesOK/MyNotes

The 5 page pdf is