LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 05-17-2021, 08:39 PM   #46
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,732

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920

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.

Last edited by michaelk; 05-17-2021 at 08:44 PM.
 
Old 05-21-2021, 10:04 PM   #47
WayCon
Member
 
Registered: Sep 2019
Posts: 77

Original Poster
Rep: Reputation: Disabled
Hello, michaelk,
I have some questions about the syntax of the line:
Quote:
lpadmin -p queue_name -v 'pipe:/usr/local/bin/script.py/' -E
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.
 
Old 05-21-2021, 10:22 PM   #48
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,732

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
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.
 
Old 05-21-2021, 10:50 PM   #49
WayCon
Member
 
Registered: Sep 2019
Posts: 77

Original Poster
Rep: Reputation: Disabled
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
Quote:
lpadmin -p queue_print -v 'pipe:/usr/local/bin/script.py/' -E
I received the error:
Quote:
lpadmin: Bad device-uri scheme "pipe".
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 .
 
Old 05-21-2021, 10:56 PM   #50
WayCon
Member
 
Registered: Sep 2019
Posts: 77

Original Poster
Rep: Reputation: Disabled
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.)

Last edited by WayCon; 05-21-2021 at 10:59 PM.
 
Old 05-21-2021, 11:13 PM   #51
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,732

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
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.

Last edited by michaelk; 05-21-2021 at 11:24 PM.
 
Old 05-22-2021, 09:35 AM   #52
WayCon
Member
 
Registered: Sep 2019
Posts: 77

Original Poster
Rep: Reputation: Disabled
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
 
Old 05-22-2021, 01:43 PM   #53
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,732

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
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...)
 
Old 05-22-2021, 02:47 PM   #54
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
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?

Last edited by shruggy; 05-22-2021 at 02:55 PM.
 
Old 05-22-2021, 03:21 PM   #55
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,732

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
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.
 
Old 05-22-2021, 09:01 PM   #56
WayCon
Member
 
Registered: Sep 2019
Posts: 77

Original Poster
Rep: Reputation: Disabled
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

Last edited by WayCon; 05-22-2021 at 09:02 PM.
 
Old 05-23-2021, 11:05 AM   #57
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,732

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
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.
 
Old 05-23-2021, 01:00 PM   #58
WayCon
Member
 
Registered: Sep 2019
Posts: 77

Original Poster
Rep: Reputation: Disabled
Hello, michaelk,
Here's what I get:
Quote:
wc@wc-O-Plex-960:~$ lpr -P Generic-Text-Only plain.txt
lpr: Generic-Text-Only: unknown printer
wc@wc-O-Plex-960:~$ lpr -P EPSON-TM-P2.01-2 plain.txt
lpr: EPSON-TM-P2.01-2: unknown printer
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 .
 
Old 05-23-2021, 01:24 PM   #59
WayCon
Member
 
Registered: Sep 2019
Posts: 77

Original Poster
Rep: Reputation: Disabled
Though I see that the following doesn't work, even though I can print to this printer with xed:
Quote:
wc@wc-O-Plex-960:~$ lpr -P Canon_MG2100_series d00026-001
lpr: Canon_MG2100_series: unknown printer
So I imagine I'm having a syntax problem.

Last edited by WayCon; 05-23-2021 at 01:25 PM.
 
Old 05-23-2021, 01:38 PM   #60
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,732

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
The output of the command lpstat -p will display all of the printer queues.

Or you can go to localhost:631/printers in your web browser.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Download a PDF/web page as "text" PDF (ie. not a picture)? littlebigman Linux - Software 7 01-28-2020 06:35 PM
Unsupported PDF data for Direct Print :1000 when printing a PDF document vishnu14 Linux - Server 5 10-18-2019 06:56 AM
[SOLVED] printing the text from a web page without printing the graphics newbiesforever Linux - General 15 03-21-2018 06:39 AM
[SOLVED] Variables in text file, how to get their values when printing out the text? idaham Linux - General 2 04-14-2010 03:28 AM
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 02:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration