0

I am preparing an acceptance testing tool for java web start application. That app autoprints pdfs to system-installed printers and I want to verify if produced pdfs are correct. To do this I am looking for a way to mock printing.

I found a way to register a custom printing service before the test:

PrintServiceLookup.registerServiceProvider(fakePrinterService);

And I know how to select that fake printer service in my tested application.

Unfortuately I found no implementations of javax.print.StreamPrintService that I can use to print to a file except of sun.print.PSStreamPrintService, which prints to postscript. It also seems to be a part of internals of the JDK, not a public API. Works but leaves some doubts.

Are there any other java printers implementations? It would be best if it could print a pdf. If not I guess I will go with PSStreamPrintService and ps2pdf conversion.

tporeba
  • 867
  • 10
  • 23
  • Why not mock it with something like JMock or Mockito? – cjstehno Feb 04 '15 at 15:35
  • Worth trying, but not that easy as using ready printer implementation if such exists. My final goal is to save that printed document to pdf file, so I can compare it with earlier prepared template. Mocking would be fine, if I could access raw data from mock. In my case document stream is somewhere in `java.awt.print.Book`, inside `org.icepdf.ri.common.PrintHelper`, so it is not easy to get it out. – tporeba Feb 04 '15 at 19:10

0 Answers0