Link to home
Start Free TrialLog in
Avatar of masdf123
masdf123

asked on

Javascript/VBScript Help

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

Avatar of dax_bad
dax_bad
Flag of Denmark image

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
Avatar of masdf123
masdf123

ASKER

Can I say something, so it's only finding. Text in first page?
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.
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?
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

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.
ASKER CERTIFIED SOLUTION
Avatar of dax_bad
dax_bad
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey masdf123,

Do you need any further assistance with this question?

cheers
Daniel
Thanks for the points mate