Features

This page is for WeasyPrint 0.21. See changelog for older versions.

URLs

WeasyPrint can read normal files, HTTP, FTP and data URIs. It will follow HTTP redirects but more advanced features like cookies and authentication are currently not supported, although a custom url fetcher can help.

HTML

Many HTML elements are implemented in CSS through the HTML5 User-Agent stylesheet.

Some elements need special treatment:

  • The <base> element, if present, determines the base for relative URLs.
  • CSS stylesheets can be embedded in <style> elements or linked by <link rel=stylesheet> elements.
  • <img>, <embed> or <object> elements accept images either in raster formats supported by GdkPixbuf (including PNG, JPEG, GIF, ...) or in SVG with CairoSVG. SVG images are not rasterized but rendered as vectors in the PDF output.

HTML presentational hints (like the width attribute on an img element) are not supported. Use CSS in the style attribute instead.

PDF

In addition to text, raster and vector graphics, WeasyPrint’s PDF files can contain hyperlinks and bookmarks.

Hyperlinks will be clickable in PDF viewers that support them. They can be either internal, to another part of the same document (eg. <a href="#pdf">) or external, to an URL. External links are resolved to absolute URLs: <a href="/news/"> on the WeasyPrint website would always point to http://weasyprint.org/news/ in PDF files.

PDF bookmarks are also called outlines and are generally shown in a sidebar. Clicking on an entry scrolls the matching part of the document into view. By default all <h1> to <h6> titles generate bookmarks, but this can be controlled with CSS (see CSS GCPM: bookmarks.)

Fonts

Although the CSS3 @font-face is not supported yet, WeasyPrint can use any font that Pango can find installed on the system. If you can use a font in a GTK+ application, just use it’s name in font-family. Copying a file into the ~/.fonts directory is generally enough to install a new font, depending on the OS.

Fonts are automatically embedded in PDF files.

CSS

CSS 2.1

The CSS 2.1 features listed here are not supported:

To the best of our knowledge, everything else that applies to the print media is supported. Please report a bug if you find this list incomplete.

CSS Selectors

With the exceptions noted here, all Level 3 selectors are supported.

PDF is generally not interactive. The :hover, :active, :focus, :target and :visited pseudo-classes are accepted as valid but never match anything.

Due to a limitation in cssselect, *:first-of-type, *:last-of-type, *:nth-of-type, *:nth-last-of-type and *:only-of-type are not supported. They work when you specify an element type but parse as invalid with *.

CSS Text: hyphenation

The experimental -weasy-hyphens property controls hyphenation as described in CSS 3 Text. To get automatic hyphenation, you to set it to auto and have the lang HTML attribute set to one of the languages supported by Pyphen.

<!doctype html>
<html lang=en>
<style>
  html { -weasy-hyphens: auto }
</style>

Automatic hyphenation can be disabled again with the manual value:

html { -weasy-hyphens: auto }
a[href]::after { content: ' [' attr(href) ']'; -weasy-hyphens: manual }

CSS GCPM: bookmarks

PDF bookmarks are controlled as described in CSS Generated Content for Paged Media. This module is experimental: the properties need to be prefixed: use -weasy-bookmark-level and -weasy-bookmark-level.

For example, if you have only one top-level <h1> and do not wish to include it in the bookmarks, add this in your stylesheet:

h1 { -weasy-bookmark-level: none }

Other CSS modules

The following features are supported:

Table Of Contents

Previous topic

API

Next topic

Hacking WeasyPrint

This Page