LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can I email (formatted) directly to a printer? (https://www.linuxquestions.org/questions/linux-newbie-8/can-i-email-formatted-directly-to-a-printer-623209/)

ayhopkins 02-22-2008 10:32 PM

Can I email (formatted) directly to a printer?
 
Can I email (formatted) directly to a printer?

I found one example on line where someone had used "lpr" in the Mail servers alias file to allow others to print directly using email. I tried this and it does work.

[my case: postfix, cups]

alias file line:
pseudoprinter: "| lpr"
And if you sent email to "pseudoprinter@example.com" it did print the email, but it was only text, with the entire header and it is quite messy.

Is there a way to create a script which would produce a better output using the pipe?

sundialsvcs 02-22-2008 10:57 PM

The cups system does have a lot of drivers and formatters out there; I honestly don't remember if it has one that can munch an HTML file directly. http://www.cups.org I don't think that it does.

To produce HTML output, you probably need to go through a layer of software that can parse and render the HTML page, with all of its various parts, into a printer-metafile or other output that can be printed. This being Unix/Linux, there are many choices.

HTML, by itself, is more of a page-markup language than a strict "hey printer, do exactly this" language a la PostScript. There is, in other words, more interpretation involved.

billymayday 02-22-2008 11:17 PM

You could probably take a mail-to-fax script as a starting point to put something together.

ayhopkins 02-23-2008 09:23 PM

Update
 
Well I found some ways to improve my results.

/usr/local/etc/postfix/aliases
Code:

printE:        "|/usr/local/bin/a2ps -=mail"
printEs:        "|/usr/local/bin/stripmime|/usr/local/bin/a2ps"
printH:        "|html2ps|lp"


After I figured out my CUPS program had A4 as the default page size in the PPD file for the default printer (/etc/cups/ppd/<default_printer> which overrode all the other page directives I found there were about three ways I could currently make "emailing to my printer" a little better.

printE:
a2ps -=mail (any to ps) will convert the email text and the html text (not formatted) into postscript and sent it directly to my printer. It has too much data and no html formatting.

printEs:
I found a perl script "stripmime" http://www.clarity.net/~adam/stripmime/ which allowed me to remove some of the headers and strip the html mime section which further improved the look of a text only email when sent to a2ps.

print H:
Using the html2ps I could send the html code directly to the default printer (using lp). Unfortunately all the headers are removed.

I found some who had a c program which compiled created html code from an email, but I couldn't get that to compile. I hope to perhaps find another way.

ayhopkins 02-25-2008 02:58 PM

Update - Final
 
I found my final solution which requires a little extra work, but works fine. This whole situation was to help a friend who wanted to send messages and fun stuff home to someone who doesn't want to use a computer.

User:
Print to PDF and email the attachment to a special email account (pdfman).
On Windows, a free nice driver is PDFCreator which also allows you to directly email the document. With it you can print any document to a PDF and then email it. You want to have the smallest file size possible when you create the PDF format. Graphics will be a problem

Server:
Set up procmail on a special account, in this case - pdfman. Within the account you need to set up the following files.

.forward
Code:

"|IFS=' '&&p=/usr/bin/procmail&&test -f $p&&exec $p -Yf-||exit 75 #pdfman"
.procmailrc
Code:

:0
|/usr/local/bin/pdfmime|/usr/local/bin/base64 -d|acroread -toPostScript -size letter|lp

It has only one rule (:0).

pdfmime
This perl script is a modified version of "stripmime" mentioned above to extract only the encoded pdf portion of the email - just modify a few variables and selection only "application/pdf" type.

base64 -d or mimencode -u
Use one or the other application which should be in your linux distribution. The commands syntax decodes the Base64 MIME encrypted enclosure.

acroread -toPostScript -size letter
Adobe Acrobat reader does have a command line option to covert to postscript. (acroread -help for other options). It unfortunately requires a writable account to create files which is why a real user account had to be created. This coverts the file to postscript which the printer can understand.

lp
Print to the default printer which understands postscript.


The final result is that you can print almost anything you can convert to a PDF. Procmail will immediately activate when it receives the email.


All times are GMT -5. The time now is 04:29 AM.