LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   Printer for printing to files (https://www.linuxquestions.org/questions/linux-desktop-74/printer-for-printing-to-files-4175598014/)

Janvanl 01-22-2017 01:45 PM

Printer for printing to files
 
Hi
after searching in all direction I ask it here.
Is there a "printerdriver" for printing to plain text files that get saved on disk.

I can hardly imagine being the first that needs this but on the internet I cannot find a solution.

Regards,
Jan

michaelk 01-22-2017 02:03 PM

Look at the print dialog box in your GUI text editor. There should be a print to file option in the printer list where you can save the output to one of several outputs like PDF. If this does not work then we need some additional information.

Janvanl 01-22-2017 02:54 PM

Thanks for the fast reply!

Ok
I found that I could define a printerque "raw" but that is no longer there, neither in Kubuntu 12.04
nor in 16.04.

What I would like is a printerque that I can print to but which saves plain textfiles without overwriting
the old ones like the PDF-printer does. (some name with date/time would do)

I know a lot is possible with lpr but did hope someone already did this.

kind regards,
Jan

michaelk 01-22-2017 03:48 PM

There should be a text box in the printer dialog where you can enter the filename of your choice.

What do you mean by saves plain text files. It seems like a bit of a paradox that you want to print to file a text file that saves as plain text.

Janvanl 01-22-2017 04:00 PM

You are right,

I want to print output from a programm to plain textfiles to produce csv-files that can be imported in another programm
because there is no functioning interface between the two. I have made several bash-scripts already to build a temporarily
solution.

We are working on the interface but that will take some time.

Some 20 years ago I did similar things with vaxvms, now openvms,
but even linux on the desktop runs so you do hardly need a command line anymore,
one gets rusty . . . .

Kind regards,
Jan

TB0ne 01-22-2017 04:18 PM

Quote:

Originally Posted by Janvanl (Post 5658738)
You are right,
I want to print output from a programm to plain textfiles to produce csv-files that can be imported in another programm because there is no functioning interface between the two. I have made several bash-scripts already to build a temporarily solution. We are working on the interface but that will take some time.

Some 20 years ago I did similar things with vaxvms, now openvms, but even linux on the desktop runs so you do hardly need a command line anymore, one gets rusty

Check out the "FileDevice" directive in the CUPS configuration:
http://git.net/ml/printing.cups.deve.../msg00007.html

There is also CUPS-PDF, which will shovel it into a PDF...from there, you could use pdf2txt (intermediate step, yes, but it could work at least)
http://www.cups-pdf.de/

OR, you could write your own printer in Perl:
Code:

#!/usr/bin/perl
use IO::Socket::INET;
$myport=<put some port number here>;
$pserve=IO::Socket::INET->new(LocalPort => $myport,Type=>SOCK_STREAM,Reuse=>1,Listen=>1) or die "can't do that $!\n";
while ($pjob=$pserve->accept()) {
  open(J,">>/private/tmp/x") or print "having issues $!\n";
  print J "New job...\n";
  while (<$pjob>) {
  print J "$_";
  }
  close J;
  close $pjob;
}

And just add a print device in CUPS to print to port <whatever you specify> above. Easy enough to shove something in there to check for the existence of a file, and rename accordingly if one exists when you try to print. Or just name the print file the Unix epoch time, so each should be unique.

Janvanl 01-22-2017 05:16 PM

Thanks T-Bone

That was what I was looking for!

Now I have something to do,
I like the perlscript.

Just added a rawprinter in cups and searching for the spooled files but the rst is for tommorow.

Kind regards,
Jan

michaelk 01-22-2017 06:38 PM

Here is some additional information about cups filters.

https://en.opensuse.org/SDB:Using_Yo...rint_with_CUPS

In addition I have also setup a samba printer using LPRNG that you can add to cups. The basic code is:

Code:

  [myprinter]
        comment = my printer
        printing= LPRNG
        path = /var/spool/samba
        printable = yes
        print command = /usr/local/bin/myscript %s


Janvanl 01-24-2017 02:59 PM

Almost there, the perlscript is perfect

Just, I need to get plain text instead of postscript and I cannot grasp where to put the right parameters.

sudo lpadmin -p tofile -E -v socket://localhost:12000 -m raw
gives a postscriptfile

sudo lpadmin -o document-format=text/plain -p tofile -E -v socket://localhost:12000 -m raw
gives a postscript file

I added -i, took away -p but no luck so far, what am i overseeing?

Knd regards,
Jan

michaelk 01-24-2017 03:38 PM

The -p is the name of the printer queue and the -i would be the name of the filter script.

The perl script does not alter the incoming print stream so your application is actually outputting Postscript?

Janvanl 01-24-2017 04:03 PM

I printed a textfile from Kate and if I choose "tofile" as a printer then this "printer" should use a PPD-file when appropriate doen't it?
Why it uses postscript I cannot see.

At least is that what I understand from "man lpadmin".

Kind regards,
Jan

Janvanl 01-24-2017 04:17 PM

If I print from the application it als sends a postscriptfile.

Kind regards,
Jan

michaelk 01-24-2017 04:32 PM

Your tofile printer will only use a PPD if specified one when it was created i.e. -P option.

It depends on the application / version / distribution but in the past the default file print format was postscript.

Janvanl 01-25-2017 02:40 AM

Thanks michaelk,

I know that and therefore I wonder that postscript is used.
This is Ubuntu 12.04 with KDE on top but that does not matter much.

Main thing is, I get a plain text file. what comes out as a ps-file is a perfect printout.
This hard to find in internet.

Kind regards,
Jan

michaelk 01-25-2017 05:07 AM

You can print from the command line using lpr which will use plain text or if you have to use kate add a PS to text conversion.


All times are GMT -5. The time now is 09:00 PM.