I create a template on QGIS which contains some text and images. I render the image using HTML with code:

.cropped {
    position: absolute;
    width: 27mm; /* width of container */
    height: 27mm;
    background-size: 256px  144px;
    overflow: hidden; 
    border-radius: 50%;
    border: 0px;
    background-position: center top;
    background-color: #eee;
#jpg {    background-image: url('img/[%"photo"%]');

<div class="cropped" id="jpg"></div>

The atlas has more than 10K items, when I tried to export the atlas on the folder, most of the images failed to be print on the PDF export file. But if I tried to add images without HTML, it works good on exporting. But actually I will need HTML styling version to print the atlas. What is the best way to solve this?

1 Answer 1


This is definitely a timing issue of Qt. The PDF generation is faster than the HTML rendering. Whenever I face such problems (missing images in HTML, missing SVGs, partly rendered images, Javascript processing in HTML), I'm using a custom Python "wait" function to pause the printing process.

Put the following Python code in the "Python Macros" section of your project (Project > Properties... > Macros) and enable running macros (Settings > Options > General):

from qgis.core import qgsfunction
from qgis.PyQt.QtCore import QTimer,QEventLoop
@qgsfunction(args=1, group='Custom', usesGeometry=False, referenced_columns=[])
def waitX(values, feature, parent):
    x = values[0]
    loop = QEventLoop()
    return 0

To get the HTML completely rendered, you have to inject this expression function somewhere into the printing process. I always put it into the data defined override of the label or HTML item Rendering exclusion option (Rendering > Exclude item from exports). That's why this function returns "0". You have to play with the function argument to increase or decrease sleeping time depending on the content of your HTML.

enter image description here

  • Hi christoph, thanks for your response. I'm trying to running and add function waitX(300) on rendering options, but the expression was not recognized on string builder windows (Expression is invalid). do you know why?
    – Riska
    Feb 20, 2022 at 7:44
  • You have to reopen your QGIS project after putting the Python code into the Macro section. And take care that running macros is enabled. You will find waitX inside Custom functions.
    – christoph
    Feb 20, 2022 at 7:54
  • Cool, it works now. Now I'm trying to play with this function. Thanks a lot!!!
    – Riska
    Feb 20, 2022 at 8:28
  • If the answer has met your expectations, you should mark it as „accepted“.
    – christoph
    Feb 20, 2022 at 9:26
  • Is there maximum time for the function? I could not add more than 10000, although ```10000```` still not running my atlas successfully
    – Riska
    Feb 20, 2022 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.