How printing HTML document via IPP protocol?

2.8k Views Asked by At

So, I write PHP component, that can print documents via IPP (Internet Printing Protocol). But I can not print HTML document (text|html - mimetype) correct. Printer has printed this type as RAW. May be somebody give example of correct request (header and body)?

For example my incorrect request, that was printed as RAW data.

Headers:

POST /printers/CanonLPR HTTP/1.1
Host: 10.2.2.105:631
Connection: close
Accept-encoding: gzip, deflate
User-agent: EHttpClient
Content-Type: application/ipp
Content-Length: 772

Body:

Gattributes-charsetutf-8Hattributes-natural-languageen_usEprinter-uri'http://10.2.2.105:631/printers/CanonLPRDrequesting-user-name
PHP-SERVERIdocument-format  text/html<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="language" content="ru" />
</head>
<body>
<img style="float: left; margin-right: 10px;" src="/static/img/printer.png" />
<h1>Test page</h1>
</body>
</html>
1

There are 1 best solutions below

0
On

Even though e.g. CUPS advertises support for text/html (see it's printer attribute document-formats-supported) it's not converting html to e.g. postscript.

You can not expect a printer or spooler to render HTML for you (like a browser would). You might want to search for a html-to-pdf converter as a workaround.

A typical and proper solution would involve a dedicated pdf-library for creating printable documents. The downside is you'd have to code the layout again.

Step 2 would involve submitting the job to the printer. It look's like you can handle this. If not check this answer. Also there's an IPP implementation for PHP available at http://www.nongnu.org/phpprintipp/