Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to sent a search term from VFP to Foxit-Reader 5

Status
Not open for further replies.

german12

Programmer
Nov 12, 2001
563
0
16
DE
Via thread184-1829365
I got excellent help from here how to have access from VFP to Foxit-Reader.

Many thanks, with that I can now switch between VFP and Foxit-Reader-pdf-files, have also now control over meanwhile 24 magazines each about 75 pages, can look everything what has been mentioned in all tables of contents, can have a look into the last edition and switch between 24 pdf-files up to now always with a search term and its known page.

I also looked into the Foxit-Reader (did not use it before) and saw that it is also possible to use a search term and Foxit shows a list
with all places where this search term appears in the PDF file.

However I would like to send search terms directly (by program) from a VFP file to the Foxit reader, but I don't know wether that is possible.
In the thread mentioned above, for example, it was the suggested search for a specific page that can be sent from VFP to the Foxit reader:

RUN /N "…Foxit Reader.exe" "C:test.pdf" /A page=5
that works fine.

My question: Is there a similar way to send only a search term, when the page is not available?

Thanks for any help.
Klaus


Peace worldwide - it starts here...
 
The full documentation of command line options of Foxit Reader is here:

Searching is not within the options, and it also makes no sense. You can't send a command to an already started Foxit Reader you can only give it a command option when starting it, and as you can see specifying a search term instead of a page number is not supported. That would also not be very ferasable, because for searching 2 or more search terms you'd still need to start 2 or more readers. It's not making much sense.

Chriss
 
Klaus,

Have you tried the code I posted in the second post in the other thread? You can adapt it as follows:

Code:
RUN /N "…Foxit Reader.exe" "C:test.pdf"

* Instantiate Windows Scripting Host
owsh = CREATEOBJECT("wscript.shell")

* Activate Foxit
owsh.AppActivate("Foxit")

* You might need to pause for a few ms here to allow time for
* Foxit to become activated

owsh.SendKeys(< keystrokes here >)

In this case "keystrokes here" would represent whatever keys are needed to search for the target term.

I haven't tested this, so treat it as a starting point only.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Also remember the general advice from the older thread to use autohotkey or autoit for automation of applications which don't provde an interface like Word, Excel, Outlook etc for COM automation.

Here's about the same question of searching PDFs with autoitscript and some suggested answers:

Chriss
 
Mike:
I tried your code as follows:
* First, use ShellExecute() to launch the PDF in the user's default viewer.
* I assume you already know how to do this.

* Instantiate Windows Scripting Host
*owsh = CREATEOBJECT("wscript.shell")
* Switch to the PDF viewer
*owsh.AppActivate("My Document")
&& Substitute the name of the PDF file (as it appears in the viewer's title bar)

Code:
Clea

Run /N "FoxitpdfReader.exe" "Eurams_2419_LR.PDF"

* Instantiate Windows Scripting Host
owsh = Createobject("wscript.shell")

* Activate Foxit
owsh.AppActivate("FoxitpdfREADER.exe")
Wait Window Timeout 10
* You might need to pause for a few ms here to allow time for
* Foxit to become activate
*The following expression "Rückversicherer" is definitely in the pdf included.
owsh.SendKeys("Rückversicherer")

...but I had no success so far.

All I saw is
a) that the term "Rückversicherer" was added to the code via Sendkey.
b) the RUN command opened the Foxitpdfreader with the last page which was opened in normal use by Foxitpdfreader before.
But that was not the page where "Rückversicherer" was mentioned.

I can not find an error in the script so far - and as Chriss already wrote
Code:
Searching is not within the options
I assume that this can also not be done with Shellexecute scripts provided that there is not another error made by me.

But of course I have to thank you for that approach recommended.
Klaus


Peace worldwide - it starts here...
 
Chriss
I also thank you for your hints concerning Foxitpdfreader and Auto-It.
Foxitpdfreader: It can also be helpful if you know that something does NOT work...that saves a lot of further attempts and energy.
Auto-It: I have no experience with that yet, but I will
look into it. Your sources can help.
Klaus


Peace worldwide - it starts here...
 
Klaus,

I mentioned that "keystrokes here" would represent whatever keys are needed to search for the target term. Those keys are not only the search term itself ("Rückversicherer" in this example), but also the key that is used to invoke the search function. In the case of Foxit, I believe that key would be CTRL+F, which you would send as ^F.

So try this:

[tt]owsh.SendKeys("^FRückversicherer")[/tt]

By the way, I used RUN /N this time because that is what you showed in your example. In practice, I would probably use ShellExecute(). But that wouldn't make any difference to the rest of the code.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,
It works! Thank you very much.
I only had to add an additional owsh.Sendkeys('{ENTER}')

Code:
* Termschickn.prg - sends terms from VFP to Foxitpdfreader pdf-file (Foxitpdfreader = external program)
* First, use ShellExecute() to launch the PDF in the user's default viewer.
* I assume you already know how to do this.

* Instantiate Windows Scripting Host
*owsh = CREATEOBJECT("wscript.shell")


* Switch to the PDF viewer
*owsh.AppActivate("My Document")
  && Substitute the name of the PDF file (as it appears in the viewer's title bar)
clea

RUN /N "FoxitpdfReader.exe" "Eurams_2422_LR.PDF"

* Instantiate Windows Scripting Host
owsh = CREATEOBJECT("wscript.shell")

* Activate Foxit
owsh.AppActivate("FoxitpdfREADER.exe")
WAIT WINDOW TIMEOUT 5
* You might need to pause for a few ms here to allow time for
* Foxit to become activated

owsh.SendKeys("^FDie wichtigsten Termine der Woche") 

*This term (english: the most imporant dates of the week)e.g. is an important section in the magazine, 
*but it is not given a page number in the table of contents.

owsh.Sendkeys('{ENTER}')
this leads to:
Weeknews_exb1sv.png


Btw: Where/how can I learn more about this script langugage?
Very interesting!
Regards
Klaus


Peace worldwide - it starts here...
 
Klaus said:
Where/how can I learn more about this script langugage?

You thinki you're using a scripting language because you use the wscript.shell object? Well, you're not, it's just a COM object of the windows scripting host WSH, and you use it's feature to activate an app, well, AppActivate(), and it's method to send keys to that application. The actual WSH scripting language main focus is not automating applicatios, though. It is for scripts doing some tasks with DOS like commands.

WSH itsef ( is outdated, because the latest scripting that Windows offers and uses is Powershell and if you would want to learn a scripting language that's onboard of Windows, then learn Powershell, not WSH scripting. That also isn't focused on automating applications, it's for system tasks you can script. Part of functionalities surely also is to start executables, but Powershell - while valuable in itself - is stil not for application automation.

MS never replaces anything, you stil have the ability to do bat or cmd batch files with Shell commands (cmd.exe is the Windows Shell), WSH allows to script things with, I think a VB scripting language or alternatively JS. Powershell scripts can use a much more powerful scripting language, the problem with these on board scripting things is that they can be very restricted. For your own use, you can allow executing any powersehell (.ps1/.psm1/.psd1) files, but first, even before learning any of these options, I'd still rather consider using one of the automation tools Mike and I suggested, as their focus is on enabling applciation automation despite no such interface offered by the application itself, those tools are the experts about that aspect.

Chriss
 
Chriss,
Thanks you for your in-depth explanation of WSH and Powershell.
I am always grateful for that.
There is still a lot to learn, but that is a good thing, especially when you are already 83 years old.
Best regards
Klaus

Peace worldwide - it starts here...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top