2 - Environment: windows 11 x64
3 - .NET Framework
4 - Code VB.NET
- Code: Select all
Imports Spire.Pdf
Imports Spire.Pdf.Conversion
Namespace ConvertPdfToExcel
Friend Class Program
Private Sub Form_Load()
Allow background operation to be cancelled
bgWorker.WorkerSupportsCancellation = True
'Allow background operation to report progress
bgWorker.WorkerReportsProgress=True
End Sub
Private Sub bgWorker_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgWorker.DoWork
If bgWorker.CancellationPending Then
e.Cancel = True
Exit Sub
Else
Dim inputFile As String = "sample.pdf"
'Specify the output directory
Dim outputDirectory As String = "D:\\Output\\"
'Load the source PDF file while initialing the PdfDocument object
Dim Pdf As PdfDocument = New PdfDocument(inputFile)
If Pdf.Pages.Count > 9 Then
'Insert the rest pages of source file to the second document
Dim Index As Integer = Pdf.Pages.Count / 10 ' split part pdf
Dim Start As Integer = 0
For i As Integer = 0 To 10
Dim newPdf As PdfDocument = New PdfDocument()
If i = 10 Then
newPdf.InsertPageRange(Pdf, Start, Pdf.Pages.Count - 1)
newPdf.SaveToFile(outputDirectory + "output-" + i.ToString() + ".pdf")
Return
End If
newPdf.InsertPageRange(Pdf, Start, Start + Index - 1)
Start = Start + Index
newPdf.SaveToFile(outputDirectory + "output-" + i.ToString() + ".pdf")
Next i
End If
'Report the progress
bgWorker.ReportProgress(percent, userstate)
End if
End Sub
Private Sub bgWorker_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles bgWorker.ProgressChanged
'Report the progress of background operation here
End Sub
Private Sub bgWorker_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgWorker.RunWorkerCompleted
If e.Cancelled Or Not IsNothing(e.Error) Then
'If the background opeartion was cancelled
'or an error occured during execution then do something
Else
'If Background execution completed normally then do something else
End If
End Sub
End Class
End Namespace