6
Answers

How to delete a particular page in a word document in C# ?

Photo of Gunti Dilip

Gunti Dilip

11y
8.1k
1
Hi,

Please help me out to delete a particular page number in word doc.?

Thanks in Advance,
Dilip

Answers (6)

0
Photo of Janat AlJamal
NA 112 21 5y
if you do not want to use the microsoft interop services, you can check out the leadtools sdk. the LEAD sdk lets you load word documents (as well as all other microsoft formats, pdfs, and images) and rearrange the pages, delete pages, add pages, then save the document back out to whatever format that you want. check out this link for more information
https://www.leadtools.com/support/forum/posts/t12249-Code-Tip---NET-Virtual-Document-Demo 
0
Photo of Atir Tahir
NA 343 163.8k 5y
This is how you can delete a particular or multiple pages from a document in C#
  1. string filePath = @"c:\sample.docx";  
  2. string filePathOut = @"c:\output\result.docx";  
  3. RemoveOptions removeOptions = new RemoveOptions(new int[] { 3, 5 }); //3 and 5 are the page numbers 
  4. using (Merger merger = new Merger(filePath))  
  5. {  
  6.     merger.RemovePages(removeOptions);  
  7.     merger.Save(filePathOut);  
  8. }  
You have to add GroupDocs.Merger for .NET DLL in order to run this piece of code.
0
Photo of Gunti Dilip
NA 54 105k 11y
int[] b = { 15, 17 };
for (int i = 0; i <= 1; i++)
{
        object goname1 = b[i];
        objWordDoc.Application.Selection.GoTo(Word.WdGoToItem.wdGoToPage,         Word.WdGoToDirection.wdGoToAbsolute, null, goname1);
        objWordDoc.Application.Selection.Bookmarks[@"\Page"].Select();
        objWordDoc.Application.Selection.Delete();

                }

It works only for even numbers ?
0
Photo of shiva reddy
NA 51 32.3k 11y
it is not what i want

i want that the file that existing in the project should be diplayed automatically when page loads.
0
Photo of Gunti Dilip
NA 54 105k 11y
It wont works... Could you please help me...
0
Photo of Ruchi H
NA 240 5.7k 11y