• Skip to content
  • Skip to link menu
KDEPrint Homepage
  • KDEPrint Homepage / User Contributions / Advanced KPrinter
 
 

Advanced KPrinter Usage

This section is a user contribution detailing advanced use of KPrinter, the KDEPrint printing utility. Our first article describes how you can setup "Special Printers" with the help of the "Command Editor" to "print" to some rather unusual devices.

Creative use of "Special Printers"

By Paul Evans.

Anyone who has printed anything from a KDE application lately can not fail to be impressed by KDEprint. Michael Goffioul and his team have given us all a wonderfully solid and flexible way to print from nearly any application. I use KDEprint in combination with CUPS (Common Unix Printing System) to painlessly configure multiple local and network printers wherever I work and the beauty of KDEPrint is that regular users find it just as easy to use in their day-to-day work.

The KDEPrint group are always careful to point out that KDEPrint is not a "real" printing system like 'lpr' or anything, but merely a GUI to give you control over one. This is true, but giving the user the choice between sending the print job to an actual printer or a special/pseudo printer opens up a whole world of possibilities. KDEPrint ships with a few default examples which are very useful:

Mail PDF file Automatically converts the printed output to PDF file and runs Kmail with it as an attachment.
Print To File (PDF/Acrobat) Converts the printed output to PDF and stores it on your hard-drive.
Print To File (PostScript) Stores the file as PostScript on your hard-drive.
Send To Fax Prompts you for a phone number and faxes the document for you.

This good natured openess and ease of use is just begging to be used by opportunistic scripters (like you and me).

When I first floated my mouse over the little icon icon for adding a special/pseudo printer the tooltip read "Add special (pseudo) printer". Intrigued, I (of course) immediately pressed it to see what would happen. This gave me a blank dialog which I just knew I would really like to use, but what was the syntax and how could I play with it? Not to worry, right-clicking on an existing pseudo-printer and choosing 'configure' showed me all I needed to know:

Configure dialog screenshot

What it boils down to is this: everything which prints under Linux produces either PostScript or plain text and KDEPrint allows you to re-direct that output wherever you want. Ta da! We can easily change either of those at will to whatever we want. Even PostScript is just plain text when you get down to it. This means:

  • We can search for patterns in the print job and replace them.
  • We can use 'pstoimg' and 'convert' to get bitmaps from PostScript.
  • We can grab or convert output to plain text.
  • We can use all the netpbm tools on resultant bitmaps.
  • We can use any language we want on the texts.

This all makes KDEPrint not 'just' a printer chooser, but also a file converter! Basically, you can make it do anything you or your users can dream up -- and they do think up some doozies. What follows are a couple of things I would never have thought of myself, but just seemed like natural questions to clients.

How do I print without revealing everyones email address?

Er, how indeed? I didn't have an immediate answer to that question, but while I was explaining 'why not' the 'how' came to me: KDEprint! Here's all it took:

#!/bin/bash
cat $1 | grep -v ".\+@.\+\..\+" \
 >~/.print.ps; kprinter ~/.print.ps

This one-liner just looks for the pattern of dots and '@' symbols which typify email addresses and outputs anything which doesn't match. Next, the semicolon allows us to put two commands on the same line and just calls kprinter again with the result, so the user can decide where the print job will really go. The script can be downloaded here.

Image

The above screen-shot shows how easy it was to incorporate into KDEprint. It's just 'scriptname %in'. That's all.

How do I have my email read to me?

This one requires a little explanation. It happens that a good friend of mine who is very smart and capable in every field of endevour has a problem with reading. He swaps letters and sees 'd's as 'b's etc. This dyslexia makes it difficult for him to carry on his business day to day, but especially when he uses a computer. One day, about two years ago, he brought over a CD containing ViaVoice from IBM and asked me to 'make it work'.

Selection list

ViaVoice turned out to be a free (as in beer) implementation of a text-to-speech converter and vice-versa. At that time I was using perl for everything having finally switched from rexx, but I felt that I should really have at least some real grasp of bash, so I resolved to write the script in bash: It is very ugly. However, it does work and even though my pride wants to rewrite it in python I never have.

Basically, the 'readfile' script just attempts to figure out what sort of file it's being fed and converts it to plain text using lynx. There is also some special treatment for mhonarc mail file names, so that they are referenced correctly from html frames.

Anyhow, when the question about having email read arose the readfile script already existed on his machine, so I only had to write a very simple script to 'print' to it:

#!/bin/bash
# pseudo printer for kprinter
# Takes output from kmail, strips out '>'s and
# then sends it to viavoice to read.
# pevans@users.sourceforge.net 2001-02-21 09:09

cat $1 | sed 's/>/ /g' >~/print.ps
ps2ascii ~/print.ps | sed 's/:-)/haw haw!/g' | \
sed 's/:-(/boo hoo./g' | sed 's/;-)/wink wink./g' > \
~/reader.txt
readfile ~/reader.txt

read email configuration dialog

The actual script is here.

You may have noticed that I never entered any "Requirements", but things seem to work just fine without them. When I did try to enter one I was warned that the requirement was not satisfied, so I just didn't bother with it anymore. You should be aware that I'm not using the newest version though - I'm still on an older version that came with Mandrake 8.2. The 3.0 version is out and may look a little different to what I've shown here in addition to having new features/fixes.

Other ideas

Really, how you can use KDEPrint is only limited by the imagination of you and your friends and clients. Here are a few other ways to use this great interface:

Print to wallpaper Use 'pstoimg' to convert the output of KOrganizer to a bitmap and have your calendar on a desktop.
Print to a translator O.K. - I haven't actually done this, but it might be neat. Especially if you then pipe the output to ViaVoice or Festival.
Add a logo to invoices etc. Just insert a 'translate' command in some eps or concatenate some other PostScript and remove the redundant 'showpage'.
Print to vector graphic file Use 'pstoedit' to create an editable vector file, say for Xfig.

Any of the many PostScript utilities are likely to work, even without knowing the PostScript language - I don't...

I'm sure you get the idea by now. Please let me know of anything you write as a result of reading this. I can be reached at pevans@catholic.org. Oh, and if you rewrite the 'readfile' script nicely I'd especially like that...

[ Edit ]

Inform

Skip menu "Inform"
  • Home
  • KDE Home
  • News
  • Information
  • People
  • Mailing Lists
  • In The Media
  • Get Involved

KDEPrint

Skip menu "KDEPrint"
  • Overview
  • Screenshots
  • Hacks

Documentation

Skip menu "Documentation"
  • FAQ
  • KDEPrint Handbook
  • Tutorials
  • User Contributions
    • Advanced KPrinter

Downloads

Skip menu "Downloads"
  • Downloads

Develop

Skip menu "Develop"
  • Developer Resources
  • Work plan

Global navigation links

  • KDE Home
  • KDE Accessibility Home
  • Description of Access Keys
  • Back to content
  • Back to menu

Search:


Maintained by printing.kde.org Webmaster
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal