對JavaPrintService API的一個誤解
使用JavaPrintService API打印HTML文檔失敗,原來是因為對JPS的誤解。雖然JPS中提供了DocFlavor.INPUT_STREAM.TEXT_HTML_HOST類型的DocFlavor,但根本沒有提供具體的實現(xiàn)HTML打印的功能。
This is "not a bug". It is user misunderstanding of the API.
Note that contrary to the indication of the submitter there is
documentation on this API.
See http://java.sun.com/j2se/1.4/docs/guide/jps/index.html
We have already documented explanation of this aspect of the API in
the user guide and in javadoc specification for the DocFlavor class.
Eg in the user guide it says
"..Before printing a document of a particular format, the client needs to ensure
that the printer can understand the format..."
The API allows you to ask to find all print services that print a particular
document type. A document type is little more than a mime string.
The only point in being able to ask the question is if there's more than
one possible answer. If all print services could print all document types
there'd be no need for such a query.
You can ask for almost anything. For example I could ask for a PrintService
that prints RTF or TIFF or anything. But for a print service to be able to
do that requires a whole lot of code somewhere that understands that format.
In merlin (1.4) there's no code anywhere in the printing implementation
that can handle any HTML in any form at all.
So when you ask for services that handle this, the answer is there are none.
The only way this is going to work is with some additional software.
A third party could write this and plug it in, (read the API docs for more
background in what's involved there) but that's a large chunk of
work and unlikely to be available any time soon.