-1

In my C++ Windows application I use ShellExecute to open a remote PDF file in the internet browser at a certain PDF Destination (dynamic bookmarks provided by Adobe Acrobat Reader):

ShellExecute(NULL, "open", "https://www.myweb.cloud/guide.pdf#dest_1", NULL , NULL, SW_SHOWNORMAL);

Then if I want to move to another Destination, another call to ShellExecute (with #dest_2 in the URL) simply open another page in the browser and download the PDF again opening it at that Destination.

Is there a way to programmatically change the URL (from #dest_1 to #dest_2) without making the browser to open a new page e re-dowload the PDF?

I also use LibCurl in my application in order to retrieve data from remote servers. Can I reach my goal with LibCurl? If so, could you plese show me a code sample?

Thanks in advance.

  • Alas, you are looking at a very deep rabbit hole. Frameworks exist to help you, though, like [Selenium](https://www.selenium.dev) and [Puppeteer](https://github.com/puppeteer/puppeteer) and [Microsoft Playwright](https://playwright.dev/) and [Robot](https://robotframework-browser.org/) — of which I know nothing but one of these ought to help if you want to go that way. – Dúthomhas Sep 24 '22 at 18:40

1 Answers1

0
  1. External links opened with ShellExecute are always opened in a new tab by default. Chrome can't change this behavior. Early Firefox had an option for opening an external link in a currently active tab, but does not seem to have it now.
  2. You can download files with libcurl, see url2file example. After a file has been downloaded, you can open it in a certain application with ShellExecute. You just need to find an application, that is suitable to your requirements. For example Adobe Reader does not seem to support opening in the same tab 1, 2. As @KJ commented while I was typing my answer, sumatrapdf -reuse-instance seem to be suitable for you.
  3. You can use Edge WebView2 component in your app instead of a browser.
273K
  • 29,503
  • 10
  • 41
  • 64
  • Thanks for your replies. I will surely investigate the tools you suggested, but firstly I'd like to better explain my goal. In my C++ application I provide the keyboard F1 command in order to open the PDF giude at the exact bookmark where the explanation of the the user current activity is located. I use Adobe Acrobat Pro for my guide because it provides Destinations other than simply bookmarks. Destinations are very useful because they remain valid while you add or delete text (pages) in your PDF. – Gianni Rossi Sep 25 '22 at 14:02
  • Also, I would like to leave the PDF guide on my remote server so that it will be always updated and, most important, my users do not have to install Acrobat. So my users' normal behavior will be: 1) they press F1 in a certain phase of the application, the guide is downloaded on the internet browser and will appear at the corresponding Destination. Then they move to another phase of the application and press F1 again for that task. Here I would like to simply move to the new Destination of the guide while it remains on the same page of the browser. Do you think there is a way to do this? – Gianni Rossi Sep 25 '22 at 14:04
  • 1
    You can't do it in a browser. You can do it in your app with Edge WebView2 component. – 273K Sep 25 '22 at 15:51
  • Thanks KJ, I will follow your suggestion and try sumatrapdf DDE GotoNamedDest command in order to jump from a destination to another. Just a final question: are named-destinations created by Adobe Acrobat recognized by sumatrapdf? – Gianni Rossi Sep 25 '22 at 19:03
  • @KJ Thanks for your help. I've installed SumatraPDF and I found it suitable for my goal. So I'm thinking of abandoning the idea of keeping my PDF guide on a remote server and deploy it to my users together with my application. Then I'll suggest to my users to download and install SumatraPDF themselves or maybe I could directly install it together with my application, do you think that SumatraPDF licence permits this? – Gianni Rossi Sep 27 '22 at 09:48
  • @KJ Finally, once the users has SumatraPDF, in my application I could use DDE to: 1) open my PDF guide the very first time they press F1; 2) jump to the proper named-destination all the subsequent times they press F1. Do you think that all this behavior is feasible? Unfortunately I don't know DDE programming so I'm asking to one of my collegues to help me on this side. Thanks again. – Gianni Rossi Sep 27 '22 at 09:48
  • @KJ I implemented in my C++ application the DDE comunication with SumatraPDF (V3.4.6 64-bit). The Open commands works fine using this syntax: `[Open(""[,,,])]` whereas the following commands to jump at a certain named-destination or page are not executed: `[GotoNamedDest("","")]` `[GotoPage("",)]` Please remember that I created the named-destinations using Adobe Acrobat Pro. What am I doing wrong? – Gianni Rossi Sep 30 '22 at 11:01
  • @KJ, ok thanks, I've posted my issue here including my sample PDF file and DDE commands: https://github.com/sumatrapdfreader/sumatrapdf/discussions/2993 – Gianni Rossi Oct 01 '22 at 13:33