Sunday, June 26, 2011

C# - How to Insert paragraph to MsWord and save it as PDF

1. First you need to install the Add-In: 2007 Microsoft Office Add-in: Microsoft Save as PDF

2. You need to create Bookmark in msWord
Microsoft.Office.Interop.Word.Application ap = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc1 = ap.Documents.Open(@"c:\test.docx", ReadOnly: false, Visible: false);
Object oBookmarkTOC1 = "BookMarkName";
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
//Update BookMark
doc1.Bookmarks.get_Item(ref oBookmarkTOC1).Range.Text = "Bla Bla 123";

Read more: Uzi Drori's Blog