Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Jul 22, 2024 12:52 am

1 - version : 9.2.5
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

alqadhihost
 
Posts: 2
Joined: Mon Jul 22, 2024 12:00 am

Mon Jul 22, 2024 8:30 am

Hello,

Thanks for your inquiry.
Our Spire.PDF has a callback interface for displaying the progress of document saving, which may meet your needs. I uploaded the code for your reference. If you have any other questions, please feel free to write back.
Code: Select all
Dim pdf As PdfDocument = New PdfDocument()
pdf.LoadFromFile(inputFile)
pdf.RegisterProgressNotifier(New CustomProgressNotifier())
pdf.SaveToFile(outputFile, FileFormat.PDF)
pdf.Close()

Public Class CustomProgressNotifier
    Implements IProgressNotifier

    Private str As StringBuilder = New StringBuilder()

    Public Sub Notify(ByVal progress As Single) Implements IProgressNotifier.Notify
        str.AppendLine(progress & "%")
        File.WriteAllText(outputFile_txt, str.ToString())
    End Sub
End Class

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 419
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.PDF