Solved

Javascript/VBScript Help

Posted on 2010-09-05
9
597 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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…

896 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

11 Experts available now in Live!

Get 1:1 Help Now