How to convert HTML to PDF with HTMLDoc on Debian 10

HTMLDOC is an open-source program that can be used to convert HTML and Markdown source files to PostScript and PDF files. There are two types of HTML files, 1) Structured documents with headings like, H1, H2, etc that is known as book and 2) unstructured documents without headings that are known as web pages.

In this tutorial, we are going to explain how to install HTMLDOC on Debian 10 and convert an HTML file to pdf.

Requirements

  • A server running Debian 10.
  • A root password is configured on your server.

Getting Started

First, update your system with the latest version by running the following command:

apt-get update -y
apt-get upgrade -y

Once your system is updated, restart it to apply the configuration changes.

Install HTMLDOC

By default, HTMLDOC is available in the Debian 10 default repository. You can install it by just running the following command:

apt-get install htmldoc -y

After installaing HTMLDOC, you can list all the options available with HTMLDOC with the following command:

htmldoc --help

Create Your First PDF from HTML

First, create a test.html file with the following command:

nano test.html

Add the following code:

<html>
<head>
    <title>This is my first PDF</title>
</head>
<body>
    This is the body of my first PDF.
</body>
</html>

Save and close the file, when you are finished.

Now, run the following command to converts test.html to test.pdf with the following command:

htmldoc --webpage -f test.pdf test.html

The above command will generate a new pdf file named test.pdf.

Congratulations! you have successfully installed HTMLDOC on Debian 10 server.

Share this page:

1 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: Kevin

Judging from the website and its list of things it doesn't support, I'm curious why someone would use this over things like pandoc and wkhtmltopdf? Those would seem to have better features. Also please don't specify that one must be running a "server" with Debian 10. Firstly, that's just not true, as htmldoc is available on other Linux distros, etc. Maybe you just meant that to follow these instructions, you should be. But more importantly here, Debian is just fine on a desktop computer or workstation; it needn't be a server. Some of us would like to end the myth that Linux is only for servers.