CourtBouillon

Authentic people growing open source code with taste

WeasyPrint v69 Has Been Released

WeasyPrint v69 has been released! Among the new features and bug fixes, the changelog contains important API changes and security information.

⚠️ If you use presentational hints and restrict CSS rules, you have to upgrade WeasyPrint to avoid possible CSS injection. ⚠️

Logical CSS properties

Version 69 supports logical properties.

Many CSS properties like borders or padding allow users to define top, bottom, left and right values. This way to define the layout seems to be obvious, but they may not be adapted to more complex cases 🤔.

Text is written from left to right in languages that use the latin alphabet, but it can also be written from right to left, in Arabic or Hebrew for example. This text direction changes the way text is horizontally aligned, but can also change the whole layout: most important elements are supposed to be seen first, they have to be displayed on the side where the text starts.

That’s why we can now define the position of some properties by using the axis (inline or block) and the side (start or end). This way, users can for example add a border on the left in English but on the right in Arabic, using the same border-inline-start property:

These properties are more and more used in stylesheets, especially by CSS frameworks that love to include bleeding edge features as soon as possible. They are part of our effort to support Taiwind 4 ✨, so don’t hesitate to upgrade if you’re still using older versions of these libraries!

Viewport units

The famous vw and vh units are now available in WeasyPrint. And they’re not alone!

The vw and vh units define lengths as percentages of the viewport’s width and height 🏞️.

In browsers, the viewport is defined as the rectangle where the page is drawn. Depending on how the window decorations and buttons are displayed, we’ll then need to rely on different viewport definitions: large, small and dynamic viewports, with their related lv*, sv* and dv* units.

All these units are equivalent for printed media, as there’s no interface decoration. Percentages are relative to the page area, which is the rectangle inside the page margin, border and padding. This is useful to define sizes that depend on the rectangle where the content is placed.

But what about elements that are supposed to cover the whole page, including margins? These elements can use the pv* unit, especially designed for this case 📃!

Other variants are available:

  • the *vi and *vb units, relative to the logical inline and block axes, as explained in the chapter above;
  • the *vmin and *vmax units, relative to the minimum and maximum values of their *vw and *vh equivalents.

And More…

As usual, this new version of WeasyPrint comes with various improvements and 🐛 bug fixes, including:

  • The output intent of PDF documents can be set using the --output-intent, replacing the --srgb option. It also supports ICC color profiles, for printed documents 🌈.
  • Angle units are now supported in SVG transforms, and the + sign can be used as SVG path separator.
  • Validity of PDF/A, PDF/UA and PDF 2 documents has been improved ☑️.
  • The detected mimetype of attachments is more consistent across platforms.
  • Honor language-specific rules for uppercase, lowercase and capitalize text transformations.
  • More corner cases are supported in table, grid and flex layouts!

What’s Next?

We hope you’ll have fun with this new version!

WeasyPrint is now regularly downloaded more than 1 million times per day on PyPI 🤯. The library is in the top 1000 of all Python packages, and some of its dependencies are even higher. These amazing numbers show the increasing popularity of WeasyPrint, and we would like to thank you for your support ❤️‍🔥!

If you use WeasyPrint professionally, there are many ways we can help you. One of them is to subscribe to one of our the consulting packages. These packages are the best way to get quick answers to the questions you may have about WeasyPrint, paged media, layouts and design. Instead of spending days to solve these problems by yourself, instead of suffering from your unsolved questions day after day, it’s time to send us one short mail and share your pain points with us!

Some of our work on CSS specifications will be implemented soon. You may be interested in the new CSS module we’re writing: CSS notes. If you’d love to use side notes, as in many books of the famous Edward Thufte, stay tuned 😎!