Print to TXT file

How do I create a printer / driver that prints to a TXT file that I can pull into a spreadsheet? I need to export data from an application that has no ASCII export ability.

Stef

Hmmm… reads very messy …

You could try print to a postscript file (easy to do with Linux). Then have a custom program to go in and remove the zillions of custom post script formatting characters. There may be some sort of ps2txt or ps2txt program for Linux that helps in that regard, … I don’t know (you will have to surf on this).

WOuld not work with a stock file that has it’s own funny characters in place.

Most applications nowadays are well know. What application has the text? Is the text in a tabular form and do you want to put that into Excel or what have you? If you can print to a ps or pdf file, there are utilities out here that convert the text into something useful. Also Unix is loaded with simple utilities just for this purpose.

A lot depends on the format of the file. Kate will open almost any file and if you have the patience you can often find the text embedded in it somewhere. I’ve managed to extract text from MS Works and Publisher files that way.

Tedious but it gets you there.

I need to extract data from an application to port to another app. The data is the complete stock list, the debitor and creditor data, etc. The application deliberately does not cater for ascii data output (maybe in an attempt to “lock customers in”?)

Once the data is out and in some ascii format, I will be able to manipulate it into a form that the other app can read.

You haven’t said what the application is or what export facilities it does have. Sometimes you can get an indirect export via a third program.

does the application run native in Linux?

does it print to a printer at all?

will it ‘print’ to a file? in any format at all, or is all ‘output’ to a
monitor?

when you look at the data files (stock list, etc) with a plain text
editor (like maybe kwrite, kate, emacs, vim, mc etc) can you see the
text? is it in some kind of logical order…if so, someone (smarter
than me) can probably write a Perl script to strip out all the
non-ascii, control characters and etc…in fact, i’d guess if you
google on the name of that application and some other stuff you might
find someone else has already solved your problem…maybe google

[appName] export ascii Perl

good luck, let us know if you find the solution is easier than writing
a new printer driver…


DenverD (Linux Counter 282315)
A Texan in Denmark

Sorry Denver, I failed to mention: It is cobol base application. You now in good ole unix it was so easy to just set up a printer (mkdev lp) and the go into the spool directory and take most of the script out and voila! - text file printer!

stefaug wrote:

>
> Sorry Denver, I failed to mention: It is cobol base application. You
> now in good ole unix it was so easy to just set up a printer (mkdev lp)
> and the go into the spool directory and take most of the script out and
> voila! - text file printer!
>
>

Always interesting to watch the discussions…

To set up a (temporary) text only printer in cups:

  • Install the ‘cups-backend’ package via yast
  • in a browser, open ‘http://localhost:631’ to access the built-in
    administration services for cups
  • When asked, the username/password is root and your current root password
  • Click on the ‘Administration’ tab
  • on the right, click on ‘Edit Configuration File’
  • Add the following line, best if near the top of file

FileDevice on

  • Save the changes, cups server will restart
  • On the left, should see ‘Add Printer’, click it.
  • Give it an appropriate name ‘textonly’, ‘test1’, ‘savemylife’, whatever.
    location / description are optional, click ‘continue’
  • Device is ‘Printing to any command via pipe’ (we’re going to change this
    actually) ‘Continue’
  • in the ‘Device URI’ field, remove ‘pipe’ and enter the following:

file:/home/user/filename

  • of course, substitute your proper username, and desired output filename as
    needed. Created/Written by root, thus can send it ANYWHERE!! BE CAREFUL
    NOT TO OVERWRITE IMPORTANT FILES!
  • ‘continue’… !
  • Make is ‘raw’, list is alphabetical… ‘continue’
  • Model is ‘Raw Queue…’ … ‘Add Printer’
  • Should see ‘Printer xxx has been installed successfully’ briefly, then it
    goes to some options for the new printer. these may be ignored.
  • click on ‘Printers’ tab, find your new printer, click on ‘Set as Default’.

Some things to be wary of

if program uses LPD to talk to printers, you will need to enable LPD
connections in the cups global settings, found in Yast -> Hardware ->
Printer -> Global Settings (on left) -> third option down, “enable LPD
clients”

the file: backend will overwrite the output file each time it’s used, rename
or move the created file before printing additional items.

the output file is owned by root, you’ll either need to be root, or change the
ownership to view / edit it.

