Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am interested in creating a "print server" for my web application and I've thought about various ways to solve the problem and came up with this solution. I found a plug-in for firefox that will get it to print from the command line (including PDF files). So I want to install FF on my Ubuntu10 server, then have my PHP scripts call FF through the command line to print to PDF the specified URL. When the operation is complete the PHP script will pick-up the generated file and send it out to the user.

Are there any issues with installing FF with no GUI on an Ubuntu server installation? Is there any obvious bottleneck's to this solution? I've been working for the last hour or so to get Firefox to run from the command line and it keeps telling me "Error: no display specified" , which makes sense as I'm running a headless server. Is there any way to get FF to run from the command line on a server with no GUI installed?

If need be, I think we will have to setup a Desktop edition (GUI) with Apache+PHP setup on it to do what we need, but it would be nice to have it all running on server boxes.

Thanks everyone

share|improve this question
    
This isn't the way to go about doing what you want I'm afraid. –  Ben Pilbrow Jul 18 '10 at 23:12
1  
I'm afraid I forgot to add the most important part to my original question... I need a HTML-2-PDF conversion... not just dumping some data from PHP into a PDF file. Real nested tables, images, CSS support... the real deal –  Greg Jul 19 '10 at 0:31

3 Answers 3

I'd suggest wkthtmltopdf to render a html page as pdf (including stylesheets) and print it via CUPS/deliver it to the user/do whatever you want with it.

share|improve this answer

This is definitely not a good way to create PDFs from PHP. There are libraries for this (i.e. FPDF).

Edit: Ok, with you comment this rules out PHP libraries. Maybe this helps? Appears to do what you want. If this still requires an X11 display set, investigate xvfb, which will create a virtual display.

share|improve this answer
    
None of the PHP libraries that I've explored are able to handle complex HTML-2-PDF conversion... nested tables seem to be the devil for this type of conversion. In fact, in the library you linked to had this to say in it's FAQ: # 19. Can I convert an HTML page to PDF with FPDF? Not real-world pages. But a GPL C utility does exist, htmldoc, which allows to do it and gives good results: None of the PHP libraries for doing HTML-2-PDF conversions seem to have anything close to the functionality of just doing a "Print to file"->PDF inside of the FF browser. IE has a similar feature. –  Greg Jul 19 '10 at 0:29

One word: PrinceXML. The only thing I know of which can reliably convert CSS/HTML to PDF. (You didn't state that you want a no-cost or a Free Software solution :-) ).

An alternative (dual-licensed: no-cost/Free Software or moderate-priced/commercial) is HTMLDOC. But it does not support the full set of CSS...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.