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:32 am

version:9.2.5
Environment:windows 11 64
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 pdf As PdfDocument = New PdfDocument()
            'Load the PDF document
            pdf.LoadFromFile("Sample1.pdf")

            'Initialize an instance of XlsxLineLayoutOptions class, in the class constructor, setting the first parameter - convertToMultipleSheet as false.
            'The four parameters represent: convertToMultipleSheet, showRotatedText, splitCell, wrapText
            Dim options As XlsxLineLayoutOptions = New XlsxLineLayoutOptions(False, True, True, True)
            'Set PDF to XLSX convert options
            pdf.ConvertOptions.SetPdfToXlsxOptions(options)

            'Save the PDF document to XLSX
            pdf.SaveToFile("PdfToOneExcelSheet.xlsx", FileFormat.XLSX
   
   '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:21 am

Hello,

Thanks for your inquiry.
Do you want to check the progress of the document conversion? If so, please refer to the code below to test. If there is any misunderstanding, 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.XLSX)
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: 454
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.PDF