Converting eml file to pdf

Hi, one of requirement for my automation task is to read eml file and save as pdf file and this has to be done in batch for several file. This is just hack how to do automate that task. THIS WILL NOT STORE THE ATTACHMENTS. Its just inserting the eml file into doc and converting it to pdf. This code is vbscript code.

wdStory=6
wdMove=0
wdNotSaveWord=0
wdSavePDF=17
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add()
Set objheaderfooter = objDoc.Sections(1)

objheaderfooter.Headers(1).Range.Font.Italic = True
objheaderfooter.Headers(1).Range.Font.Color = RGB(0,0,255)

objheaderfooter.Footers(1).PageNumbers.Add
objheaderfooter.Borders.Enable = true
Set objSelection = objWord.Selection
objWord.Visible = false

objSelection.EndKey wdStory, wdMove
objSelection.TypeParagraph()

rem insert file code
objSelection.InsertFile("YOUR FILE PATH")
objSelection.EndKey wdStory, wdMove

'Save word to temp folders
timemills = now()
strfilename=replace(timemills,"/","_")
strfilename=replace(strfilename,":","_")
strfilename=replace(strfilename," ","_")
tsname="Sample"
pdfpath=tsname&"_"&strfilename&".pdf"


Set fso = CreateObject("Scripting.FileSystemObject")
foldername = now()
folderdate = split(foldername," ")
current = Replace (folderdate (0),"/","_")

rem folder path to save file
folderpath ="FOLDER PATH TO SAVE FILE"

If fso.folderexists (folderpath) then
msgbox "Folder exists not creating new one"

End if

pdfpath=folderpath&"\"&pdfpath
msgbox pdfpath
objDoc.SaveAs pdfpath,wdSavePDF
objWord.Quit wdNotSaveWord

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s