Send Notes document as PDF attachment

Sub Click(Source As Button)
	
	'// Declarations
	Dim wApp As Variant 
	Dim ws As NotesUIWorkspace
	Dim s As NotesSession
	Dim uidoc As NotesUIDocument, nuidoc As NotesUIDocument
	Dim path As String, fpath As String, unid As String 
	Dim doc As NotesDocument 
	Dim rt As NotesRichTextITem 
	Dim mdb As NotesDatabase 
	
	'// Set temp file location
	tpath = "C:\Personal\"
	
	'// Initialize
	Set s = New NotesSession 
	Set ws = New notesuiworkspace
	Set uidoc = ws.CurrentDocument
	unid = uidoc.Document.UniversalID
	fpath = tpath+unid+".pdf"
	Call uidoc.SelectAll
	Call uidoc.Copy
	
	'// Open OLE Object
	Set wApp=CreateObject("Word.Application")
	wApp.Visible=visibility
	Call wApp.Documents.Add()
	wApp.Visible = False
	wApp.Selection.Paste
	wApp.ActiveDocument.SaveAs fpath, 17
	
	'// Close OLE Object 
	wApp.ActiveDocument.Close wdSaveChanges
	wApp.Quit
	
	'// Open new mail 
	Set mdb = s.Getdatabase(s.Getenvironmentstring("MailServer", True), s.Getenvironmentstring("MailFile", True), False)
	Set doc = New NotesDocument(mdb) 
	doc.Form = "Memo" 
	Set rt = doc.CreateRichTextItem("Body")
	Call rt.EmbedObject(Embed_Attachment, "", fpath, "test" )
	Call doc.Save(True, False) 
	Call ws.Editdocument(True, doc) 
	Call doc.RemoveItem("SaveOptions")
	
	'// Remove tmp file 
	Kill fpath 
End Sub





This script is ideally placed on a form and allows the user to mail entire document as a PDF. The logic is as follows
- Copy and Paste UI doc into a temporary MS Word object
- Save MS Word as PDF
- Closes MS Word OLE Object
- Opens new mail & attaches PDF file
- Kills temporary file

LotusScript
Ben Menesi
May 19, 2015 7:25 PM
Rating
259

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...