ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Unsolved Powershell (or CMD) to print PDF files

    IT Discussion
    powershell printing linux
    5
    13
    2.0k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JaredBuschJ
      JaredBusch
      last edited by

      I have a bit of an automation problem.

      Customer has a tool that generates PDF files (containing a fancy label) as orders are processed. Great.

      Problem: Once the order is printed and the line worker is going to package the item, the generated fancy label needs printed for the box.

      Previously, they used a not fancy label and a generic barcode printer. For that process I wrote a simply webpage served on a local raspberry pi. The Line worker's computer is a simply Linux Mint system and all they do is load the page and scan a barcode on the product. this printed out the label. making use of ssh and the lp command.

      The new process uses a printer without a Linux driver, so I have a Windows box. setup for testing. I can easily print the PDF with Start-Process in a simple PowerShell script from the user machine. But if I connect via SSH and invoke the script, it executes, but nothing happens. I assume this is because there is no environment for the Start-Process command to do anything.

      So what other way can I print a PDF file from a PowerShell script? Or lacking that from cmd.

      The end users really just need to have only their webpage open and the hand scanner that scans the barcode as the data entry.

      @Obsolesce I guess maybe instead of a webpage I could have some kind of PowerShell application running with a little GUI for the feedback?

      If the new printer had a Linux Driver, this would be moot, but it does not. https://www.primera.com/lx900downloads

      ObsolesceO JaredBuschJ 2 Replies Last reply Reply Quote 0
      • 1
        1337
        last edited by 1337

        Use mailbox message passing instead.

        Basically you make a powershell script that runs in a loop. It looks in a folder for file_to_print. When it finds it it send it to the printer, perhaps generate a response.txt file and then the deletes file_to_print.

        Your webserver prints by sending the file_to_print into the right folder using ssh (or smb). Then waits for the response.txt for ok or error. Or polls it on a regular basis.

        It's message passing between two different asynchronous processes where both can access a common folder. The common folder is the "mailbox" in the paradigm - and the files are the "messages".

        1 JaredBuschJ 2 Replies Last reply Reply Quote 0
        • 1
          1337 @1337
          last edited by 1337

          @1337 said in Powershell (or CMD) to print PDF files:

          Use mailbox message passing instead.

          Basically you make a powershell script that runs in a loop. It looks in a folder for file_to_print. When it finds it it send it to the printer, perhaps generate a response.txt file and then the deletes file_to_print.

          Your webserver prints by sending the file_to_print into the right folder using ssh (or smb). Then waits for the response.txt for ok or error. Or polls it on a regular basis.

          It's message passing between two different asynchronous processes where both can access a common folder. The common folder is the "mailbox" in the paradigm - and the files are the "messages".

          I think I'd lean towards using smb to transfer the files since it would be so very simple to drop the pdf-file directly into the right place from wherever you want - if you set up a file share on the windows PC.

          1 Reply Last reply Reply Quote 0
          • ObsolesceO
            Obsolesce @JaredBusch
            last edited by

            @JaredBusch said in Powershell (or CMD) to print PDF files:

            @Obsolesce I guess maybe instead of a webpage I could have some kind of PowerShell application running with a little GUI for the feedback?

            Could you serve the same web page from the Windows box and have it do the printing?
            Another possibility, use node or php to run a powershell script from the web page.
            Otherwise yes, you could make a simple PowerShell GUI script to have the scanner enter the info and print. Then what? They would use that Windows box instead of the Mint box?

            JaredBuschJ 2 Replies Last reply Reply Quote 0
            • JaredBuschJ
              JaredBusch @Obsolesce
              last edited by

              @Obsolesce said in Powershell (or CMD) to print PDF files:

              Could you serve the same web page from the Windows box and have it do the printing?

              From my prior research I found a webpage cannot print directly, served locally or not. The over all point of the process is the user scans a barcode and something prints, zero other interactions.

              1 Reply Last reply Reply Quote 0
              • JaredBuschJ
                JaredBusch @Obsolesce
                last edited by

                @Obsolesce said in Powershell (or CMD) to print PDF files:

                Another possibility, use node or php to run a powershell script from the web page.

                I think this could possibly work since the node or php "server" would be the machine itself. Brain didn't go the route of full local process.

                1 Reply Last reply Reply Quote 0
                • JaredBuschJ
                  JaredBusch @JaredBusch
                  last edited by

                  @JaredBusch said in Powershell (or CMD) to print PDF files:

                  I can easily print the PDF with Start-Process in a simple PowerShell script from the user machine

                  Because this is launching an actual process of whatever the default PDF viewer is I still would like something better than Start-Process if anything exists.

                  ObsolesceO 1 Reply Last reply Reply Quote 0
                  • JaredBuschJ
                    JaredBusch @1337
                    last edited by

                    @1337 said in Powershell (or CMD) to print PDF files:

                    that runs in a loop.

                    Rejected

                    1 Reply Last reply Reply Quote 0
                    • ObsolesceO
                      Obsolesce @JaredBusch
                      last edited by

                      @JaredBusch said in Powershell (or CMD) to print PDF files:

                      @JaredBusch said in Powershell (or CMD) to print PDF files:

                      I can easily print the PDF with Start-Process in a simple PowerShell script from the user machine

                      Because this is launching an actual process of whatever the default PDF viewer is I still would like something better than Start-Process if anything exists.

                      There's no native support in PowerShell/.NET from my understanding, so you'd need to rely on an external tool which is what I'm guessing you're launching with Start-Process.

                      The only thing I can think of atm is keeping the Windows box logged on to, and running the process as the user or launching the process with ServiceUI.exe from within the PowerShell script.

                      JaredBuschJ 1 Reply Last reply Reply Quote 0
                      • JaredBuschJ
                        JaredBusch @Obsolesce
                        last edited by

                        @Obsolesce said in Powershell (or CMD) to print PDF files:

                        The only thing I can think of atm is keeping the Windows box logged on to, and running the process as the user or launching the process with ServiceUI.exe from within the PowerShell script.

                        I have no problem with this, the user will be logged in anyway. Just Start Process, with Adobe Reader as the default PDF application causes an instance of reader to launch and close. Taking focus from where ever the command came from. So far focus has come back to the windows that called Start-Process but I would prefer to be certain of it.

                        So, I guess I'll deal with writing a little PowerShell application for this.

                        JaredBuschJ R 2 Replies Last reply Reply Quote 0
                        • JaredBuschJ
                          JaredBusch @JaredBusch
                          last edited by

                          @JaredBusch said in Powershell (or CMD) to print PDF files:

                          with Adobe Reader as the default PDF application

                          FYI, I cannot use Edge as the default viewer for this as it does not print correctly, I tried leaving that default.

                          1 Reply Last reply Reply Quote 0
                          • R
                            rjt @JaredBusch
                            last edited by rjt

                            @JaredBusch,

                            ls file.pdf | Start-Process -verb print
                            

                            does not necessarily
                            depend upon a PDF reader at all. It is dependent upon the verb “Print” existing and configured in the registry for Explorer.exe configuration entries residing in the registry.

                            • In Explorer.exe, navigate to any folder containing a file.pdf.
                            • Right click the file.
                            • Does the verb “Print” appear in the pop up context sensitive menu?
                            • if not, then you will get the behavior seen.

                            the Verbs “Open”, “Edit”, “RunAs”, and “Print” are windows Explorer.exe

                            P 1 Reply Last reply Reply Quote 0
                            • P
                              pirho99 @rjt
                              last edited by

                              There is a ppd you can use for cups in the Mac driver.

                              Primera LX900 - ColorLabelSugned - Payload~~ - Library - Printers - PPDs - Contents - Resources - CL900.ppd

                              1 Reply Last reply Reply Quote 0
                              • 1 / 1
                              • First post
                                Last post