Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If your willing to experiment a little you can create your own cups backend. All of the below will be accomplished via sudo... https://github.com/jsmeix/cups-backends
Copy the pipe script to /usr/lib/cups/backend/pipe and save with the same permissions as the other files. Here is a simple python script to save the print job as a file and convert it to text. Save it to the /usr/local/bin directory and make sure it is executable.
Code:
#!/usr/bin/python
import os
import sys
import string
import random
import subprocess
def get_string(length):
letters = string.ascii_lowercase
result_str = ''.join(random.choice(letters) for i in range(length))
return result_str
#client = os.environ['REMOTE_HOST']
input = sys.stdin.read()
fname = get_string(8)
a="/var/spool/samba/"+fname
b="/var/spool/samba/"+fname+".txt"
with open(a,'wb') as output:
output.write(input)
subprocess.call(["/usr/bin/pdftotext","-layout",a,b])
subprocess.call(["/bin/chmod","666",b])
To create the printer run the command (via sudo)
lpadmin -p queue_name -v 'pipe:/usr/local/bin/script.py/' -E
queue_name can be anything. When you print from xed to the new printer it will convert the PDF file format output to text in the /var/spool/samba/ directory. The file name will be a random string.txt
You can try printing the text file via the lpr command to the Epson printer and see what happens too.
When I save the code you offered before, what name do I give the file in /usr/local/bin ? "script.py" ? I'm getting error messages. I presume queue_name is whatever name I wish to assign my new "printer." Also, when I go to /var/spool , I don't have a /samba directory. I do have a cups directory and in there I find copies of many things I've printed out starting with c0001 through c00057 and a few others starting with d - for example d00016-001 . Some of these later are PDFs. I tried to decript the lpadmin by just using the above line, unchanged, hoping for error messages, and I managed to create a printer called "queue_name" and found the text output to it from xed as a PDF titled d00057-001.
Sorry, remnants of a samba lprng printer for a Windows application from long ago. It is automatically created when you install the samba server. You can create a /var/spool/samba directory it has the same suid permissions as /tmp.
The d files are the actual data which should be the generated output PDF file from xed and you can use it instead of creating a new file but you need to use PIPE_BACKEND_ARGV1 for the job ID. Yes, script.py is just a generic file name for the posted script and can be anything as well as the queue name for the printer.
You can try copying the data file to another directory and convert it to text via pdftotext utility and try printing it to the Epson via lpr.
Thank you, again,
I created the /var/spool/samba directory and have the script.py file in /user/local/bin. In "Properties" for script.py I checked the box "Allow executing file as program." When I executed
It did create a printer "queue_print" with the device url: file:///dev/null
If I try to print to it, I get an "!" on top of the printer icon on the printer for a moment and nothing else. The output isn't in /var/spool/samba but it does show up as a pdf in /var/spool/cups .
Also, if this is the moment to mention it, I didn't understand your comment, "but you need to use PIPE_BACKEND_ARGV1 for the job ID." Is script.py the "pdftotext" utility?
(Thank you.)
pdftotext is a command line utility program that is typically installed by default.
PIPE_BACKEND_ARGV1 is an environment variable created by the pipe backend script. It mimics the actual cups environment variables and you can use that to find out the job ID for processing the input.
script.py is just a python program to "capture" the print output to a file which should be the same as the d00016-001. Its basically the same thing as print to file.
I would say just ignore all that and use the d00016-001 file. I am probably causing more confusion then necessary.
Hello, again, michaelk,
One method might be to "print to a file" and have a little spooler utility that automatically prints anything that appears in a specified folder. I know such programs exist for Windows.
Wayne
Its possible using inotify but we still have the same problem that the file format of a print to file output is PS or PDF which is not compatible with the Epson (at least from what I can tell...)
Shouldn't an Epson printer use a variant of ESC/P? printer-driver-escpr is for inkjet printers. Perhaps, it's backward compatible to ESC/P2 and will work with a dot matrix printer as well? There are also Perl module Printer::ESCPOS for printing receipts on POS terminals and printer-driver-gutenprint. Could they also be compatible?
Here is a synopsis of the problem as I understand it:
The OP can successfully print using dBase via dosemu which uses "lpr -P printer-queue" command and which would be just a DOS ESC/P printer driver so the output is basically plain ASCII.
The OP can not print successfully using xed which we know the standard print output is PDF. cups is not converting PDF back to ESC/P which is accomplished by the rastertoescpx print driver. Either something is wrong maybe with the PPD, rastertoescpx or with cups itself.
Although it was suggested to print the file from the command line i.e. lpr -P printer_queue text_file reviewing the posts I can not find the results. Technically it should be the same as printing from dosemu. I guess I got side tracked...
Although the OP can print successfully via just a "cat text file > /dev/lp0" the process is herky-jerky and slow printing.
Hello, all,
michaelk's synopsis seems correct. I don't see how to print to a parallel printer (unless I accept printing at one line per second, which is too slow for waiting customers). Maybe it's unreasonable to print out to "lpt1" with Linux. I do see that under some circumstances dBase on dosemu can print to a file, sometimes as a text file or to a PDF. My question, now: is there an automated process (program) to print out a txt or pdf file that appears in a specific directory (a simple spooler)? Otherwise, I don't see any way to do what I'm trying to do (send a dBase output to a printer of any kind). I can accept that, and certainly appreciate all the effort that has put into this by the various people at linuxquestions.org . My reasoning was that I wanted to break from MicroSoft, but DOS and dBase belong to their world. I'm embarrassed to have asked for something that may well be ridiculous and impossible.
Sincerely,
Wayne
Just to backtrack a bit because I did not find the answer in any of the posts. Can you print a text file directly from the command line to the Epson i.e.
lpr -P Epson text.file (Or whatever its queue name is called basically the same line as dosemu)
If so, one possible workaround would be to write your own POS program that creates its own printout as a text file then call lpr to print. To fully breakaway from DOS you can convert your dBase to anything supported by linux i.e postgresql, mysql, sqlite3 etc.
These are the names of two of the installed printers I have for lpt1.
I have the feeling that dosemu/dbase may be end-running cups because, when I print out, successfully, but slowly, the little cups printer icon on the lower left right hand corner of the screen doesn't show a "1." Also, the receipt is working (slowly) now with all the "$_lpt1 = " lines rem-ed out in dosemu.conf .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.