Showing posts with label lotus script. Show all posts
Showing posts with label lotus script. Show all posts

Tuesday, December 10, 2013

Open PDF's stored in a rich text item from lotus script.

I have an application which stores PDF's as embedded files in a rich text item. I want to write some lotus script code which detach the PDF to a temporary directory and then launch the os default reader for PDF's to view the file. Ok the first part to detach the file is very easy and strait forward.

 Set rtitem=dokument.Getfirstitem("Body")
 Forall obj In rtitem.Embeddedobjects
  fileName=Environ("TEMP")+"\"+obj.Source
  Call obj.extractFile(fileName)
 End ForAll

Hm now we have the attachment in the temp directory, but how can we launch this attachment? My first guess was to use shell(fileName). But Notes quits this with an "illegal function call" error. I have tried many ways to call the shell function, but could not get it to work. So i have searched for another solution and found out, that the easiest way to workaround this problem is to use the Windows Scripting host to execute the PDF file.

  Set objShell = CreateObject("WScript.Shell")
  returnValue = objShell.Run(fileName, 3, false)

This works very well for all other file types your windows system recognize too. You can find a detailed description of the WScript.Shell function on MSDN
ad