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


#1

Hi!

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.


#2

@muf
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”


#3

@GitHubRulesOK

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.


#4

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


#5

@GitHubRulesOK

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.


#6

@GitHubRulesOK

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


#7

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


#8

@GitHubRulesOK

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.


#9

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:


#10

@GitHubRulesOK

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?


#11

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 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

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 is to first set exit on escape in settings (EscToExit = true)
:start
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


#12

@GitHubRulesOK

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.