Forum moved here!

Home / Printing from command line


Hi, we print our documents with command like this

sumatrapdf -exit-on-print -print-to “my-printer” my-document.pdf

and it works most of the time.

But suddenly sumatra displays “Cannot print file”.

Trying the very same command again works perfectly.

Is there a logfile where we can find the reason why the document was not printed ?

Or does sumatrapdf give a “returncode” that there was a problem with printing ?


Looking at the code ( “Cannot print this file” happens when we can’t open / process file.

If it’s intermittent I would blame anti-virus software for messing with file access.



thanks for your answer.

But is there a way that I can react to this problem ?

If my batchfile would know there was a problem it could wait a second and try to print the file again.


When printing fails, the return code is 1. If it doesn’t, it’s 0.



perfect, works like a charm !

Here is the solution I came up with (suggestions for improvement are welcome):

@echo off

set count=1
set silent01=1


if %silent01% == 1 goto silent

SumatraPDF.exe -exit-on-print -print-to %1 %2

goto finish


SumatraPDF.exe -silent -exit-on-print -print-to %1 %2

if errorlevel 1 goto error
goto finish


timeout /t 3

set /a count=%count%+1

if   %count% geq 5 set silent01=0

goto start