Solved

Javascript/VBScript Help

Posted on 2010-09-05
9
595 Views
Last Modified: 2012-08-13
Hi,

I have the attached script. Which checks the number of pages in each pdf and puts them into relevant folder.

1page pdf goes to folder 1
2page pdf goes to folder 2
...
And after 4 pages all files go to a specific folder.

This script is ran using Enfocus PowerSwitch.

I would like to ammend it, so that it finds for 2 specific words on the first page of each file.
Example: "word1" and "word2"

If both words were found, put then in folder A (Success)
If both or 1 words was not found, put the file in folder B (Fail/Error).

Please help
'==================================================================================================
' This example script drives Adobe Acrobat to query the number of pages from a PDF file. It then
' searches for a connection called "Output (x)" where x is the number of pages in the PDF file. If
' found the PDF file is moved through that connection; if not found it is moved to error out.
'
' ----------------------------------------------------------------
' Author: David van Driessche, Gradual Software
' Last changed: September 26, 2006
' Copyright (c) 2006 - Gradual Software
' ==================================================================================================


' --------------------------------------------------------------------------------------------------
' getConnectionByName
' 
' This function gets the full list of outgoing connections for the given script element and searches 
' through this list for a connection with a given name.
' If such a connection is found it is returned, if nothing is found this function returns null.
' --------------------------------------------------------------------------------------------------
Public function getConnectionByName( ByVal s, ByVal connectionName ) 

	' Get the list with connections from this script element
	Dim theConnections
	Set theConnections = s.getOutConnections()

	' Loop over all of them and see if we find the correct one
	for i=0 to theConnections.getCount()-1

		if (theConnections.getItem(i).getName() = connectionName) Then
			getConnectionByName = i
			exit function
		end if

	next

	' Nothing found, return null
   getConnectionByName = -1

end function


' --------------------------------------------------------------------------------------------------
' getPageCountFromAcrobat
' 
' Launches Adobe Acrobat and gets the number of pages from a job
' --------------------------------------------------------------------------------------------------
Public Function getPageCountFromAcrobat( ByVal InputFilePath )

	' Create the Adobe Acrobat application object and an object
	' to handle PDF documents on low-level
	Set AcrobatApplication = CreateObject( "AcroExch.App" )
	Set pdDocument = CreateObject("AcroExch.PDDoc")
	
	' Try to open the input document and process it
    If pdDocument.Open(InputFilePath) Then

        ' Count number of pages
        getPageCountFromAcrobat = pdDocument.GetNumPages()
	
	Else
	
	    ' Found nothing or failed, just returned zero
	    getPageCountFromAcrobat = 0
	
	End If
	
   ' Make sure to clean up before leaving
   pdDocument.close()
   Set pdDocument = Nothing
   Set AcrobatApplication = Nothing

End Function


' --------------------------------------------------------------------------------------------------
' jobArrived
' 
' Script entry point that is called for each new job that enters the input folder for this script
' --------------------------------------------------------------------------------------------------
 Function jobArrived(s, job)

	' Get the number of pages from Adobe Acrobat
	theNumberOfPages = getPageCountFromAcrobat( job.getPath() )

	' Get the list with connections from this script element
	theOutConnectionIndex = getConnectionByName( s, "Output (" & theNumberOfPages & ")" )

	' Move to that connection if found, or to error if not found
	if (theOutConnectionIndex = -1) then
		job.sendToData 3, job.getPath()
	else

		Dim theConnections
		Set theConnections = s.getOutConnections()
		job.sendTo theConnections.getItem( theOutConnectionIndex ), job.getPath()
	end if 

 End Function

Open in new window

0
Comment
Question by:masdf123
  • 6
  • 3
9 Comments
 
LVL 6

Expert Comment

by:dax_bad
ID: 33610503
Hi

You can use the FindText() method of the AcroExch.AVDoc object, it returns a True or -1 if the text is found, otherwise false or 0.

 FindText params: StringToSearchFor, caseSensitive (1 or 0), WholeWords (1 or 0), '  'ResetSearchToBeginOfDocument (1 or 0)

sText = "word1"
foundText = gAvDoc.FindText(sText, 1, 0, 1) 'Returns -1 if found, 0 otherwise

Cheers
Daniel
0
 
LVL 1

Author Comment

by:masdf123
ID: 33611589
Can I say something, so it's only finding. Text in first page?
0
 
LVL 6

Expert Comment

by:dax_bad
ID: 33615208
Im pretty sure that method looks through the entire document, and exits if it finds the word. The last parameter just resets the method to start from the beginning.
0
 
LVL 1

Author Comment

by:masdf123
ID: 33623233
What if I want to search only the first page, can I specify something?

My original script used: AcroExch.PDDoc

And yours uses: AcroExch.AVDoc

Whats the difference?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 6

Expert Comment

by:dax_bad
ID: 33625061
Sorry the AcroExch.AVDoc object is the active acrobat document, i think it needs to be open to work like that, so AcroExch.PDDoc is the correct one to use as this is the physical document.

Try this snippet

ps: dont have adobe acrobat pro installed, so havent tested it. let me know if it works
Set pdDocument = CreateObject("AcroExch.PDDoc")
path = "" 'Document path

If pdDocument.Open (path) Then
page = pdDocument.AcquirePage(1)
Ok = page.FindText("CPU", 0, 1, 1)
msgbox(Ok)
end if

set pdDocument = Nothing

Open in new window

0
 
LVL 1

Author Comment

by:masdf123
ID: 33626632
Can you refer to the initial script I gave and suggest the script accordingly. As I don't want a message box. I just want the file which had the word "CPU" in the first go to a folder and rest go to a fail folder.

In my initial script it does something similar while counting page numbers.
0
 
LVL 6

Accepted Solution

by:
dax_bad earned 500 total points
ID: 33627372
Add this function to your code and call it with pdf document path and a search word, it will return true if the word is found or false if not

so something like this

if findWord(path,"Word") = True Then
'Put file in this found folder
Else
'or this folder fail folder
End if  
Function findWord(ByVal inputFilePath,ByVal searchWord)
Set pdDocument = CreateObject("AcroExch.PDDoc")

If pdDocument.Open (inputFilePath) Then
    page = pdDocument.AcquirePage(1)
    If page.FindText(searchWord, 0, 1, 1) = True Then
    findWord = True
    End if
Else
   findWord = False
end if

set pdDocument = Nothing
End Function

Open in new window

0
 
LVL 6

Expert Comment

by:dax_bad
ID: 33765020
Hey masdf123,

Do you need any further assistance with this question?

cheers
Daniel
0
 
LVL 6

Expert Comment

by:dax_bad
ID: 33873160
Thanks for the points mate
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now