Pregunta

We're trying to have a master document (after an automated mailmerge) be sent, in an automated fashion, to one of our network printers which has both a network name and internal IP assigned.

But here's the really tricky part. When we print a document from our workstations we do get prompted with a 'Job Accounting' dialog to enter the project code that the document is for before it'll print, so the finance department can do all their fancy accounting and billing stuff.

So, how do we send a document (docx) to a network printer along with the Job Accounting parameter programmatically?

I am not sure how common accounting data is when doing print jobs, as this is the first job I've ever seen it.

Here are the important specifics:

  • PHP 5 (preferred)
  • Windows Server (2003, I believe)
  • Kyocera KM-4050 Printer (w/ static IP)
  • Some experience with C++ and Visual Basic

We've done some research but haven't found too many viable solutions out in the wild and after some discussion, we're not entirely sure where to start. Unfortunately, there does not appear to be any kind of API we can plug into.

----- SOLUTION -----

My team has decided to implement code that will call an executable file to convert each document to PCL and then to take the generated PCL and prepend it with

@PJL SET KJOBMANAGERCODE="[project code here]"

Then we will take the generated file and write it to the printer spool where the printer will process it and start each job.

Thank you all for your help. Each answer pretty much inspired a certain part of our implementation plan.

¿Fue útil?

Solución 4

My team has decided to implement code that will call an executable file to convert each document to PCL and then to take the generated PCL and prepend it with

@PJL SET KJOBMANAGERCODE="[project code here]"

Then we will take the generated file and write it to the printer spool where the printer will process it and start each job.

Thank you all for your help. Each answer pretty much inspired a certain part of our implementation plan.

Otros consejos

What I would do is:

  • create a C++/VB script, that would do the hard work (sorry no help from me)
    • make it look into a directory for jobs / accept CLI params
  • make the server PHP save the files into some directory along with some info
    • say save a 1.txt (the number is your internal counter and needs to be unique and every new must be bigger than the one before) file into /path/infos having somthing like this inside: 1 c:\temp\filetoprint.docx
  • the VB script will look into that directory and read the first file (the one with smallest number)
    • and see that it's for Job Accounting ID = 1
    • the file to print is in c:\temp\filetoprint.docx
    • and print it :)
    • delete the file(s) (!important)

Now everything depends on your VB/C++ programing skills :) BTW: the other option is instead of saving files to directory you can use exec() and CLI params for the VBScript/C++. But the file-based solution is more robust, as it's kind of a natural queue and it's also resistant to the print program failures - the job is only removed when it'S completed. If the print job fails, it will try that the next time. Analogy to the files can be done using database, but I'm not sure how easy is to connect to DB from VB/C++ so the filesystem is best fallback ;)

The PHP part is only having a link to script that will save JA ID and filename to a file in /path/infos/

It's kind of a workaround solution, but I don't think it's worth to do it in pure PHP (using an PHP extension).

'Job accounting' is just the driver rebranding the username/password prompt.

It would be helpful if you'd mentioned what operating system(s) you're using for hosting PHP and where your users experience these prompts - but I think its fairly obvious that you are using MSWindows for both.

Short answer is that you need to bypass the dialog - which is (currently) built into your printer driver). It may be possible to configure the printer driver, or you could use an alternative printing subsystem such as Cups.

If you want it to use PHP, passing PJL parameters (needed for the accounting) is not easily achievable (AFAIK of course). But you may use a socket connection to pass any parameter you like, along with the document in question to print. Example:

> @PJL INFO ID
@PJL INFO ID
"LASERJET 4000"
> @PJL INFO STATUS
@PJL INFO STATUS
CODE=10001
DISPLAY="Ready"
ONLINE=TRUE
> @PJL INFO PAGECOUNT
@PJL INFO PAGECOUNT
536225
> @PJL INFO MEMORY
@PJL INFO MEMORY
TOTAL=2526160
LARGEST=1204208

The above example is from the IronGeek Blog, who has an interesting introductionary article on coding your own connection to control network printers. However, I would start by sniffing the traffic send between your computer and the network printer on a printjob to get a good look at the exact commands involved - this should make the protocol easily implementable via a socket-connection over PHP.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top