How to remove given pages?

Hi, Support,

I have a question like this:
for example, there is a document that has 100 pages, and I want to delete page 1,page 5 to page 10, and the last page. How to work it out based on VB.net?

Thanks for your help.

Ducaisoft

@ducaisoft

Thanks for your inquiry. In your case, we suggest you please use the PageSplitter utility to achieve your requirement. Please check the attached ZIP file for DocumentPageSplitter code.
PageSplitter.zip (5.9 KB)

Following code example shows how to remove the 3rd page from the document. Hope this helps you.

Dim pageToRemove As Integer = 3
Dim doc As Document = New Document(MyDir & "in.docx")
Dim finalDoc As Document = CType(doc.Clone(False), Document)
finalDoc.RemoveAllChildren()
Dim layoutCollector As LayoutCollector = New LayoutCollector(doc)
doc.UpdatePageLayout()
Dim splitter As DocumentPageSplitter = New DocumentPageSplitter(doc)

For page As Integer = 1 To doc.PageCount
    Dim pageDoc As Document = splitter.GetDocumentOfPage(page)
    If page <> pageToRemove Then finalDoc.AppendDocument(pageDoc, ImportFormatMode.KeepSourceFormatting)
Next

finalDoc.Save(MyDir & "19.2.docx")

Thanks for your suggestion!
However, there is some errors in the PageSplitter.vb file attached. Could you fix the PageSplitter.vb and re-upload it for me ? Or could you check my project to see why it cannot be compiled successfully?
DemoProject.zip (4.0 MB)

Thanks!

@ducaisoft

Please accept my apologies for your inconvenience. We have attached the correct PageSplitter utility with this post. PageSplitter.zip (5.9 KB)

Please let us know if you have any more queries.