QGIS – Adding Feature-Linked Image in Report Layout

fields-attributesimageqgisreports

In QGIS 3.16. This is related to this question and this question for which the only posted answers do not solve my problem.

I am creating a report with a field group section; the goal is to have 1 page per feature, with various attributes of each feature displayed on the page. One attribute is 'Image' which links to a .JPG (via Layer Properties–>Attributes Form–>Widget Type = Attachment).

In order to display the image on the page, I have done the following: 'insert image', then in Object Properties, 'Data-defined value', and from the menu, "Field type: string" and select the 'Image' attribute.

When I do that, the image box is filled with a giant red X. If I try to export the report to PDF, I get a two-panel error message; the top panel reads "The image source is missing or corrupt", and the bottom panel reads "The source of the image cannot be loaded or is corrupt" followed by the correct name of the .JPG file it attempted to load.

The files are not missing or corrupt; the attribute is the correct type (String, with a sufficiently long character limit), the 'Image' link works fine in the Identify Features form window, and the images are visualized as expected. It is only here in the Report view that it seems to be getting jammed somehow.

Edit: here is a link to 5 screenshots showing 1)How the image is linked to the field; 2)Correct display of the image via the "Identify features" tool; 3)How the image source is selected for the report; 4)The way the image object displays in the report; and 5)The error message when attempting to export to PDF.

Best Answer

The issue is functionally solved for my case. Here are some things I had to do in order for it to work:

  1. I created an Atlas, rather than a Report;
  2. I inserted an image, rather than a label or an html object (two suggested alternatives);
  3. I sourced the image simply by naming the field in the expression editor, rather than selecting the field from the data-defined value menu, or using a more complex expression (the full file path seems not to be necessary);
  4. Also, when setting the parameters in the Attributes form menu, I had to make sure that the file path was absolute (not relative) and that the file was a JPG (and not a PNG).
Related Question