Print PDF Attachment with Lotusscript

I am not a designer/programmer. I am a Notes/Domino admin. But every niow and then I am asked to see if I can create/edit some code for a desired outcome.In this case, we need to add a button to a mail file so a user can open a doc, press this button and it will print the email and the contents of the attachment.

I found the following code online, which works great, but it does not address PDF files which is primarily what I need. Here is the whole code first:

Sub Click(Source As Button)

’This routine is set up to scan a document for attachments and then

’print them out automatically based on their file extension and ‘ ‘associated application.

Dim ws As New NotesUIWorkSpace

Dim session As New NotesSession

Dim dbThis As NotesDatabase

Dim uidocThis As NotesUIDocument

Dim docThis As NotesDocument

Dim embAttachment As NotesEmbeddedObject

Dim strFileUniqueID As String

Dim strAttachmentType As String

Dim strAttachmentName As String

Dim lngPrintDelay As Long



Set dbThis = session.CurrentDatabase



Set uidocThis = ws.CurrentDocument

Set docThis =uidocThis.Document

’This prints the actual Notes document prior to printing the ‘attachments.

Call uidocThis.Print(1)



strFileUniqueID = Format(Now, "yyyymmddhhmmss")

'By traversing all the item elements in the document, all attachments ‘should be snagged.

Forall i In docThis.Items

      If i.type = Attachment Then

            Set embAttachment = docThis.GetAttachment(i.values(0))

            strAttachmentType = Right$(embAttachment.Name, 3)

            strAttachmentName = "c:\temp\BRDocPrintAttachment" &

strFileUniqueID

            Call embAttachment.ExtractFile(strAttachmentName)



            Select Case Lcase(strAttachmentType)

'This routine prints txt files with the Notepad application running ‘under the /p print switch. It assumes that Notepad.exe is running in ‘c:\Windows.

            Case "txt"

                  Dim strNotepadLocation As String

                  Dim intTaskID As Integer

                  strNotepadLocation = "c:\Windows\Notepad.exe"

                  intTaskID = Shell(strNotepadLocation & " /p" &

strAttachmentName)

                  Kill strAttachmentName

'This routine prints Excel files. It assumes that Excel is installed ‘on the machine doing the printing.

            Case "xls"

                  Dim ExcelApp As Variant

                  Dim ExcelDoc As Variant

                  Set ExcelApp = CreateObject("Excel.Application")

                  Set ExcelDoc =

ExcelApp.Workbooks.Open(strAttachmentName)

                  Call ExcelDoc.PrintOut

                  Call ExcelDoc.Close(0)

                  Call ExcelApp.Quit

                  Set ExcelApp = Nothing

                  Kill strAttachmentName

'This routine prints Word files. It assumes that Word is

’installed on the machine doing the printing.

            Case "doc"

                  Dim WordApp As Variant

                  Dim WordDoc As Variant

                  Set WordApp = CreateObject("Word.Application")

                  Set WordDoc =

WordApp.Documents.Open(strAttachmentName)

                  Call WordDoc.PrintOut

                  Call WordDoc.Close(0)

                  Call WordApp.Quit

                  Set WordApp = Nothing

                  Kill strAttachmentName

'This routine prints Visio files. It assumes that Visio

’is installed on the machine doing the printing.

            Case "vsd"

                  Dim VisioApp As Variant

                  Dim VisioDoc As Variant

                  Set VisioApp = CreateObject("Visio.Application")

                  VisioApp.Visible = False

                  Set VisioDoc =

VisioApp.Documents.Open(strAttachmentName)

                  Call VisioDoc.Print

                  Call VisioApp.Quit

                  Set VisioApp = Nothing

                  Kill strAttachmentName

'This routine prints Microsoft Project files. It assumes

’that Microsoft Project is installed on the machine doing the printing.

            Case "mpp"

                  Dim ProjectApp As Variant

                  Set ProjectApp =

CreateObject(“MSProject.Application”)

                  Call ProjectApp.FileOpen(strAttachmentName)

                  Call ProjectApp.FilePrint(1)

                  Call ProjectApp.FileClose(0)

                  Call ProjectApp.Quit

                  Set ProjectApp = Nothing

                  Kill strAttachmentName

