Click here to Skip to main content
15,885,875 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
There is a third-part application that houses a list of PDFs. The only way to open them, is to double-click each item one at a time, or press Enter on a highlighted item. Once the PDF opens, a temporary file is saved in C:\Temp. I created a tool that halfway works. It basically uses sendkeys to press enter on an item, then it listens for the process "Acrobat", closes the PDF, then goes to the next item. However, this is all in a For loop and it seems that if there is any network lag, it will skip lines and or freeze... I am a new programmer and looking for a point in the right direction of how to accomplish this:

1.) Open each PDF
2.) Close each PDF
3.) Go to the next line down in the other app and repeat 1-2-3

VB
Sub ProcessPDF()
	Dim z As Integer = Next1
	AppActivate("Hyperspace")
	For i = 1 To z			
		SendKeys.SendWait("{ENTER}") ' Open PDF
		p = Process.GetProcessesByName("Acrobat") ' Check if PDF opened
		If p.Count > 0 Then
			p(0).CloseMainWindow()	'Close PDF
			SendKeys.SendWait("^Q") 'Quit current screen 
			SendKeys.SendWait("{DOWN}") 'Go to next PDF
		End If
		Next1 = Next1 - 1
		label2.Text = Next1 & " PDFs Left!"
	Next
End Sub
Posted
Updated 6-Jan-16 9:57am
v2
Comments
Sergey Alexandrovich Kryukov 6-Jan-16 16:47pm    
Bad idea: 1) nothing guarantees that Acrobat reader is installed; 2) Acrobat reader is a very bad program; 3) UI developed with SendKeys is abuse, not reliable, etc.
I don't know your purpose and even application type, but it would be good to avoid using PDF at all...
—SA
Member 12248279 6-Jan-16 17:18pm    
This is a tool I use only on my computer and it will not be used by anyone else. It is to help me expedite my work.
Karthik V Ambakad 6-Jan-16 17:22pm    
I second relying on not using another program as a base and using send keys I'm not stating acrobat reader is bad.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900