Friday, May 22, 2009

Add blank page in word document using C#.Net

Hello Friends

U can add blank page at particular page number in word document using below code.

object missing = System.Reflection.Missing.Value;
object fileName = @"D:\TestFile.docx";
object readOnly = false;
object isVisible = true;

//Start Word and open a document.
_Application oWord;
_Document oDoc;
oWord = new Application();
oWord.Visible = true;

oDoc = oWord.Documents.Open(ref fileName, ref missing, ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref isVisible, ref missing,
ref missing, ref missing, ref missing);

//Goto some specific page and insert a blank page or page break
object gotoPage = WdGoToItem.wdGoToPage;
object gotoNext = WdGoToDirection.wdGoToNext;
object gotoCount = null;
//Page Numer
object gotoName = "4";

oWord.Selection.GoTo(ref gotoPage, ref gotoNext, ref gotoCount, ref gotoName);

//Insert a blank page
oWord.Selection.InsertNewPage();

//Insert a page break
object breakPage = WdBreakType.wdPageBreak;
oWord.Selection.InsertBreak(ref breakPage);

Thanks & Regards
Jignesh Patel

No comments:

Post a Comment