CourtBouillon

Authentic people growing open source code with taste

WeasyPrint Without Cairo: Beta Time

After many months of hard work, we have never been so close to a WeasyPrint release without Cairo and now it is the moment for you to try a beta 🎉!

What Is New?

The main new thing, of course, with this WeasyPrint beta version is that it doesn’t depend on Cairo anymore. One less non-Python dependency!

Cairo is a high-level PDF (among other things) generator. In order to remove it, we had to use another PDF generator. So we created our own low-level PDF generator called pydyf, fully written in Python 🐍.

This beta also includes new features and bug fixes like:

  • leader support;
  • WOFF fonts support;
  • more ISO and JIS paper sizes;
  • nicer kerning.

Also, we worked on a new documentation architecture, clearer and easier to dive in 📖. Don’t hesitate to tell us what you think about it or if you find a mistake.

What about SVG Support?

If you already follow our adventure, you know it. With the removal of Cairo, we had to find a solution to support SVG as we used CairoSVG before (that, as you may guess with the name of the project, depends on Cairo).

First, we thought about creating a new library to handle SVG with pydyf. But after a short developing time, we realized that it would make the library too much dependent on WeasyPrint and that it won’t be usable for other project. So we directly included SVG support into WeasyPrint.

As you may suspect, supporting SVG is a bit complex. Most of the tags should work like a charm, but the following features may be broken or not supported yet (compared to CairoSVG):

  • clipping;
  • gradients;
  • filling text with sources;
  • text on path.

Also, by spending time working on SVG, we took the opportunity to have a basic inline SVG support!

Are Some Features Lost?

With this kind of big changes, you may be wondering whether some WeasyPrint features have been lost. And that is a good question.

Because of the complexity, we don’t support color emojis anymore (you are still able to use black and white ones). It’s not a feature that is going to be lost forever but it’s not our top priority for now.

If you have time (and patience) to dive into this, contributions are always welcome 😉.

Cairo was also used to provide PNG export. As we removed Cairo, PNG export won’t be supported anymore by WeasyPrint. If you use this feature, we recommend you to look at Ghostscript or Poppler which are two open source tools that provide powerful PDF to PNG conversion.

What Are the Next Steps?

The next big step is a real release of this version of WeasyPrint.

But before that, we need you to try this beta and report bugs 🐛!

On our side, we are going to continue working on SVG support and we will (try to) fix all the bugs you will find.

After that, it will be time for a real release 🎇.

Have fun with this beta 💜.

Edit: in order to improve WeasyPrint, we launched a short survey to know more about your needs. It’s open until the end of May, that’s the occasion to tell us everything about you and WeasyPrint 😉