Forum moved here!

Home / Make a new file open in the current window instead of the new window



I’m trying to use Sumatra PDF as a a bundled viewer for my application.
I want Sumatra PDF to be launched on the second monitor in full screen mode, and that it receives commands to open the necessary files.

I’ve successfully configured Sumatra PDF using SumatraPDF-settings.txt and sumatrapdfrestrict.ini.
However, when I send a DDE Open command (like [Open("C:\test.pdf", 0, 0, 0)]), Sumatra PDF opens a new window, even though the newwindow parameter has value 0.
Is there a way to make the new file simply replace the current one in the same window?
So I want the behavior as by <Ctrl> + <Shift> + Right and <Ctrl> + <Shift> + Left shortcuts.

Thank you in advance.


I would avoid DDE as most of its function can now be accessed by settings and CLI
There are two factors affecting the number of instances (singular mode)
one is that in tabs mode it will be more singular but can still allow more than one file to open
the key one is ensuring ReuseInstance is set = true in the settings.txt
there was a CLI/DDE -Reuse-Instance call but it should NOT be needed if its in the settings file
I would switch tabs off and simply call “path to \SumatraPDF.EXE” “path and filename.pdf”
if SumatraPDF is default handler you only need to call “path and filename.pdf”
However on Win 10 edge could take control back so I would stick with the .exe & .pdf call

If you have a folder of files its “path to \SumatraPDF.EXE” “path name\*.pdf”



Thanks for the reply!

I’ve set ReuseInstance to true and UseTabs to false.
But if I call "...\SumatraPDF.exe" "...\1.pdf" and then call "...\SumatraPDF.exe" "...\2.pdf", Sumatra PDF opens a second window.
However, when I call "...\SumatraPDF.exe" "...\1.pdf" twice, no second window is opened. And that’s what I want to achieve, but with different files.

P.S. I’m trying everything in a maximized state of the window (WindowState = 2), as I don’t have a second monitor right now.


Sorry looks like I mislead you on testing it looks like reuse is not behaving same as I remember from previous versions What OS are you using (I’m on 10x64 calling 3.1.2 x32 portable from dos window, same issues)

You will either need to try DDE with -reuse-instance (it will take me a while to check if that’s still working)
OR call a folder of files as suggested above



No problem. :slight_smile:

I’m using Win 10 Pro version 1803 build 17134.319 64-bit and I’m testing everything on portable version of Sumatra PDF 3.1.2 64-bit.

OK, I’ll try DDE with with -reuse-instance.

Call a folder of files is not an option for me, as I want to show just one file at a time.



Seems like -reuse-instance doesn’t bring anything new. I still get a new window every time I ask to open a new file.


Looks like at present, I’m totally wrong as I can’t achieve exactly what your after via CLI in older versions.
This is odd as I’m equally sure I needed to call files in the past, exactly the same way you are after.

The only way is to call the first file in a given folder then use ctrl shift left or right to view the other files
So am going to try DDE and look for older batch files



OK. Thanks for the help anyway.

Sadly, but I can’t consider <Ctrl> + <Shift> + Right and <Ctrl> + <Shift> + Left as an option as I need to be specific in which file to open. Because otherwise I might need to switch about 50 or more files until I get the needed one.

So can be a current situation considered a bug?
I’ve thought I might have got something wrong, when trying to achieve my goal. But as you also are experiencing problems, it sounds more like a bug (or unavailable feature) than my error.


The use of tabs allows multiple files to be called in one session so there is no “bug”
the alternative desired use is call a pdf & open it call another pdf & open that (alternately in a second widow). The reason for reuse instance was to stop a second window opening when the first file was recalled, as required for forward search by a LaTeX editor. That still works (otherwise there would be screaming) however there were changes to allow for tabs. The one dirty method is to killtask and run a fresh single file session. but I’m trying to avoid that as my last suggestion :slight_smile:



Yes, usage of tabs is a nice feature, but I can’t use it, as there is no way to tell Sumatra PDF to close a current tab via DDE or CLI or whatever (or maybe I just don’t get it right now).

I’m already using a dirty method (opening a file in a new window and closing the previous window). :sweat_smile:
But I’ve thought that it’s possible to do things nicely. :slightly_smiling_face:

Can I post a feature request for reusing current window?


I would search GitHub issues (open and closed) before opening a new request there, just in case your usage was re-solved better there.

Here are my “best of 3” current solutions

Since SumatraPDF does not lock files under 10MB [UPDATE now 32MB in pre-release] you can simply substitute first.pdf with file2.pdf then hit R IF necessary to refresh (that’s the whole point of reuse, it should auto refresh, but depends on where your pdfs are, as some users have found the system does not see a remote overwrite)
so script wise for files seamless under 10MB [Or 32MB in 3.2 pre-release]

sumatrapdf.exe -fullscreen welcome.pdf
wait trigger
copy file1.pdf welcome.pdf
wait trigger
copy file2.pdf welcome.pdf
(optionally loop back to before file1.pdf)

The simplest use for run (& optionally loop) given list of files, including over 10MB [Or now 32MB in 3.2 pre-release] is to first set exit on escape in settings (EscToExit = true)
call sumatrapdf.exe -fullscreen file1.pdf (then when done hit esc)
call sumatrapdf.exe file2.pdf (then when done hit esc)

goto start
It will close and reopen the window on second screen (depending how fast script and next call takes it may only be momentary distraction

Lastly DDE method DOES require Tabs enabled so all files are finally in memory for recall (via a menu ?) there will obviously be a limit per machine as to how many files (depending on their size) can be loaded. ALL files could be preloaded without a pause then be selected using a backend menu system

here is how it can work one at a time (without preload)

SumatraPDF.exe -fullscreen first.pdf
pause (or wait)
execdde (via whatever script engine your using) [Open(“second.pdf”,0,0,1]
pause (or wait)
execdde (via whatever script engine your using) [Open(“third.pdf”,0,0,1]
pause (or wait)

(optionally loop back, will run quicker second run as all tabbed files are now loaded

So now you have 3 options or a hybrid between them



Thanks for such a detailed suggestion!

I obviously can’t use the fist method, as the files can easily be over 10 MB.

So I’ll use the combination of second and third for now.

I guess, I’ll create a feature request anyway, as the feature is actually already present via <Ctrl> + <Shift> + Right / Left, but just doesn’t have a fully controllable API (don’t know how to call it correctly), so it might be not hard to implement and future users might benefit from it.


Longtime later but whilst testing a similar SumatraPDF does not have a specific close filename command in DDE or CLI (if the only file is closed the app is in effect closed.) I found the best way to open and close a file list in sequence is as follows.

Pseudo Code (not real, just the concept showing 2 files)

set "NextName=Path\2nd.pdf"
set "PrevName=Path\1st.pdf"

Rem -reuse-instance ensures a single session
SumatraPDF -reuse-instance %PrevName%

SumatraPDF -reuse-instance %NextName%

Rem send a clean request to close PrevName
Taskkill /T /FI "Imagename eq SumatraPDF.exe" /FI "WindowTitle eq %PrevName%*"

Set  "PrevName=%NextName%"
IF %PrevName%=%LastName% exit
goto Loop