Use Pdf.dll API to print pdf file and how to know the printing job task is completed?

Hi, Support:

I use the aspose.pdf.dll to print a pdf document object, and I want to know how to detect the printing job task of the pdf document for printing is completely printed. For example:

  Dim SrcPdf as Document=new Document(InputPdf)
  Dim PrintPdf as  Document=new Document(InputPdf)
  PrintPdf.pages.add(SrcPdf.pages(1))
  PrintPdf.pages.add(SrcPdf.pages(2))
 Dim viewer As PdfViewer = New PdfViewer()
viewer.BindPdf(PrintPdf)
        Dim printersetting As System.Drawing.Printing.PrinterSettings = New System.Drawing.Printing.PrinterSettings()
        printersetting.Copies = Copies
        printersetting.PrinterName = PrinterName
        printersetting.PrintRange = Printing.PrintRange.AllPages
        Dim pagesetting As System.Drawing.Printing.PageSettings = New System.Drawing.Printing.PageSettings()
         viewer.PrintDocumentWithSettings(pagesetting, printersetting)
Dim PrintJobTaskIsOver as boolean=false
    Do
        Application.DoEvents
      System.Threading.sleep(500)
     PrintJobTaskIsOver =viewer.IsBusy
   loop while   PrintJobTaskIsOver 
        viewer.Dispose()

What is the method to monitor the Printing-Comepleted-Status?

Thanks for your help!

@ducaisoft

To print a PDF document using the Aspose.Pdf library and monitor the completion of the printing job, you can utilize the PdfViewer class. Below is an example of how to implement this in VB.NET:

Dim SrcPdf As Document = New Document(InputPdf)
Dim PrintPdf As Document = New Document(InputPdf)
PrintPdf.Pages.Add(SrcPdf.Pages(1))
PrintPdf.Pages.Add(SrcPdf.Pages(2))

Dim viewer As PdfViewer = New PdfViewer()
viewer.BindPdf(PrintPdf)

Dim printerSettings As System.Drawing.Printing.PrinterSettings = New System.Drawing.Printing.PrinterSettings()
printerSettings.Copies = Copies
printerSettings.PrinterName = PrinterName
printerSettings.PrintRange = Printing.PrintRange.AllPages

Dim pageSettings As System.Drawing.Printing.PageSettings = New System.Drawing.Printing.PageSettings()

' Start printing the document
viewer.PrintDocumentWithSettings(pageSettings, printerSettings)

' Monitor the printing job status
Dim printJobTaskIsOver As Boolean = False
Do
    Application.DoEvents()
    System.Threading.Thread.Sleep(500)
    printJobTaskIsOver = viewer.IsBusy
Loop While printJobTaskIsOver

' Clean up
viewer.Dispose()

Explanation:

  1. Document Creation: You create a new Document object for both the source and the print version of the PDF.
  2. PdfViewer Setup: The PdfViewer is initialized and bound to the PDF document you want to print.
  3. Printer Settings: You configure the printer settings, including the number of copies and the printer name.
  4. Printing: The PrintDocumentWithSettings method is called to start the printing process.
  5. Monitoring: A loop is used to check if the viewer is busy printing. The IsBusy property indicates whether the printing job is still in progress.
  6. Cleanup: After the printing is complete, the viewer is disposed of to free resources.

This approach allows you to effectively monitor the printing status and ensure that your application can respond accordingly once the printing task is completed.

For more detailed examples and additional functionalities, you can refer to the Aspose documentation or the provided code samples in the Aspose GitHub repository.

If you have further questions or need additional assistance, feel free to ask!

Thanks for this auto reply!

However, there is no PdfViewer.IsBusy property for monitoring the job complete status.
I still need further help!

@ducaisoft

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-58714

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thanks for your attention for updating!
And a new feature should be consiedered such as following:

Do

PrintingProgreass.value=Viewer.HasPrintedPageNumbers & “/” & Viewer.TotalPageNumbersForPrint

Loop while Viewer.IsBusy

@ducaisoft

Sure, we have recorded these details and will inform you as soon as the feature is implemented.