Forum How do I...?

How can I debug missing alternative text on images?

ha3441kg
Hi,

I am converting HTML to PDF/UA-1. In my HTML, images have an alternative text using the `alt` attribute on the image.

My HTML:

<figure>
<img src="" alt="text is here" />
</figure>


My CSS :

figure { prince-pdf-tag-type: Div } /* figure grouper */
figcaption { prince-pdf-tag-type: Caption }
img, input[type="image"] {
prince-pdf-tag-type: Figure;
prince-alt-text: attr(alt);
}



For some reason, I get this error “Figure structure element is missing alternative text on page xx”.

How can I debug what's happening? What other thing should I do for my alt attributes to be picked up and used in the PDF as text alternatives for the graphic?
wangp
Can you check which version of Prince you are running, and post a small test case which demonstrates the issue?

I'm unable to reproduce the error message using the attached HTML input; the resulting PDF is also attached.
  1. figure.html0.3 kB
  2. figure.pdf9.4 kB
ha3441kg
Thanks for your response !

I found the issue while creating a minimal test case.

The bit of markup that I shared wasn't the one with the problem, it was an svg element a few lines down. Eventhough it had role="presentation" and aria-hidden="true", the lack of a <title> was a problem. When I added a <title> to the SVG the page reported no problems.

So lesson learned is always make sure there is a text alternative for your SVGs.

If any of Prince devs are reading this: it would have been helpful to me in this case if the error message showed the line that had the problem.

Edited by ha3441kg

wangp
You can consider adding a rule such as:
svg[aria-hidden="true"] {                                                                        
  prince-pdf-tag-type: Artifact;                                                                 
}

markbrown
> If any of Prince devs are reading this: it would have been helpful to me in this case if the error message showed the line that had the problem.

Thanks for the feedback. Line numbers would indeed be useful, though there are technical reasons that make it tricky to provide them in all the cases that we'd like to.