Company logo in reports

Usually there is the need to show the company logo on printed reports, so it will be great if we add some fields on company to allow the user to customize it. In trytonspain there is a module [1] which add the logo as Binary field, so the idea is to include in base at least this fields:

  • logo: field.Binary
  • width: field.Integer which stores the logo width
  • height: field.Integer which stores the logo height

We can also change header and footer to HTML fields, but we first need to solve issue2068.

Do you think more fields are needed?
Do you think that this information can be reused for other usages?



To put an image in Relatorio, we also need the mime-type (which is limited to the relatorio.templates.opendocument.EXTENSIONS).

About the size, is it not better to get a fixed size and resize the binary on the fly?

Also the generic common header/footer should be improved to include the image when it is present (maybe it should be optional). Maybe there are cases where user wants to have the logo on the footer.
I think we need to get an example of such generic header/footer.

Another possibility will be to allow HTML in the header/footer which could contains <img/>.

+1 For HTML in the header footer.

For the mime-type, can not be detected when uploading the image? I think it’s too complicated for end users to enter the mime-type.

+1 For HTML in the header footer.

For the mime-type I would use just one type and use pillow (o whatever) to convert the uploaded logo to this on the fly. The same way for image size.

For HTML, we will need first to solve issue2068.

I would prefer to keep pillow dependency as optional.
So we could say in the help that the image should be in this format with this size and if pillow is available we proceed to the conversion otherwise we will let the report fails later.
Indeed the resizing will only be about limiting the size of the resulted document.

1 Like

I will agree to keep dependencies as optional. So for me we can go ahead with JPEG or PNG formats.

I prefer PNG because it support alpha channels


IME, logos work best when in some kind of vector format. SVG seems to work well enough with libreoffice.

PNGs and (deity forbid) JPEGs give poor result, either their resolution is too small or leads to scaling issues or their size is too large. Sometimes white background in the logo is not really white, leading to strange colored or gray rectangles, depending on output-device and -capabilities.

SVG even works in current web-browsers out of the box, and shouldn’t have size- or fuzziness-issues on high-DPI-displays.

1 Like

But it is not yet supported by relatorio see:

Are you shure that is really needed? putting this

image: (StringIO(str(production.barcode128)), 'image/svg','6cm','1.5cm')

into the “Name”-field of an image in a report in libreoffice seems to suffice.

I’m pretty sure because this code will fail.

oups. I just noticed that I added
'image/svg': 'svg',
to relatorio.templates.opendocument.EXTENSIONS. I don’t know if anything more would be needed for “proper” support, but for barcodes and logos, this works for me. I can prepare code review for relatorio.


3 posts were split to a new topic: AttributeError: module ‘magic’ has no attribute ‘from_buffer’

Here is Support company logo in report (#13205) · Issues · Tryton / Tryton · GitLab