?
Solved

Javascript/VBScript Help

Posted on 2010-09-05
9
Medium Priority
?
617 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

770 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