Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a HTML file that is using a style.css and has colors, ex.:

<font style=BACKGROUND-COLOR:red; color=white>FOO</font>

How can I "export" this local file on my Ubuntu 12.04 to a PDF? (the look and color should stay the same). I tried ex.: Ctrl+P -> print to PDF, but it didn't preserve the colours. I tried htmldoc with the --color option.. but it's the same problem..

It would be great to do this via the command line.

share|improve this question

4 Answers 4

up vote 5 down vote accepted

Open your html file in LibreOffice Writer and then, under File in the menu, choose export to PDF. That's it.

If you prefer the command line, take a look at Convert HTML Page To a PDF Using Open Source Tool - Linux / OS X / Windows.

The software can be installed using sudo apt-get install wkhtmltopdf.

share|improve this answer
I think this can be automated on the command line as well with some efforts. :) –  gertvdijk Jul 15 '13 at 7:08
@gertvdijk, That is beyond my competence. I've never used LibO via CLI. –  user25656 Jul 15 '13 at 7:14
There is this, wkhtmltopdf, as well but I have no experience of it: cyberciti.biz/open-source/… –  user25656 Jul 15 '13 at 7:16
Please post wkhtmltopdf as ANSWER, it resolved the problem –  gasko peter Jul 15 '13 at 7:28
@gaskopeter, done as requested by editing the answer. –  user25656 Jul 15 '13 at 7:36

Web2PDFConverter extension for Chromium or Chrome convert any webpage to PDF.

Or, you can just only use this site: http://pdfcrowd.com/. For local files: http://pdfcrowd.com/#convert_by_upload

share|improve this answer
using Firefox+cmd line would be better:P –  gasko peter Jul 15 '13 at 7:19
@gaskopeter pdfcrowd.com/#convert_by_upload - open it in Firefox –  Radu Rădeanu Jul 15 '13 at 7:21

Webkit HTML to PDF:

sudo apt-get install wkhtmltopdf



The latest version is headless (does not require X server).

Another possibility: phantomjs is a magic headless web browser, also based on webkit html. It can export a page as PDF among other things.


share|improve this answer

Try dompdf. Here is a link explaining HTML to PDF PHP

share|improve this answer
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. –  David Foerster Nov 14 '14 at 3:58

protected by Community Dec 9 '14 at 7:49

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.