Unsolved Powershell (or CMD) to print PDF files
-
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 thelp
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 theStart-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
-
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".
-
@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.
-
@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? -
@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.
-
@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.
-
@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. -
-
@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.
-
@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.
-
@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.
-
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
-
There is a ppd you can use for cups in the Mac driver.
Primera LX900 - ColorLabelSugned - Payload~~ - Library - Printers - PPDs - Contents - Resources - CL900.ppd