'And if the attachment doesn’t have a recognized extension, we tell the ‘user to print the attachment manually.

            Case Else



                  Msgbox "This routine doesn't recognize " +

strAttachmentType + " file types. Please print the attachment manually."

            End Select

      End If

End Forall

End Sub

Am I trying to add something like this for the PDF files:

'This routine prints PDF files. It assumes ’that Adobe Reader is installed on the machine doing the printing.

 Case "pdf"

Dim AdobeReader8App As Variant

           Set AdobeReader8App = CreateObject("Adobe Reader 8.Application")

Call AdobeReader8App.FileOpen(strAttachmentName)

Call AdobeReader8App.FilePrint(1)

Call AdobeReader8App.FileClose(0)

Call AdobeReader8App.Quit

Set AdobeReader8App = Nothing

Kill strAttachmentName

When I run this, I get “cannot create automation object”.

Any help would be greatly appreciated! Thanks in advance.

Subject: Print PDF Attachment with Lotusscript

Adobe reader cannot print/create PDF’s but there are pleanty of free tools that can. See below for a great solution (FREE)

Link → http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllThreadedWeb/8FAF8DF4ABE6C694852574BB004ECD71?opendocument&login

Subject: Print PDF Attachment with Lotusscript

This forum is loaded with “Notes to PDF” posts. Here are a few that might help.

http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/1befbea9846216a985256ff300674df5?OpenDocument

http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/c42d877a975ea17785257347006d3b7c?OpenDocument

http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/ae0568facedee7028525729c006c5336?OpenDocument

Good luck.

Subject: RE: Print PDF Attachment with Lotusscript

Hi Gregg,

Thank you very much for your posts. But these were not what I am looking for. I don’t need to convert the documents from Notes to PDF, nor do I want to convert them to Word before printing them. I just want the user to be able to press a button, and the email and the attachment print out.

If you or anyone else can offer any suggesitons, or take a look at the code I have and help tweak it, it would be very appreciated.

Thank you for your help.

Subject: RE: Print PDF Attachment with Lotusscript

I am not the right person to offer code suggestions. But, thanks to your clarification, here are a couple of other links that may be useful:

http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/eee8dcdd089c32b885256f870031e015?OpenDocument

http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/f1db7143deb7ec6a8525702900275329?OpenDocument

You might also want to look at openntf.org, codestore.net, and searchdomino.com.

Subject: RE: Print PDF Attachment with Lotusscript

Hey Gregg,

Thanks again for posting, but these did not give me what I needed. I also tried the other websites you suggested, but they did not have the specifics I am looking for.

Thank you for your input, however.

If there is anyone that can give me some direction on the code I have, it would be greatly appreciated. I just can’t seem to figure out how to get PDF files to print…

Thanks.

Subject: RE: Print PDF Attachment with Lotusscript

Adobe went the whole way to implement a Knowledge Base powered by Domino just to answer this question. This is why it cannot be done the way you try it.

http://support.adobe.com/devsup/devsup.nsf/docs/50796.htm

http://support.adobe.com/devsup/devsup.nsf/docs/51619.htm

Searching this forum (or maybe the Notes 5 forum, I don’t remember off hands) you should be able to find a code sample by Ulrich Krause that shows how to call native Windows functions to print files. Since the code is intended for client use, the restriction to the Windows platform is probably not an issue.

Subject: RE: Print PDF Attachment with Lotusscript

Thank you for your response.I found this link http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/6506dc31f80b5f418525710f000b99bb?OpenDocument

which after tweaking a bit, is perfect for our needs. I just need it to do one last thing. Print the email with the attachment. I’ve tried copying some of the code from the other script I had, but it keeps failing with Object variable not set on the call:

Dim uidocThis As NotesUIDocument

Dim ws As New NotesUIWorkSpace

Set uidocThis = ws.CurrentDocument

Call uidocThis.Print(1)

And these lines are essentially right out of the Help. I am guessing this is because this is an agent vs a button, but am having a hard time finding the correct code for an agent (believe it or not).

Any further assistance would be most appreciated.

Thanks again to those who’ve responded.