0

I have a Java application, which communicates to a printer and prints documents. Till now I needed only PS/PDF and the printer could handle that. However, now I need to print HTML documents also.

I have seen that it is possible to do it using JavaFX (WebView), but the server on which the application runs does not have a display. Hence, I cannot render it to a display object (in Swing or AWT). What are my options to get a PostScript rendering of a web page which I can then send to the printer?

One solution I had was to use xvfb to emulate a display screen, but that not only seems far fetched, but also is impossible for us to maintain as we use cloud services and our current CI framework does not handle management of system-level binaries.

Any help is greatly appreciated.

1

2 Answers 2

1

That iText is what I'm using in one of my projects to generate PDF on a server from an HTML page. doc is the HTML Document and output is an OutputStream.

ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(doc, null);
OutputStream output = ec.getResponseOutputStream();
renderer.layout();
renderer.createPDF(output);
Sign up to request clarification or add additional context in comments.

2 Comments

Hi! Thanks for replying. How do you set the width/height of the pdf? i.e. how would I specify the printing dimensions for the generated pdf?
I'm not setting up the dimensions. By default it looks to be like the default paper size with is DIN-A4 for me. There is like a lot of documentation on the library so there should be settings for this. You might also be able to set it via CSS properties in your HTML source document
0

As you already have the infrastructure for printing PS/PDF, you can "convert" (render) your HTML into PS; see: what is the best way to convert html to postscript? in java

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.