Use BytesIO instead of StringIO.

This is to workaround an issue with weasyprint and cffi.

Change-Id: I1f5157dd98ea02ca0bfa454ed38c16fa6590e9ee