We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

What's wrong about the PageSplitter class?

Hi, Support:
Here report an issue about PageSplitter class. It’s as follow:

    Dim Doc as new Aspose.Words.document(sFile)
    Dim splitter As Aspose.Words.Examples.CSharp.Loading_Saving.DocumentPageSplitter
        splitter = New Aspose.Words.Examples.CSharp.Loading_Saving.DocumentPageSplitter(Doc)
        Dim SplitDoc As Global.Aspose.Words.Document
        Dim TmpDoc As Global.Aspose.Words.Document
        Dim sPages As Integer = Doc.PageCount
   'sPage=7
   for pi as integer=1 to sPage
      if pi=1 then
        SplitDoc=splitter.GetDocumentOfPage(pi)
        'This runs ok
      else
         on error resume next
        SplitDoc=splitter.GetDocumentOfPage(pi)
        ' Here , why it throw error="91  Object reference not set to an instance of an object."
      end if
  next

========

        Public Function GetDocumentOfPage(ByVal pageIndex As Integer) As Document
            Return Me.GetDocumentOfPageRange(pageIndex, pageIndex)
        End Function
        Public Function GetDocumentOfPageRange(ByVal startIndex As Integer, ByVal endIndex As Integer) As Document
            On Error Resume Next
            Dim result As Document = CType(Me.Document.Clone(False), Document)
            Dim a As String = Err.Number & "  " & Err.Description
'Here a="91  Object reference not set to an instance of an object."
            For Each section In Me.pageNumberFinder.RetrieveAllNodesOnPages(startIndex, endIndex, NodeType.Section)
                result.AppendChild(result.ImportNode(section, True))
            Next

            Return result
        End Function

=====
How to fix this problem.

@ducaisoft In the latest Aspose.Words version there is an Document.ExtractPages() method which could be used to simplify your scenario. Also you could check Split a Document Page by Page article for code example. If you will face any issues with the provided method please let us know.

Thanks! It works.
The PageSplitter class has been obsolete. I use Document.ExtractPages to implement that.