Sumatra PDF is a PDF, ePub, MOBI, CHM, XPS, DjVu, CBZ, CBR reader for Windows

Making SumatraPDF accept /A page=numbers from Zotero

In Zotero, if the source PDF has a TOC, I get an option to open the PDF directly to the section by clicking the following link:

Zotero_TOC_Link

In its raw format, Zotero parsed the TOC into zotero://open-pdf/0_VWWUW7AT/332

Also, documentations for commands in Stata, as I may recall, also have its PDF_links that jump to the proper section in the linked PDF.

If I was setting Sumatra as the default PDF reader (for filetype .pdf), three Sumatra window will pop up, with first two being blank (gray) windows and the third being the file on its first page.


May I get a simple answer, of whether Sumatra can handle these PDF_links?

I am not surprised that Adobe Acrobat can open these links when set as the default program for .pdf files. Surprisingly, Xchange PDF Viewer (the old version) is also able to handle such “PDF_links”.


Thanks a lot!

All the best,

-Linfeng

ToC entries are generally called the document “outline” but many people call them “bookmarks”

They are a collection of “named destinations”

When calling SumatraPDF via an external command you can specify them or a page label like this

SumatraPDF.exe -named-dest “my bookmark” “filename.pdf”

also you can set page (and others like zoom)

SumatraPDF.exe -page 24 “filename.pdf”

this is slightly different syntax to acrobat but the result should be similar

I dont know how Zotero applies the commands for different apps but it should be possible to make it function the same way, if it is not adjustable then you need to raise a support question with them. One technique that may be required is an intermediate “shim” that is you tell Zotero to use a dummy application called say acro2sumatra.cmd which translates the commands from Acrobat format to SumatraPDF format.

There are various ways to combine SumatraPDF and Zotero as discussed in https://forums.zotero.org/discussion/comment/334930/#Comment_334930

Many comments at https://forums.zotero.org/search/?Search=sumatrapdf suggest there is no highlight but if you use the pre-release version then although highlight is still going through changes it should be stable enough.

This was made more complicated by the fact that it is a combination of Zotero and a plugin called Zotfiles

I used a portable copy for testing and found that I needed to make a couple of changes as described above I found it easiest to add an acro2sumatra.cmd file into the SumatraPDF folder (but it does not really matter where it is located)

my acro2sumatra.cmd file was one line

start "" "c:\program files\sumatrapdf\sumatrapdf.exe" -reuse-instance -%2 %3 %4

and in Zotero i simply told it to use that file

It would be simpler if zotfiles can be modified to provide the correct method as my “shim” is a workaround for the method that it uses to call acrobat

2 Likes

Fantastic! I can now keep the global PDF viewer as Sumatra, and use Xchange PDFViewer for annotating files through Zotero.

Thank you for the helpful pointer to the post on the Zotero forum. Indeed, there is an option to specify which PDF viewer/editor to use specifically for Zotero. Here is my current setting:


Just saw your recent post about appointing the acro2sumatra.cmd script as the “pdf viewer” for Zotero. Will check it out and update :slight_smile:

You will also find a technique in this forum to integrate xchange with sumatrapdf so the pages can be viewed via cross links between the two bypassing zotfiles when it may prove quicker see Use sumatra as external viewer

One more thing about running acro2sumatra.cmd. In my Zotero with version 5.0.85, it did not like the file extension .cmd. How did you set yours?

image

Using “Custom” navigate to the folder where you stored it and just type part of the name it should find the full name.

Just learned another Windows trick!

I appointed the script with the following content. Though, when clicking on the “link”, a dark window flashes (I guess it is a command window) and nothing happened.

start "" "C:/Program Files (x86)/SumatraPDF/SumatraPDF.exe" -reuse-instance -%2 %3 %4

Running "C:/Program Files (x86)/SumatraPDF/SumatraPDF.exe" through the command prompt did open Sumatra.


Also, thank you for pointing me to this solution that can get Xchange Viewer to open up the current page as displayed in Sumatra! Learning too much good things on a Friday night :slight_smile:

The black window is the result of using the .cmd file in a background window and ideally if zotfiles did it directly or the cmd was a .exe or .com file that would not happen. (I tried a bat to exe converter, which can run “hidden” or minimized so as to avoid that brief flash, however it adds complexity and delay that for a single user is not worth the trouble, but can be useful in a multi-user setting to avoid suspicion that something else is happening :slight_smile:)

If you click on the cmd file it should only see the - before %2 and then it will expect
zotfiles adds the second third and fourth parameters as page # "filename"

Syntax can be troublesome in some cases note that I used \ rather than / and in some systems it can look like the yen symbol. "Double quotes" can also cause problems in some languages and should be simple one key producing a pair of uprights.

Thanks for your workaround, but after that, every time I normally click to open a pdf from Zotero, the Sumatra will pop up a message like “Load error C:\Program Files(×86)\Zotero-”. So now I can open a pdf and go to page from the Table of Contents, but can’t open a pdf just by normally click.


how to improve the command above to avoid this happening? I 'm not very familliar with cml syntax in windows.

This should be a simple case of one line adjustment behaves the same for everyone BUT

The idea of command line adjustments is they should normally (but not always) work well where broken parts are "surrounded by double quotes"

Unfortunately cut and paste in a forum can itself be a problem, and the older images above were deleted by the discourse system !

However there are some cases where there is interference by mismatch or other symbols such as here seen by your text near the \ - but your image says more.

The intention here is that when Zotero calls SumatraPDF with a Page reference the command line is slightly adapted
Thus Acrobat /A page=123 "and filename" becomes SumatraPDF -page 123 "and filename"

That is done via the acro2suma.cmd by ignoring %1 (the /A part) and changing %2 (the page part) by adding a - in front of it without a space

What is happening in this case is that when double clicking the command is started but without any valid page request and file name it would therefore in SumatraPDF appear to be asking to open a file simply named “-” (actually if there is a file called “-” it will open it and wait for the next in the line)

The solution is a more complex IF page requested DO this, ELSE DO that.
so the CMD file just needs to see if %2 is “page” otherwise we could assume that %1 etc. is NOT /A but perhaps the filename

To Keep It Stupidly Simple (KISS) we just need to do something like an inelegant

@if /i [%1]==[/A] start "" "C:/Program Files (x86)/SumatraPDF/SumatraPDF.exe" -reuse-instance -%2 %3 %4
@if /i not [%1]==[/A] start "" "C:/Program Files (x86)/SumatraPDF/SumatraPDF.exe" -reuse-instance %1 %2 %3 %4
1 Like

Your commands work like a magic! Now pdfs can be opened from Zotero by SumatraPDF in both situations. Thanks, and have a nice day!