And I was able to get it to work.. but any in-line images are not brought into the pdf file.
here is the code:
pdfConverter Script Library
Options
%REM
Library PdfConverter
Created Sep 9, 2016 by Betsy Thiede/DEV/SPRGFLD/CSCI
Description: Comments for Library
%END REM
Option Public
Option Declare
Use "OpenLogFunctions"
Declarations
Const APIModule = "NNOTES"
Const wdExportFormatPDF = 17
Const wdExportFormatXPS = 18
Const wdExportOptimizeForOnScreen = 1
Const wdExportOptimizeForPrint = 0
Const wdExportAllDocument = 0
Const wdExportCurrentPage = 2
Const wdExportFromTo = 3
Const wdExportSelection = 1
Const wdExportDocumentContent = 0
Const wdExportDocumentWithMarkup = 7
Const wdExportCreateHeadingBookmarks = 1
Const wdExportCreateNoBookmarks = 0
Const wdExportCreateWordBookmarks = 2
Declare Function MailGetMessageBodyComposite Lib APIModule Alias "MailGetMessageBodyComposite" ( ByVal hNT As Long, ByVal N As String, ByVal D As String, nD As Long) As Integer
Declare Function ExportRTF Lib "nxrtf" Alias "ExportRTF" (ByVal sTempFile As String, ByVal flags As Long, hmod As Long, ByVal altlibrary As String, ByVal sRTFFile As String) As Integer
%REM
Sub ConvertDocToRtfFile
Description: Converts a NotesDocument to an RTF-Document and saves it under the filePath
Generates and removes some temporary Files while Working
%END REM
Public Sub ConvertDocToRtfFile(doc As NotesDocument, filePath As String)
Dim tempDoc As NotesDocument
Dim tempRti As NotesRichTextItem
' On Error GoTo ErrorHandler
Set tempDoc = doc.ParentDatabase.CreateDocument()
Set tempRti = tempDoc.CreateRichTextItem("Body")
Call doc.RenderToRTItem(tempRti)
Call ConvertItemToRtfFile(tempRti, filePath)
Exit Sub
ErrorHandler:
Call LogErrorEx("Error in: ConvertDocToRtfFile", SEVERITY_HIGH, doc)
Error Err, Error$
End Sub
%REM
Sub ConvertDocumentToPdf
Description: Converts a NotesDocument to an PDF-Document and saves it under the filePath
Needs an COM-Instace of a Word Application created with:
Dim word As Variant
Set word = CreateObject("Word.Application")
Generates and removes some temporary Files while Working
%END REM
Public Sub ConvertDocumentToPdf(doc As NotesDocument, word As Variant, filePath As String)
Dim wordDoc As Variant
' On Error GoTo ErrorHandler
Call ConvertDocToRtfFile(doc, filePath & ".rtf")
'http://msdn.microsoft.com/en-us/library/office/bb216319(v=office.12).aspx
Set wordDoc = word.Documents.Open(filePath & ".rtf", False, True, False)
'http://msdn.microsoft.com/en-us/library/office/bb256835(v=office.12).aspx
Call wordDoc.ExportAsFixedFormat(filePath, wdExportFormatPDF, False, wdExportOptimizeForPrint, wdExportAllDocument, 0, 9999999, wdExportDocumentContent, True, True, wdExportCreateHeadingBookmarks, True, True, True, Nothing)
Call wordDoc.Close(0)
Kill filePath & ".rtf"
Exit Sub
ErrorHandler:
Call LogErrorEx("Error in: ConvertDocumentToPdf", SEVERITY_HIGH, doc)
Error Err, Error$
End Sub
%REM
Function ConvertItemToRtfFile
Description: Converts an NotesRichTextItem to an RTF-Document and saves it under the filePath
Generates and removes a temporary File while Working
%END REM
Public Sub ConvertItemToRtfFile(item As NotesRichTextItem, filePath As String)
' On Error GoTo ErrorHandler
Dim fileSize As Long
Dim doc As NotesDocument
Set doc = item.Parent
Call MailGetMessageBodyComposite(doc.handle , "Body", filePath & ".cd", fileSize)
Call ExportRTF(filePath & ".cd", 0, 0, "", filePath)
Kill filePath & ".cd"
Exit Sub
ErrorHandler:
Call LogErrorEx("Error in: ConvertItemToRtfFile", SEVERITY_MEDIUM, doc)
Error Err, Error$
End Sub
Then the agent that calls this script library:
%REM
Agent convert to pdf
Created Sep 9, 2016 by Betsy Thiede/DEV/SPRGFLD/CSCI
Description: Comments for Agent
%END REM
Option Public
Option Declare
Use "PdfConverter"
Sub Initialize
Dim Session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim filePath As String
Dim objWord As Variant
Set objWord = CreateObject("Word.Application")
Set db = session.Currentdatabase
Set collection = db.Unprocesseddocuments
If collection.count = 0 Then
Exit sub
End If
Set doc = collection.Getfirstdocument()
Do Until doc Is Nothing
filePath = "C:\Users\bthiede\Documents\test_files\" & doc.Universalid
'Call ConvertDocToRtfFile(doc , filePath)
Call ConvertDocumentToPdf(doc, objWord, filePath)
Set doc = collection.Getnextdocument(doc)
Loop
End Sub
Feedback number WEBBADMLBV created by ~Hal Quetlu on 09.09.2016
Status: Open
Comments: