07-06-2011, 10:00 PM
Hello.
That's easy to fix.
I anticipated this kind of issue around the command-line arguments that the script is passing to the conversion utility but missed to see that even the path to the utility needs to be enclosed in double quotes.
If you'll notice, the path at which you placed the files is broken by a space after "Documents". That's why you received the runtime error. Basically, your script couldn't locate the conversion utility.
I've updated the script and here it is:
This fixes your first problem.
I think when trying to use this script, you're printing pages before running this script. That will be an issue. You have to call the "Printing Action" at Ln. 16
Replace the line above with the code that will actually print pages through your application. You have a separate action for it, I guess? You can call that action here and wait for it to complete before proceeding.
Assuming that you got it right, you will see the pdf generated at
Your_Report_Path\PdfDocs\Your_Action_Name.pdf
Actually, you can modify the values of the variables: outputDirectoryForPrintedPdf and nameOfPdfFile to get the pdf generated where you like. Try putting an absolute path here if you want.
In a nutshell, you have to do this now:
1. Copy the new script from this reply and update the value of the variable: pathToConversionUtil like you did earlier.
2. Go to Line 16 in this new script and replace it with the code that will print pages through the application in question and wait for it to complete.
3. Run only this script. It will take care of both printing pages and opening PDF.
If you have any issues surrounding Step 2, let me know. All we need is the date and time immediately before the printing starts to make this script work.
If you could successfully get past the line where you got the general runtime error today, please capture the value of the variable: returnedStatusCode and quote it in your next reply so as to make it easy for me to discern what went wrong if it did.
*A request: While posting replies, please ensure that you don't include any personally identifiable information inadvertently. For example, in the path you posted, it is evident that your user name on your system is "pandeypr". This may put you and your system at risk. You can replace any such information with something random, like, "my_user_name"
Thank you so much for reading my detailed replies and working toward perfecting this script.
Cheers,
Light.
That's easy to fix.
I anticipated this kind of issue around the command-line arguments that the script is passing to the conversion utility but missed to see that even the path to the utility needs to be enclosed in double quotes.
If you'll notice, the path at which you placed the files is broken by a space after "Documents". That's why you received the runtime error. Basically, your script couldn't locate the conversion utility.
I've updated the script and here it is:
Code:
Dim returnedStatusCode 'This is the variable that will hold the status of pdf conversion
outputDirectoryForPrintedPdf = Reporter.ReportPath & "\PdfDocs" 'This is where the pdf would be generated; You can change this to suit your needs.
temporaryCacheFolder = Reporter.ReportPath & "\PdfCache" 'This cache will be deleted at the end of conversion but can also be kept through the switch -ClearCacheFinally False. You can change this to suit your needs.
nameOfPdfFile = Environment("ActionName") 'This will be the name of the pdf file generated under the folder:outputPathForPrintedPdf. You can change this to suit your needs.
pathToConversionUtil = "D:\OneNote2PDF\OneNote2PDF\bin\Debug\OneNote2PDF.exe" 'You have to specify the path where you have placed the executable in your machine..
Set oShell = CreateObject("Wscript.Shell") 'Let's get the shell object to run OneNote2PDF command-line utility. O' Shell, come to my rescue!
lastPrintedTime = CStr(Now) ' Capture the current time before proceeding to print
'Since we need the lasprintedtime to be our lower limit for pages, give the print command to the application here AFTER we have captured the current time.
msgbox "Modify the script here to call the action that prints pages through the application!"
' Actually run the command-line utility in the background and wait for the utility to return a code.
' ClearCacheFinally switch deletes the cache files generated during conversion at the end.
' UseUnfiled switch tells the program to use the "Unfiled Notes.one" file
' Output switch determines where the final merged pdf would be placed
' CacheFolder is just a temporary location to hold various pages in the Unfiled Notes section
' PagesAfterThisTime tells the program to look for only those pages which were printed after the specified time
' ShowTOC makes sure that the pdf is not cluttered with a Table Of Contents if you specify it as false
returnedStatusCode = oShell.Run("""" & pathToConversionUtil & """" & " -NameOfPdfFile " & """" & nameOfPdfFile &"""" & " -ClearCacheFinally True -UseUnfiled -Output " & """" & outputDirectoryForPrintedPdf & """" & " -CacheFolder " & """" & temporaryCacheFolder &"""" & " -PagesAfterThisTime " & """" & lastPrintedTime &"""" & " -ShowTOC False -ExportNotebook True -RefreshCache True", 0, True)
' I have hardcoded 0 to mean Success
If returnedStatusCode = 0 Then
fullPathToPdf = outputDirectoryForPrintedPdf & "\" & nameOfPdfFile & ".pdf"
' Okay, now, we have a pdf at the location contained in the location contained in fullPathToPdf variable
' Let's open the pdf.
' Now, if you have Adobe Acrobat Standard or Professional on your machine, then you can use the ActiveX approach, which is more robust.
' I just have Adobe Reader X so I've used the another way. It will just show the pdf on screen. Feel free to modify this according to your needs.
pdfViewResult = oShell.Run("acrord32.exe " & fullPathToPdf, 1, True)
' This one manual step is actually hurting me! More information needed to improve this...
testerChoice = MsgBox("Was the PDFOkay?", vbYesNo, "Pdf Verification")
If testerChoice = vbYes And pdfViewResult = 1 Then
Reporter.ReportEvent micPass, "CheckingPrintedPages", "The pages printed are fine and a pdf is available @ " & fullPathToPdf
Else
Reporter.ReportEvent micFail, "CheckingPrintedPages", "The application's Print functionality has a problem. Pdf available @ " & fullPathToPdf
End If
End If
' I have modified the command-line utility to return various codes in case of error
' -1 means Could not obtain reference to OneNote
' -2 means The file Unfiled Notes.one does not exist, which in our case will mean that no prints were received by the OneNote Printer Driver. This is so because even if the file does not exist, OneNote regenerates it every time it receives a print request.
'-3 means that the OneNote couldn't return the OneNote Xml for the notebook we're interested in. Basically, this means that there was some problem with OneNote.
'9 means that an unknown error occurred.
' -99 means that there were no pages printed after the date time we specified.
If returnedStatusCode = -2 Or returnedStatusCode = -99 Then
Reporter.ReportEvent micFail, "CheckingPrintedPages", "No pages were printed by the application"
Else If returnedStatusCode = -1 Or returnedStatusCode = -3 Or returnedStatusCode = -9 Then
Reporter.ReportEvent micFail, "CheckingPrintedPages", "There was a problem accessing the OneNote Application"
End If
End If
This fixes your first problem.
I think when trying to use this script, you're printing pages before running this script. That will be an issue. You have to call the "Printing Action" at Ln. 16
Code:
msgbox "Modify the script here to call the action that prints pages through the application!"
Replace the line above with the code that will actually print pages through your application. You have a separate action for it, I guess? You can call that action here and wait for it to complete before proceeding.
Assuming that you got it right, you will see the pdf generated at
Your_Report_Path\PdfDocs\Your_Action_Name.pdf
Actually, you can modify the values of the variables: outputDirectoryForPrintedPdf and nameOfPdfFile to get the pdf generated where you like. Try putting an absolute path here if you want.
In a nutshell, you have to do this now:
1. Copy the new script from this reply and update the value of the variable: pathToConversionUtil like you did earlier.
2. Go to Line 16 in this new script and replace it with the code that will print pages through the application in question and wait for it to complete.
3. Run only this script. It will take care of both printing pages and opening PDF.
If you have any issues surrounding Step 2, let me know. All we need is the date and time immediately before the printing starts to make this script work.
If you could successfully get past the line where you got the general runtime error today, please capture the value of the variable: returnedStatusCode and quote it in your next reply so as to make it easy for me to discern what went wrong if it did.
*A request: While posting replies, please ensure that you don't include any personally identifiable information inadvertently. For example, in the path you posted, it is evident that your user name on your system is "pandeypr". This may put you and your system at risk. You can replace any such information with something random, like, "my_user_name"
Thank you so much for reading my detailed replies and working toward perfecting this script.
Cheers,
Light.