Solved

Javascript/VBScript Help

Posted on 2010-09-05
9
612 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

717 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