Forum moved here!

Home / How to send DDE command to SumatraPDF

Ma_Jordan

Hello,
I am a new comer to SumatraPDF.
I wanted to communicate with it by DDE. So

1. I just downloaded the SumatraPDF 3.3.3 64-bit in my win7 .
3. I mannually started the SumatraPDF and opened one PDF file.
4. In windows console, I ran DDECmd.exe servers, but no server named Sumatra or similarly named popped up.
I am wondering how the DDE commands which are documented in the SumatraPDF site could be send ?
GitHubRulesOK

In general there must be an agreement in DDE to communicate either as 32 bit or 64bit since MS decided there cannot be DDE comms between dissimilar bitwise apps so since DDE Command is 32 bit you need to use 32 bit SumatraPDF to be seen broadcasting on that channel.

Also SumatraPDF must be running so best to call SumatraPDF 32bit with a file open if possible (not essential) first before sending controls. AND if using Chris Oldwoods app it may not list SUMATRA as a SERVER you may need to add it manually.

Just to check as DDE commands can be very fickle, I used the simpler oneliner cl-2-dde from the google zip

>cl-2-dde-1.0.exe @- -SUMATRA- -control- -[Open("C:\Users\K\Desktop\Shrinkpdf.pdf",0,1,1)]-


It opened the file at the first page (in a new tab) in a recent version on windows 7

Then to move to page 2 used

cl-2-dde-1.0.exe @- -SUMATRA- -control- -[GotoPage("C:\Users\K\Desktop\Shrinkpdf.pdf",2)]-


BUT BEWARE its case sensitive and I first wrote GoTo which appeared not to work. (Mia Culpa)

Finally to prove it still works in DDE Query I used GotoPage ,3

More hints at [How-To] Part1 - Using CLI & DDE with SumatraPDF - SumatraPDF - Sumatra Reader Discussion Forum (sumatrapdfreader.org) sadly the images were lost by the server.

Ma_Jordan

@GitHubRulesOK
I have been given many clues by your replay. Many many thanks.

First,

1. I Instaledl the SumatraPDF 3.3.3 32bit version
2. Run it , open a pdf file
4. Input the DDE command [GotoPage(“C:\Users\OneCrazyStone\Desktop\123.pdf”,3)], whose type is CF_TEXT
5. Tried to run “Request Item”, “Poke Item” or “Execute” submenu in Command menu. ( I don’t know which type of Item is correct to emit ) . Feedbacks were always sth like invalid parameter. Following this error message, the caption of DDE query window changed to “DDE Query” from " DDE Query - SUMATRA|CONROL". It might means the connction has lost or never been established.

Second,

I failed to find the cl-2-dde-1.0.exe , can you pls send it to me ?

Third,

(Let me clarify my intent to use DDE. When reading the PDF, I need to take some notes in other app like OneNote, and also record the PDF filename, page involved, or even the viewport and scroll locations. I call these infos as Link. Later when I review the notes, with the help of DDE, I can send Link info to SumatraPDF and ask it to open specified file and navigate to the PDF page. )

BRs
Jordan Ma

GitHubRulesOK

The ITEM needs to be sent as execute CF_TEXT, but it needs to be sent whilst SumatraPDF is active the 1st one must then Open (if the file is not already open) and 2nd must GotoPage . So it is very much one line at a time like a batch file sequence, but DDE is less forgiving or verbose on feedback when a single character is not right. Often with that GUI, I may need to disconnect and reconnect to test a fresh attempt because the previous one had a bad entry the nice thing is you can add a list of items in a script file to run many line quickly.

I downloaded yesterday cl-2-dde1.0.exe from the referenced still active link from command-line-version-dde-client download I chose standard zip file for my testing as it is so much easier to use for command line. Note there is also a dbg version.

However to call SumatraPDF easily from another app (thus use 64 bit direct), you can use CLI calls something like below but beware you may need to play with the order of switches to get exact behavior or split a command into two lines same as DDE. In general there are more options via CLI that you can combine on the one line at a time like -scroll etc.

"Sumatrapdf.exe" -reuse-instance -page=3 -zoom=100 "path/filename.pdf"

Ma_Jordan
1. I downloaed the cl-2-dde-1.0 tool, it works as I expected. Thank you very much.
2. the other way, CLI, I have not try. There is sth wrong with my window, I guess it is virus-infected.

Anyway DDE proves to be effeictve. From the document , the DDE coomands provided can not completely satisfy my purpose. Because there are only Set commands, not inlcuding Get commands. I downloaded the source code of SumatraPDF, in order to find the way to add Get DDE commands.

You helped me a lot, thanks.

GitHubRulesOK

It is not easy to “get” info from SumatraPDF but you could search the issues and forks for similar queries/dll wrappers. It only added DDE server for LaTex Editors a long time ago where the file did not need closing or driving more than constantly reopen on a given page, it was as much as was need then and no more than that. A few extras may have been added but it was not intended as an API.

Whilst using SumatraPDF as an app the only direct usage output is for Current Filename and Page (possibly selection in recent addition) and that can be set to a hotkey that calls an ExternalViewer command such as a clipboard utility or exe to process that info, the other common output is a synctex method for opening an editor with current indexed location but that is not generally useful to other non LaTeX apps

Ma_Jordan

It is very kind of you to inform me of these backgrounds.

What do you do at work? Are/Were you a coder?

GitHubRulesOK

My past forte was Tech Support for CAD/Graphics Applications so very low ability to code (but dabbled lightly with practically every computer language you might mention from 4th…Ada… Assembler…to ZPL and beyond ) especially do not understand SumatraPDF c++ code base but a vast amount of know how about users encountering related problems with such tech.

Ma_Jordan

Very glad to meet you here !