Public Sub makePDF(ByVal fName As String, ByVal lName As String, ByVal companyName As String, _
ByVal strDate As String, ByVal strCity As String, ByVal strOrganization As String, ByVal strState As String, ByVal strPresident As String)
On Error GoTo makePDFerr
Dim docLocation As String = App_Path() & "\Certificate.doc"
Dim pdfFile As String = App_Path() & "\Certificate.pdf"
'Write out DOC to the PDF File using office 2010
'***************************************************************************************************
'Clear the last PDF
Kill(App_Path() & "\Certificate.pdf")
Dim wordApp As New Microsoft.Office.Interop.Word.Application
Dim wordDoc As New Microsoft.Office.Interop.Word.Document
Dim oFalse As Object = False
Dim oTrue As Object = True
Dim oNothing As Object = Nothing
If System.IO.File.Exists(docLocation) = False Then
MsgBox("The word doc file " & Chr(34) & docLocation & Chr(34) & " does not exist.")
End
End If
wordApp = New Microsoft.Office.Interop.Word.Application
wordApp.Visible = False
Dim doWord = wordApp.Documents.Open(docLocation, oFalse, oTrue)
'Find and Replace routine
'*******************************************************************
doWord.Content.Find.Execute(FindText:="<<First_Name>>", ReplaceWith:=StrConv(fName, VbStrConv.Uppercase), Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
doWord.Content.Find.Execute(FindText:="<<Last_Name>>", ReplaceWith:=StrConv(lName, VbStrConv.Uppercase), Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
doWord.Content.Find.Execute(FindText:="<<date>>", ReplaceWith:=strDate, Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
doWord.Content.Find.Execute(FindText:="<<companyOrganization>>", ReplaceWith:=companyName, Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
doWord.Content.Find.Execute(FindText:="<<city>>", ReplaceWith:=StrConv(strCity, VbStrConv.ProperCase), Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
doWord.Content.Find.Execute(FindText:="<<state>>", ReplaceWith:=StrConv(strState, VbStrConv.Uppercase), Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
doWord.Content.Find.Execute(FindText:="<<president>>", ReplaceWith:=StrConv(strPresident, VbStrConv.ProperCase), Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
'*******************************************************************
doWord.ExportAsFixedFormat(pdfFile, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF)
doWord.Close(oFalse, oNothing, oNothing)
wordApp.Quit()
'***************************************************************************************************
Exit Sub
makePDFerr:
Select Case Err.Number
Case Else
MsgBox(Err.Number & " " & Err.Description)
End Select
End
End Sub