VisualBasic - get number of pages

Post Reply
User avatar
JimmyHartington
Member
Posts: 28
Joined: Tue Mar 22, 2011 7:38 am

VisualBasic - get number of pages

Post by JimmyHartington »

Hi



I have a Visual Basic script, which logs data about jobs to an Excel-file.



Now I have tried to modify it to log the number of pages in a pdf.

I use this code:

theSpreadSheet.Cells(theRow,2).Value = job.getVariableAsString("[Stats.NumberOfPages]", s)



But I get an error on getVariableAsString.



Is it possible to get this data in Visual Basic?



The original script was written by David van Driessche.



Here is the script.

'==================================================================================================

' This is an example script that shows how to access information from a job and log it into an

' excel spreadsheet

'

' ----------------------------------------------------------------

' Author:David van Driessche, Gradual Software

' Last changed: August 21, 2006

' Copyright (c) 2006 - Gradual Software

' ==================================================================================================



' ------------------------------------------------------------------------------------

' Gets a handle to Microsoft Excel

'

' Returns: An object representing Microsoft Excel

' ------------------------------------------------------------------------------------

Public Function initializeMicraosoftExcel()

Set initializeMicrosoftExcel = CreateObject( "Excel.Application" )

End Function





' ------------------------------------------------------------------------------------

' Finalize Microsoft Excel, quits the application and releases the reference

'

' inExcelApplication: The object representing Microsoft Excel

' ------------------------------------------------------------------------------------

Public Function finalizeMicrosoftExcel( ByRef ioExcelApplication )

ioExcelApplication.Quit

Set ioExcelApplication = Nothing

End Function





' ------------------------------------------------------------------------------------

' Open a given workbook (identified by a full path)

'

' inExcelApplication: The object representing Microsoft Excel

' inWorkbookPath: The full path to the workbook

' ------------------------------------------------------------------------------------

Public Function openWorkbook( ByVal inExcelApplication, ByVal inWorkbookPath )

Set openWorkbook = inExcelApplication.Workbooks.Open( inWorkbookPath )

End Function





' -------------------------------------------------------------------------------------

' logJobInformation

'

' Logs all information for the current job in the given spreadsheet

' --------------------------------------------------------------------------------------

Sub logJobInformation( s, job, inSpreadsheetPath )



' Get hold of Microsoft Excel and get the correct sheet

Set theExcel = initializeMicrosoftExcel()

Set theWorkbook = openWorkbook( theExcel, inSpreadsheetPath )

Set theSpreadSheet = theWorkbook.WorkSheets("Log")



' Find the first free row

theRow = 1

Do Until (theSpreadSheet.Cells(theRow,1).Value = "")

theRow = theRow + 1

Loop



' Now log various details about this job

theSpreadSheet.Cells(theRow,1).Value = job.getName()

theSpreadSheet.Cells(theRow,2).Value = job.getVariableAsString("[Stats.NumberOfPages]", s)



' Close down the spreadsheet and Microsoft Excel after logging this job

theWorkbook.close True

finalizeMicrosoftExcel( theExcel )



' Note in the PowerSWITCH log that we did our thing

s.log 1, "Logged: " & job.getName()



End Sub





' ------------------------------------------------------------------------------------------------

' 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 information about the logfile we need to update

Dim theSpreadsheetPath

theSpreadsheetPath = s.getPropertyValue( "propSpreadsheetPath" )



' Log the information for this job in the spreadsheet

Call logJobInformation( s, job, theSpreadsheetPath )



' Always send just the original job on to the output folder

job.sendToSingle job.getPath()



End Function



User avatar
Terkelsen
Member
Posts: 126
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

VisualBasic - get number of pages

Post by Terkelsen »

Hi Jimmy,



You could try contacting David at david.van.driessche@fourpees.com
Post Reply