this is a very simplistic solution. a better, long-term solution, would be to
create a proper backend which would not overwrite files, so large batches
could be printed. Please let me know if you need that, it’s relatively
simple to write, but lengthy to put here.

Setting the printer as default is important, since most programs (especially
lpd based) tend to just output to the ‘default queue’, usually ‘lp’. you may
want to name the new textonly printer ‘lp’ for exactly this reason.

Remember to reset your default printer, or remove (or disable) this printer
queue, so you don’t “lose” documents you would really like to print. {Grin}

Hope this helps, kinda lengthy.

Loni
lornix@lornix.com


L R Nix
lornix@lornix.com

Your explanation is not lengthy at all. The application, like all good old cobol stuff just cat to a printer device in small pieces, thus overwriting the file MANY times in a single print - so I do need the propper backend, please.

Your explanation is not lengthy at all. The application, like all good old cobol stuff just cat to a printer device in many small pieces, thus overwriting the file - so I do need the propper backend, please.

stefaug wrote:

>
> Your explanation is not lengthy at all. The application, like all good
> old cobol stuff just cat to a printer device in many small pieces, thus
> overwriting the file - so I do need the propper backend, please.
>
>
Ok, give me a short bit, watching “My Cousin Vinny”, right at the best part,
where he gets Lisa to solve the case! (Love this classic!)

I’ll have it done in an hour or so, will send it here, can send it to your
email directly, you can contact me at lornix@lornix.com

Back soon,

Loni


L R Nix
lornix@lornix.com

Here goes…

new backend is ‘cobolprint’ (original huh?)

File may be downloaded at http://www.lornix.com/files/cobolprint.tar.gz or
http://www.lornix.com/files/cobolprint

Yup, just one file. Maaaagic!

Stef, I’ll write this to support both 64bit and 32bit. (actually only one
difference, a single path)

The ‘cobolprint’ file is a perl script. needs to be copied into the
cups/backends subdirectory,

(you’ll need to be root)

32bit: /usr/lib/cups/backends
64bit: /usr/lib64/cups/backends

The file MUST have permissions of -rwx------ (700), and be owned by root, in
root group.

32bit: chmod 700 /usr/lib/cups/backends/cobolprint
32bit: chown root:root /usr/lib/cups/backends/cobolprint

64bit: chmod 700 /usr/lib64/cups/backends/cobolprint
64bit: chown root:root /usr/lib64/cups/backends/cobolprint

once you’ve verified that the file is in the proper directory, with proper
permissions and ownership… the backend is in place, now we need to add a
printer

browse to http://localhost:631

when you’re asked, username is ‘root’, password is your current root password.

click on ‘Administration’

click on ‘Add Printer’

choose appropriate name, I’ll use ‘cobol’ in this text
location and descripton are optional, fill in as desired
<continue>

Device is “Capture COBOL output to files”
<continue>

Device URI is “cobolprint:/path/to/file”
Thus, I would use “cobolprint:/home/lornix/outputfile”
or “cobolprint:/tmp/cobolstuff”

Choose a VALID location. This location MUST exist. You may not have a
trailing slash on the path, this has to point to a file, not a directory.
(file can’t exist either)
<continue>

Make is ‘raw’, list is alphabetical
<continue>

Model is ‘Raw Queue (en)’
<Add Printer>

(most likely prompted for password here… )

“Printer added successfully”

cups then advances to a page to set banners and policies. ignore this.

click on ‘Printers’ tab

find your printer. in this case, I used the name ‘cobol’

click on ‘set as default’

You’re done!!

Now, ANYTHING printed to the ‘cobol’ printer will show up as a file wherever
you specified with a sequence number.

For instance, if I were to print the cups page currently showing, konqueror or
firefox (or whatever) will send the page as postscript to the cobol printer,
where it’ll be saved as ‘outputfile_0001’ in /home/lornix. The file will be
viewable by me, and owned by me. pretty slick!

Next job printed would be ‘outputfile_0002’, and so on.

backend will dump files to /dev/null IF it gets to _9999 suffix. Relatively
simple to extend the range, but goodness!! you’ve printed 10,000 jobs!?!

if you delete the files (outputfile_xxxx), the backend will start over at the
lowest number available.

I Hope this helps

Loni
lornix@lornix.com


L R Nix
lornix@lornix.com