Is it possible to let sumatraPDF output the page number of the current page displayed somehow so that another program can access such info? For example, write the current page number to SumatraPDF-settings.txt? Thanks for any clues.
Home / Current page number of the page displayed for presentations
No plans to do that.
If you describe your use case I might come up with some solution, but writing out the page to a file every time it changes would not be good.
Current File and Page Number are exposed via ExternalViewers so can be sent to any external CLI App via CMD see the many examples in forum for different use cases.
Thank you for your response. I am thinking to write a CMD script to check which page the sumatraPDF is at in the current document, and then use the info to launch another sumatraPDF window with another PDF document at a page with the same page number (or -1 or +1 page etc). It is basically for the presentation purpose. If this is achievable, it can make sumatraPDF a nice competitor of MS PPT for two-screen presentation.
I checked my SumatraPDF-settings.txt file, and there is nothing under ExternalViewers. Can you provide more clues or examples to show how it works? Thanks.
Do you mean navigating to the next / prev page in the currently displayed document?
I’m confused by “launch another window with another document”. Why launch another window? Is “another document” the same as the one you’re querying for current page or a different document (different doesn’t make much sense to me).
I might add some way of controlling Sumatra with small JavaScript programs in the future.
In such case, would currentDocument.goToNextPage()
, currentDocument.goToPrevPage()
be enough for your purposes or would you need more commands?
The docs for configuring external viewers:
What I really like to do is to mimic what MS PPT does when doing a two-screen presentation, where one screen shows the full-screen presentation while the other screen shows the current page and the next page. For PDF presentation, I don’t think there is any app that can do this easily. Currently, what I can achieve using sumatraPDF is to first copy a PDF file to another name, and then use a CMD script to launch two sumatraPDF windows for the two PDF files at given pages, one in full-screen on one screen and another on the second screen, and to turn the pages forward in the two screens simultaneously in the script (with the help of -reuse-instance). It works but not convenient since I have to control the two screens using the script. I wish that the script can tell which page one sumatraPDF window is at and then automatically turn the other sumatraPDF window to a given page, such as the next page. If this is possible, the script can run in the background, and all I need is to turn pages in one sumatraPDF window that is in full-screen mode, similar to MS PPT. Hope I make my idea clear. Thanks for considering my question. I feel that sumatraPDF is pretty close to achieve this.
It may be possible to do that in one line so lets try to start to emulate your desire, as I see from what you request. To get two windows you could initially use
cmd /d /c "SumatraPDF.exe -new-window %1 %p"
That would open a second window at the current page of current file.
There would be several disadvantages, since the -new-window would not be on separate screen and need manually dragging to second monitor.
The best way to address that is use two separate SumatraPDF.exe sessions each with their own monitor settings. So the easiest way to do that, is to have a separate copy of SumatraPDF.exe portable in its own folder thus with its own setting file.
Separating settings can cause some shortcomings, that normally would not be recommended, however for this presentation usage should not matter. So
cmd /d /c "c:\Another\SumatraPDF.exe -reuse-instance %1 %p"
and assign a key combination such as ALTFD (or other nearby 3rd key such as G)
Should be enough to open second monitor with current page, to follow main presentation, and that can be driven in such a way that only the odd or even pages appear on the second monitor. (strictly -reuse-instance is not needed as it should be the default setting, but helps maintain consistency.) Maths at command line level can be tricky (not impossible) and we can thus target current page -1 or +4 etc. but to do that may require more than a single line approach using a .cmd script.
The way you structure the commands is specific to each users needs, but the core principles will be similar.
I like your idea of assigning a global key combination to invoke the command so that it can be run at any time. But I am not sure how you supply the page number or change to a different page number. Do you have to type it in a CMD window each time?
As I said in my earlier message, I partially achieved this with the help of Vim editor. I first copy the presentation file, say main.pdf, to another name, say main2.pdf, and open them in two sumatraPDF windows, one (main.pdf) is in fullscreen mode in one screen and the other (main2.pdf) is in another screen. Then I create a text file with one page number in each line, such as
1
2
3
4
I open the file in Vim and map a key, say F5, to the following Vim function:
fun! OpenSumatra()
let curpos = getline(".")
let nextpos = curpos + 1
exec ‘:!start SumatraPDF.exe -reuse-instance -fullscreen -page ’ . curpos . ’ main.pdf’
exec ‘:!start SumatraPDF.exe -reuse-instance -page ’ . nextpos . ’ main2.pdf’
endfun
Then all I need to do is to press F5, and depending on which page number my cursor is on, the fullscreen will show the page and the other sumatraPDF window will show the following page. One issue I have is that once F5 is pressed, the Vim window loses its focus, and I have to click it again before I can move my cursor to the next line and press F5 again. Even if this issue can be solved, it is not an ideal solution, and I still hope that there is a way that sumatraPDF window can output the current page number it is on and the script can automatically detect the page number and update the other sumatraPDF window. This way, the script can run in background, instead of in foreground as I am currently doing.
I am not sure how this can be done solely in CMD and batch command. If you have more details, please let me know.
[Later-Edit] TLDR to skip down to a working copy click here
I am assuming since you say “following” page you are similar to a Beamer presentation using every second page for notes and projection. and this method sould work for such cases
In advanced settings replace the ExternalViewers section with
ExternalViewers [
[
CommandLine = c:\windows\system32\cmd.exe /d /c ""C:\some where\SecondMonitor.cmd" "%1" -page %p"
Name = Pa&Ge on Second Monitor
Filter = *.pdf
]
]
the &followed by G is the ALT F extension to make the three keys closer together
This assumes you have a named folder for a given project which in this case I have called \some where\ but can be any subfolder with the pdf files in \anywhere\else\ (or beneath the same folder If you like, just edit as appropriate)
The content of SecondMonitor.cmd can be as simple as
"C:\Anywhere\SpdfX32.exe" -appdata "C:\Anywhere" %1 -page %3
Note since -page counts as %2 then on transfer the %p becomes %3
The reason I did not add the two commands within SumatraPDF was to deliberately keep them separate for testing, so you can alter them easily if not working well. You may find later that it is possible to make the call directly in external viewers without the SecondMonitor.cmd.
SPDFx32.exe is a second portable copy of your preferred version of SumatraPDF.exe, but again for testing helps if it is a different variety e.g. use 64bit for main and try 32bit for second copy then later you can try using a 64bit for both.
c:\Anywhere can be any other working directory or even same as C:\some where\ the important bit is the -appdata folder should be the same as for the second.exe
Why all these temporary workaround techniques? Its because Windows likes to name the two copies in memory as both SumatraPDF.exe so it can be difficult to stop a request for second instance NOT processed/showing as would normally be desired in the main window !!
How to use:- Open the double page file in the driving monitor as a two page spread (as seen here on the left) and using ALT +F +G we can see the first page in the projection Monitor (right hand screen)
Once you set up the layout as required then the left page will always be seen on the second screen when you press ALT +F+G
Limitations
If your notes are the first page and second page is the one to show you would need to add some math to the cmd file or change page order in an pdf shuffler.
When the command runs the keyboard focus transfers to second screen (often useful for navigation but not when you want to page down
and press keys in the driver window.) this can be overcome with extra routines to push focus back to main session by duplicating the call within a cycle from a second line in the cmd back to the main page and that could be + two pages on for the next invocation.
So have a play and see what might be possible.
I think now I understand your idea. I will give it a try and report back. Thanks a lot
What I really like to achieve is to open a pdf file in full-screen mode on one screen and then open the same pdf file but at the following page in another window on another screen. If I turn to the next page in the first screen, the second screen should turn to the next page automatically. I do not use Beamer, and I am not sure this is what Beamer can do or not. It is similar to MS PPT’s slide screen and presentter’s screen.
I think I implemented successfully what you suggested. But it also has some limitations as the method I tried based on Vim. Here is what I did and maybe you can tell whether it can be improved or not.
I first downloaded a 32-bit SumatraPDF-3.2-32.exe and created a second.com file with the following line
set PGNO=%2
set /a PGNO=PGNO-1
SumatraPDF-3.2-32.exe -page %PGNO% “%1”
Then I added the following in SumatraPDF-settings.txt
ExternalViewers [
[
CommandLine = “second.cmd” “%1” %p
Name = Pa&Ge
Filter = *.pdf
]
]
If I open the first sumatraPDF window and press Alt-F-G, the second sumatraPDF window showing the same pdf file but at the previous page. Then I move the second window to another screen and make it a full-screen. Now if I go back to the first window and turn a page and press Alt-F-G again, the full-screen will turn a page too. So it worked. But there are some limitations making this method not so convenient to use. The first is that once sumatraPDF window is in fullscreen mode, the shortcut key binding Alt-F-G stops working. Thus I have to control the whole thing from the second window, which is always one page ahead of the page showing in fullscreen mode, thus not very convenient. Also whenever Alt-F-G is pressed, the fullscreen takes over the focus. I have to click the first window first, turn a page and then press Alt-F-G again to complete the whole cycle.
If it is too much to ask sumatraPDF to output its current page number, having the ability to launch the external viewer defined under ExternalViewers using one shortcut key when the sumatrapdf window is in fullscreen mode would make this method much better and more useable. It would be even better if the launched external viewer will not steal away the focus of the sumatrapdf window. Hope kjk will consider this feature.
Thank you for the clever idea of using ExternalViewers.
Either F5 or F11 once that 1st screen is reselected the alt keys should pulldown menu (certainly does in latest 64 bit v3.3) The problem is that calling 2nd screen windows will shift keyboard focus to that 2nd screen.
The reason I suggested part 2 is in a CMD file is the neat way you used set /a
maths to shift back a page. So at the end line you can now shift the focus back into the first SumatraPDF 64bit in a similar fashion such that it moves on one or two pages to allow for next Alt+F+G.
set /a PGNext=PGNO+1
SumatraPDF-3.3.64.exe -reuse-instance -page %PGNext% "%1"
Thus hopefully achieving all your requirements in the one cmd. If you need a delay after second screen is called and recalling first screen then use an intervening timeout 10
where 10 is 10 seconds
If you need a timed loop sequence you could loop within the cmd but then might need
FOR /L %%F in …
and thus possibly have to start cmd with
SETLOCAL EnableDelayedExpansion
see EnableDelayedExpansion - Windows CMD - SS64.com
Thank you for further tips and patience. To make sure we are not confused by the screen names. I use the first sumatrapdf (64bit) window on the first screen that is in a regular mode and shows one page ahead of what I want to present, and the second sumatrapdf (32bit) window on the second screen that is in fullscreen mode and shows the page that I want to present.
I wish I could control the whole cycle from the second screen as this is the primary screen for presentation. Unfortunately, it is in fullscreen mode and Alt-F-G not working. I could press F5 or F11 to exit the fullscreen mode to access Alt-F-G. But I want to avoid this because it will interrupt the presentation.
If I understand correctly your method for returning the focus back to the first window automatically, I added another line in my second.com as follows:
set PGNO=%2
set /a PGPV=PGNO-1
REM the following line will update the second screen
SumatraPDF-3.2-32.exe -page %PGPV% “%1”
REM the following line will refresh the first screen
SumatraPDF.exe -reuse-instance -page %PGNO% “%1”
in a hope that it would refresh the first window and regain the focus. Unfortunately, it does not work, and it simply let the second screen show the same page as the first screen (I am surprised about this because the second screen runs 32bit sumatrapdf and I am not sure why the 64bit sumatrapdf will refresh the 32bit window). If I delete -reuse-instance in the second command, it will simply launch a new window instead of updating the second screen. Looks like this method does not work. Maybe I did not understand your method accurately. Anyway, I still hope I can access the ExternalViewers command by a single shortcut key in fullscreen mode.
The reason I said try to keep 2 SumatraPDF sessions separated by type is that windows and SumatraPDF are HIGHLY efficient by default in windows memory of directing control to the Master session only (usually the first in memory) I will see If I can emulate your setup but it is important the two exes are not in the same location sharing the one settings file hence my mention to use -appdata “c:\second\folder” where second exe is located
They are already in different names. I will try to put them in different locations and add -appdata to one of them to ensure they have different appdata folders. Thanks.
I am wondering if I am working wrong way round since you are saying you wish presentation screen to do the driving ? So one screen is usually notes for the presenter to control whilst secondary (presentation .projector screen) is for audience to view without interference.
In a typical MS PPT setting, you are right and the presenter’s screen is the primary screen that drives everything because it does show both the current page and the next page plus some notes. In my situation, I do not worry about any notes and all I am concerned about is to show the following page for reference. If my first screen can show two windows, one for the current page and one the next page, and the second screen shows the current page in fullscreen, then you are right and I should use the first screen to drive everything. But I think working out a method to manage three windows may be even more difficult. That is how I came up the idea that I am trying to achieve.
Ok I think I have it, but on rereading the thread I may still be wrong page round, if so swap page 1 and 2 over AND/OR change PGshift=PGNO-1 to +1
I used PaulsPresenter.cmd to setup for drag and drop a file on top or double click to start both without files
@echo off
Set "Folder1=C:\Presenter\1stFolder"
Set "Folder2=C:\Presenter\2ndFolder"
REM the following line SHOULD start the first screen on page 1
start "Sumatra1" "%Folder1%\SumatraPDF.exe" -appdata "%Folder1%" -page 1 %1
REM the following line SHOULD start the second screen on page 2
start "Sumatra2" "%Folder2%\SumatraPDF.exe" -appdata "%Folder2%" -page 2 %1
Sumatra2 Advanced settings has at the top
ReuseInstance = true
UseSysColors = false
RestoreSession = true
and
ExternalViewers [
[
CommandLine = c:\windows\system32\cmd.exe /d /c "start "" /MIN C:\wherever\Second.cmd "%1" %p"
Name = Pa&Ge
Filter = *.pdf
]
]
beware I am using start “” /MIN to minimise annoying black screen but that requires an exit in second.bat to return AND no quotes around C:\wherever\Second.cmd
unless it has a space when they are required
and wherever\second.cmd should look like
@echo off
Set "Folder1=C:\Presenter\1stFolder"
Set "Folder2=C:\Presenter\2ndFolder"
set PGNO=%2
Rem prepare the shifted pages this could be -2 -1 +1 or +2 depending on needs
set /a PGshift=PGNO-1
REM the following line SHOULD reset the first screen shifted e.g. -1
start "Sumatra1" "%Folder1%\SumatraPDF.exe" -appdata "%Folder1%" -page %PGshift% %1
REM the following line SHOULD return focus back to the second screen
start "Sumatra2" "%Folder2%\SumatraPDF.exe" -appdata "%Folder2%" -page %PGNO% %1
exit
See If I am close, but there are bits you need to watch out for. So with task manager active you should only see the two sumatraPDF.exe (not a third). You can alter each screen settings so one could be say “facing” or “book mode” but you might want screen one (Sumatra1) to be in advance settings
ReuseInstance = false
UseSysColors = false
RestoreSession = false
If all is working well then see if you have problems by replacing the 32bit 2nd copy with a second 64bit as I have not tested that yet Now tested all is working well with both as exactly same version 64bit even though both then have same name in memory.
Funny things that could appear odd later
I used a txt file for a test and as fonts are set different then one screen had 3 pages the other had 4 but you are using pdf only so that would not apply. However it reminds me that some pdf can have strange page number settings.
With just one page shift and two pages per screen then the middle page is on both screens (you would need to use shift=2 to avoid that)
So now we have a versatile twin screen presenter with minor edits the pages can jump 4 at a time or with notes and slide on alternate pages we can jump forwards 2 pages as per MS / Beamer presentations.
What a nice solution for the issue. I just tested it and it works beautifully, especially now the focus automatically returns to Sumatra2 so I don’t need to click the window first before press Alt-F-G. Thank you so much.
It now makes me wonder whether we can achieve exactly what MS PPT does. That is, there are three sumatra windows: Sumatra1 is in fullscreen mode in one screen, and Sumatra2 and Sumatra3 are in regular mode in another screen where Sumatra2 shows the same page as Sumatra1, and Sumatra3 shows the following page, and the control is done via Sumatra2 window. This way, I just need to look at Sumatra2 window, turn a page and press Alt-F-G, which will give me similar experience as MS PPT. I will give it try and report back. Now I just wish if I could use a single key to replace Alt-F-G, it would be perfect.