Automatically print a document on a network printer

We are trying to send a master document (after automatic distribution) automatically to one of our network printers, which has both a network name and an internal IP address.

But here is the really difficult part. When we print a document from our workstations, we get a hint with the Work Accounting dialog box to enter the project code before which it will be printed, so the finance department can do all its fancy accounting and billing materials.

So, how do we send a document (docx) to a network printer using the Job Accounting option programmatically?

I’m not sure how accounting data is common for print jobs, as this is the first work I have ever seen.

Here are the important features:

  • PHP 5 (optional)
  • Windows Server (2003, I reckon)
  • Kyocera KM-4050 Printer (with Static IP)
  • Experience with C ++ and Visual Basic

We did some research, but did not find too many viable solutions in the wild, and after some discussion we are not quite sure where to start. Unfortunately, there is no API that we can plug in.

----- DECISION -----

My team decided to implement code that would call an executable file to convert each document to a PCL, and then take the generated PCL and add it using

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

Then we take the generated file and write it to the printer spindle, where the printer processes it and starts each job.

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

+4
source share
4 answers

My team decided to implement code that would call an executable file to convert each document to a PCL, and then take the generated PCL and add it using

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

Then we take the generated file and write it to the printer spindle, where the printer processes it and starts each job.

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

+1
source

What would I do:

  • create a C ++ / VB script that will do the hard work (sorry, don't help me)
    • make it look in the job directory / accept CLI parameters
  • make php server save files to some directory along with some information
    • say, save 1.txt (your internal counter number must be unique, and each new one must be greater than the one that was previously) in / path / infos, having something like this inside: 1 c: \ temp \ filetoprint. docx
  • VB script will examine this directory and read the first file (the one that has the smallest number)
    • and see what it is for job id Job = 1
    • file for printing is located in the directory c: \ temp \ filetoprint.docx
    • and print it out :)
    • delete file (! important)

Now it all depends on your VB / C ++ programming skills :) BTW: another option, instead of saving files to a directory, allows you to use the exec () and CLI parameters for VBScript / C ++. But the file solution is more reliable, since it is a natural queue, and also resistant to printing program crashes - the job is deleted only after its completion. If the print job fails, he will try to do it next time. An analogy with files can be done using a database, but I'm not sure how easy it is to connect to the database from VB / C ++, so the file system is best suited;)

The PHP part only has a link to a script that will store the JA ID and file name in the file / path / infos /

This is a kind of workaround, but I don’t think it is worth doing in pure PHP (using the PHP extension).

+1
source

Job Accounting is simply re-entering the username / password in the driver.

It would be helpful if you mentioned which operating systems you use to host PHP and where your users are experiencing these prompts, but I think it is pretty obvious that you are using MSWindows for both.

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

+1
source

If you want it to use PHP, passing PJL parameters (necessary for accounting) is not always achievable (AFAIK, of course). But you can use a socket connection to pass any parameter that you like, along with the document in question, for printing. 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 , which has an interesting introductory article about encoding your own connection to manage network printers. However, I would start by sniffing the transfer of traffic between your computer and a network printer for print-writing in order to get familiar with the specific commands involved - this should make the protocol easily implementable through a socket connection through PHP.

+1
source

Source: https://habr.com/ru/post/1380041/


All Articles