Company logo in reports


(Sergi Almacellas Abellana) #1

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?

[1] https://bitbucket.org/trytonspain/trytond-company_logo


(Cédric Krier) #2

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/>.


(Sergi Almacellas Abellana) #3

+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.


#4

+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.


(Cédric Krier) #5

For HTML, we will need first to solve issue2068.


(Cédric Krier) #6

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.


(Sergi Almacellas Abellana) #7

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


#8

I prefer PNG because it support alpha channels


(Robert Schöftner) #9

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.


(Cédric Krier) #10

But it is not yet supported by relatorio see:


(Robert Schöftner) #11

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.


(Cédric Krier) #12

I’m pretty sure because this code will fail.


(Robert Schöftner) #13

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.


(Richard PALO) #14

We would like to add png, jpeg and eps images, where exactly do these image types need to be added?
(actually, the eps have turned into x-vclgraphic)
That is, there is not only a single company logo, but also other images such as certifications that need to be displayed on externally communicated documents.

[edited]
seems relatorio has restructured and no longer uses EXTENSIONS as did when the earlier posts were made.
That said, I don’t understand why it does not simply copy any images in the template document even if not overridden programmatically.

For example, the template has the following snippet:


</draw:frame><draw:frame draw:style-name=“fr2” draw:name=“Image1” text:anchor-type=“paragraph” svg:x=“0.25cm” svg:y="-1.06cm" svg:width=“3cm” svg:height=“2.551cm” draw:z-index=“7”><draw:image loext:mime-type=“image/jpeg”>
office:binary-data

the report generation using this template fails with:

AttributeError: module ‘magic’ has no attribute ‘from_buffer’

How to get this to work, being single company, we don’t care to override the images programatically anyway.