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


  1. If you got only one attachment in document, you can use separate Form with Auto launch set to -First attachment-
    No need for Windows-specific scripts.
    Here is an example how to open attachment after promp:
    Dim ws As New NotesUIWorkspace
    Dim ns As New NotesSession
    Dim db As NotesDatabase
    Set db = ns.CurrentDatabase
    Set coll = ws.PickListCollection(3,False,"",db.FilePath,"($docswithattachments)","Choose doc to open","Open attachment")
    If coll.Count > 0 Then
    Dim doc As NotesDocument
    Set doc = coll.GetFirstDocument
    If Not doc Is Nothing Then
    doc.Form ="OpenAttachment" 'Form with autolaunch set to First attachment
    Call ws.EditDocument(False, doc)
    End If
    End If

  2. Thank you for this very interesting idea.

    1. We have succesfully used that for a while and it works well. There was a problem with Symantec virus scanner which added fields to document and saved it without asking.
      Fortunately there is fix(2641800) for that:

  3. I've not tried it with a PDF, but the below code works with Excel. It does require that you know the default application to create the object with.

    Set objExcel = CreateObject( "Excel.Application" )
    objExcel.Visible = False

    objExcel.Workbooks.Open strTemplateFilename, , True


  4. Thank you Brian for your input, but your way to open the excel sheet has one big problem, that it will not work if excel is not installed on the computer. Today many computers have installed other spreadsheet applications like Libreoffice Calc. With your approach you will get an error, but with mine or Olli's way it will work on such computes too.

  5. There are many different formats in which the index PDF works. You can choose for a CSV format, where the different indexed entities would be separated by a comma. Adobe After Effects CC 2015

  6. Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!THANKS!!!!!! altoconvertpdftoexcel.com

  7. This online pdf merger or pdf combiner or pdf joiner will easily merge pdf files together with use of any software or any registration. pdf merger online

  8. Perusing on a PC can be frustratingly troublesome for those with low vision, dyslexia, or other print-perusing challenges. A text-to-speech program which peruses text so anyone might hear is typically basic.notevibes

  9. A connection to your document will then be given. To spare the picture, right tap on it and pick spare picture as. altopdf.com

  10. Took me technology to entre all of the observations, however I absolutely loved the article. It proved to be Very cordial to me and i am unconditional to all the commenters here! Its constantly clean whilst you can't on your own be informed, however with entertained! https://www.vaporwavetext.online/

  11. It is momentous that speech combination PC innovation has prompted the advancement of text to speech software.notevibes.com

  12. So glad you shared your blog link with me - I was able to direct a colleague to this post today when they were looking for PDF information. Great stuff!
    merge pdf files free