Creating a word document and replace data and pdf generation

  • Thread starter Thread starter Aryaa
  • Start date Start date
A

Aryaa

Guest
Hi Guys,


I have the requirement where

1) take a word document template as a base

2) create instance of it and replace data inside that and SAVEAS different file file but PDF format.


everything works fine with the below code. My requirement is to change the font dynamically (based on business rules for few elements) for the data being replaced.


Private Sub CreatePDF()
Dim MyApp As New Word.Application()

Dim MyWordDoc As Word.Document = MyApp.Documents.Add("C:\WorkProjects\Temp\Tmp\Tmp\PDF\COPYWORD_TEMPLATE.docx")
MyApp.Visible = False
MyApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone


For Each item As String In mDataDictionary.Keys
Dim keyInfo As String = item
MyWordDoc.Content.Find.Execute(FindText:=keyInfo, ReplaceWith:=mDataDictionary(keyInfo).ToString(), Replace:=Word.WdReplace.wdReplaceAll)
Next


IO.File.Delete("C:\WorkProjects\Temp\Tmp\Tmp\PDF\tmpGeneratedPDFFileFinal.pdf")

MyWordDoc.SaveAs("C:\WorkProjects\Temp\Tmp\Tmp\PDF\tmpGeneratedPDFFileFinal.pdf",Word.WdSaveFormat.wdFormatPDF)
MyWordDoc.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
MyApp.Quit()

End Sub

Continue reading...
 
Back
Top