Dim pdfDoc As New Spire.Pdf.PdfDocument(item.FileName) 'open existing file
Dim newDoc As Spire.Pdf.PdfDocument
Dim startPage As Integer = 0 'first page starts at 0 index
Dim endPage As Integer = -1 'when incremented for first page will be 0
Using pdfDoc
For i As Integer = 1 To item.DocumentSegments
imageFileName = IO.Path.Combine(basePath, item.BuildDestinationFileName(i))
newDoc = New Spire.Pdf.PdfDocument()
'calculate start and end
startPage = endPage + 1
endPage = (30 * i) - 1
'prevent going out of bounds
If endPage > item.PageCount Then
endPage = item.PageCount - 1
End If
Using newDoc
'copy current segment to new pdf file
For j As Integer = startPage To endPage
newDoc.InsertPage(pdfDoc, j)
Next
newDoc.SaveToFile(imageFileName)
If Not IO.File.Exists(imageFileName) Then
Return False
Else
'save the split file in case we need to roll back
item.SplitFilesList.Add(imageFileName)
End If
newDoc.Close()
End Using
Next
pdfDoc.Close()
End Using
Sub Main()
Dim doc As New PdfDocument(your pdf document)
Dim startPage As Integer = 0
Dim endPage As Integer = -1
Dim filename As String = Nothing
For i As Integer = 1 To doc.Pages.Count - 1
Dim newdoc As New PdfDocument()
Dim sec As PdfSection = newdoc.Sections.Add()
startPage = endPage + 1
endPage = 30 * i
If endPage > doc.Pages.Count Then
endPage = doc.Pages.Count
End If
If startPage > endPage Then
Exit For
End If
filename = String.Format("..\..\original-{0}-{1}.pdf", startPage, endPage)
For j As Integer = startPage To endPage - 1
Dim newdocpage As PdfPageBase = sec.Pages.Add()
doc.Pages(j).CreateTemplate().Draw(newdocpage, 0, 0)
Next
newdoc.SaveToFile(filename, FileFormat.PDF)
Next
End Sub