Exporting to MHTML or PDF - InfoPath Dev
in

InfoPath Dev

Exporting to MHTML or PDF

Last post 12-18-2009 09:58 AM by samsonsandeep. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 11-20-2006 01:01 PM

    Exporting to MHTML or PDF

    Hello,
    I've seen all the postings for how to export an xml document. "File > Export to" as well "File > Print > Adobe Distiller".

    Is there anyway to put an export button on the form itself so users don't have to go through those steps? I have a time sheet that consultants have to fill out in my department. After they are approved and digitally signed, they need to be sent to the consultant's company. Since they won't have InfoPath, I'll need to send them a pdf or mhtml file. Does anyone know how to do this? I'm not real great at the custom code aspect so I'm looking for a way to do this through the Infopath interface. If not, I could use some help on the code. My form uses VBscript. Any help would be appreciated.

    Thank you.
  • 11-21-2006 06:38 AM In reply to

    Re: Exporting to MHTML or PDF

    Hey,

    Here is some code that we used to create a MHT file of the form and send it via email. Note that your form will need to be fully trusted.

    In the button code put the following:

    Dim oFormNum, oFormName, sMHT
    Dim sTo, sCC, sBCC, sSubj, sBody

    'grab the form number and title of current form
    Set oFormNum = XDocument.DOM.selectSingleNode("//my:FORMINFO/my:FormNumber")
    Set oFormName = XDocument.DOM.selectSingleNode("//my:FORMINFO/my:FormTitle")


    'create the MHT file 1st
    sMHT = CreateMHT(oFormNum.Text)

    'create the email envelope
    sTo = ""
    sCC = ""
    sBCC = ""
    sSubj = oFormNum.text & " - " & oFormName.text
    sBody = "message for the body of the email"
    CreateMailMsg sTo, sCC, sBCC, sSubj, sBody, sMHT


    Add the following subroutine and function to your script file:

    Function CreateMHT(sFormNum)
    'purpose to create a MHT web file of the form with its data for the user
    'date 4/13/2006
    'revised


    Dim wshShell,oFileSys, filePath, sFormFile, myDocs, sFile, sDate


    'unique name for file
    sDate = Year(Now) & Month(Now) & Day(Now) & "_" & Hour(Now) & Minute(Now) & Second(Now)
    sFile = sFormNum & "_" & sDate & ".mht"



    Set wshShell = Createobject("WScript.Shell")

    'path to user's data - assumes there is a Forms folder under My Documents
    myDocs = wshShell.SpecialFolders("MyDocuments")
    filePath = myDocs & "\Forms\"

    'check if path file exists
    Set oFileSys = CreateObject("Scripting.FileSystemObject")

    If oFileSys.FolderExists(filePath) Then
    sFormFile = filePath & sFile
    Else
    sFormFile = myDocs & sFile
    End if

    'check to see if the file exists - if it does, overwrite it
    If oFileSys.FileExists(sFormFile) Then
    oFileSys.DeleteFile sFormFile, True
    end if

    'create the mht file - needs digital certificate to do this
    XDocument.View.Export sFormFile, "MHT"

    CreateMHT = sFormFile

    End Function

    Sub CreateMailMsg(sTo, sCC, sBCC, sSubj, sBody, sAttachFile)
    'purpose creates an outlook message and attaches the MHT file created above
    'date 04/19/2006

    Dim objOlApp
    Dim objItm
    Set objOlApp = CreateObject("Outlook.Application")
    Set objItm = objOlApp.CreateItem(olMailItem)

    With objItm

    .To = sTo
    .CC = sCC
    .BCC = sBCC
    .Subject = sSubj
    .Body = sBody
    .Attachments.Add sAttachFile
    .Display

    End With

    End Sub

    Hope that helps,
    MB
  • 12-18-2009 09:58 AM In reply to

    Re: Exporting to MHTML or PDF

    Hello,

    I have a similar situation and please help me get a code for the button. One of the form content is "filename"..I want function to be as when clicked on the button it must capture the data entered in the filename textbox and save the file in .mht format in a folder path locally in computer and, if possible, another copy in a folder on server. Once that is done, the form must close and a new form must be opened. The local path to save the form is "C:\Feedback" and the naming of the file is to be derived from what is entered in the "filename" text box.

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.