Making Nice-Looking PDF Courses with wkhtmltopdf
For my tech education platform, I wanted every course to have a downloadable PDF: something learners can print, annotate or read offline. My first one was a Linux filesystem crash course, and I wanted it to look designed, not like a Word export.
The trick: write the course in HTML and CSS, then convert it to PDF with wkhtmltopdf.
Why HTML → PDF?
- You already know the tools. CSS gives you full control over typography, colors, callouts and code blocks.
- One source, two outputs. The same content can power the web version of the course and the PDF.
- Automatable. One command rebuilds the PDF after every edit.
What wkhtmltopdf is (and an important caveat)
wkhtmltopdf is a command-line tool that renders HTML with a WebKit engine and prints it to PDF. It's fast, simple, scriptable, and it's in most Linux package managers.
Caveat: the project is no longer actively maintained (its repository has been archived), and it uses an old WebKit engine. In practice:
- Modern CSS layout is limited. Flexbox support is partial and old, and CSS Grid isn't supported. Plan on block layout, tables or floats.
- Modern JavaScript may not run.
- It's fine for document-style layouts. For new projects, also consider headless Chromium (via Puppeteer or Playwright) or WeasyPrint, both actively maintained with better CSS support.
I used wkhtmltopdf because it was quick to set up and my layout was simple. Know the limits before you commit.
The basic command
wkhtmltopdf \
--enable-local-file-access \
--page-size Letter \
--margin-top 18mm --margin-bottom 18mm \
--margin-left 16mm --margin-right 16mm \
--footer-center "[page] / [topage]" \
--footer-font-size 8 \
--print-media-type \
course.html linux-filesystem-crash-course.pdf
What the important flags do:
--enable-local-file-access: required in newer versions to load local CSS, images and fonts.--print-media-type: applies your@media printCSS rules.--footer-center "[page] / [topage]": automatic page numbers.- Add
tocbefore the input file to generate a table of contents from your headings.
[[TODO: paste your actual command if it differs]]
Styling tips that made it look professional
Control page breaks.
h2 { page-break-before: always; }
pre, table, .callout { page-break-inside: avoid; }
Style code blocks for print. Light background, a thin border, a monospace font and wrapped lines so nothing runs off the page:
pre {
background: #f5f5f7;
border: 1px solid #ddd;
padding: 10px;
white-space: pre-wrap;
word-wrap: break-word;
font-size: 9pt;
}
Use callout boxes for tips and warnings. They break up dense technical content:
.callout { border-left: 4px solid #3b82f6; background: #eff6ff; padding: 8px 12px; }
.callout.warn { border-color: #f59e0b; background: #fffbeb; }
Embed fonts locally. Reference font files with local paths (with --enable-local-file-access) rather than web fonts, so the output is consistent.
Make a cover page. wkhtmltopdf supports a separate cover page. It's a small touch that makes a PDF feel like a product.
Gotchas I hit
- fonts not loading
- blank pages
- scaling differences
Other common ones:
- Text looks tiny or huge: try
--disable-smart-shrinkingor set--zoom. - Images missing: the local-file-access flag, or relative paths resolved from the wrong directory.
- Layout looks different from the browser: remember it's an old engine. Test in the PDF, not in Chrome.
The result

The Linux filesystem crash course PDF covers: the directory hierarchy, permissions, mounts, links, command reference
You can check out the full course on sparkskills.dev
