none
Print XPS file to a specific physical printer with Copy Count RRS feed

  • Question

  • I am developing a VB.NET Windows Form Application that is needed to print an existing XPS Documentusing a specific physical printer (will be selected by the user). I don't want any dialog box or any other application to pop up after pressing the print button. I also need to specify the Printer (always Local), Page Size (always A4) and Copy Count (Variable and very important).

    I came past this article and modifies the code as- 

         Public Sub printf()
                Dim localPrintServer As New LocalPrintServer()
                Dim defaultPrintQueue As PrintQueue = LocalPrintServer.GetDefaultPrintQueue()
                Dim fileName As String = "file.xps"
                Try
                    Dim xpsPrintJob As PrintSystemJobInfo = defaultPrintQueue.AddJob("XPS", fileName, False)
                Catch e As PrintJobException
                    Debug.Print("Print Error: " & e.ToString)
                End Try
            End Sub

    But it didn't work. 

    I also tried the following code proposed in this stackoverflow thread

    Private Sub print_Click(sender As Object, e As EventArgs) Handles print.Click
                printf("HP LaserJet Professional P1102")
            End Sub
        
            Public Sub printf(printerName As String)
                Dim printer As New PrintServer
                Dim defQ As PrintQueue = printer.GetPrintQueue("HP LaserJet Professional P1102")
                Dim pt As PrintTicket = defQ.DefaultPrintTicket
                pt.CopyCount = 2
                defQ.AddJob("name", "OMR_Sheet.xps", False, pt)
            End Sub

    This code also does nothing for me. Now how to do this problem in .NET silently (Not making any window poping up) without using any third-party tool?

    (At first I thought about printing PDF file. But hours of googling made me realize that Microsoft may not have that good relation with PDF and I must use any third party library or application to do so, what I strongly would like to avoid. So, suggestions to print a PDF silently and efficiently with the told requirements are also appreciated but not using any third-party tool, not even Adobe Reader.)

         
    Tuesday, January 9, 2018 9:42 AM

All replies

  • I am developing a VB.NET Windows Form Application that is needed to print an existing XPS Documentusing a specific physical printer (will be selected by the user). I don't want any dialog box or any other application to pop up after pressing the print button. I also need to specify the Printer (always Local), Page Size (always A4) and Copy Count (Variable and very important).

    I came past this article and modifies the code as- 

         Public Sub printf()
                Dim localPrintServer As New LocalPrintServer()
                Dim defaultPrintQueue As PrintQueue = LocalPrintServer.GetDefaultPrintQueue()
                Dim fileName As String = "file.xps"
                Try
                    Dim xpsPrintJob As PrintSystemJobInfo = defaultPrintQueue.AddJob("XPS", fileName, False)
                Catch e As PrintJobException
                    Debug.Print("Print Error: " & e.ToString)
                End Try
            End Sub

    But it didn't work. 

    I also tried the following code proposed in this stackoverflow thread

    Private Sub print_Click(sender As Object, e As EventArgs) Handles print.Click
                printf("HP LaserJet Professional P1102")
            End Sub
        
            Public Sub printf(printerName As String)
                Dim printer As New PrintServer
                Dim defQ As PrintQueue = printer.GetPrintQueue("HP LaserJet Professional P1102")
                Dim pt As PrintTicket = defQ.DefaultPrintTicket
                pt.CopyCount = 2
                defQ.AddJob("name", "OMR_Sheet.xps", False, pt)
            End Sub

    This code also does nothing for me. Now how to do this problem in .NET silently (Not making any window poping up) without using any third-party tool?

    (At first I thought about printing PDF file. But hours of googling made me realize that Microsoft may not have that good relation with PDF and I must use any third party library or application to do so, what I strongly would like to avoid. So, suggestions to print a PDF silently and efficiently with the told requirements are also appreciated but not using any third-party tool, not even Adobe Reader.)

         
    Tuesday, January 9, 2018 8:35 AM
  • Hi Sayom,

    I find the same thread that you can take a look, hope it is helpful to you.

    https://stackoverflow.com/questions/21918040/print-to-xps-without-a-save-as-dialog

    https://stackoverflow.com/questions/46357249/print-xps-document-without-open-the-dialog-box-in-c-sharp

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 10, 2018 6:26 AM
    Moderator
  • Hi Sayom,

    I find the same thread that you can take a look, hope it is helpful to you.

    https://stackoverflow.com/questions/21918040/print-to-xps-without-a-save-as-dialog

    https://stackoverflow.com/questions/46357249/print-xps-document-without-open-the-dialog-box-in-c-sharp

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    These answers are about print to XPS But my question is about printing a XPS by a physical printer.

    nsssayom

    Thursday, January 11, 2018 5:15 AM