How to add AltText to an image using Itext 7 version 9. I found this code snippet on the NET but the SetAltText method does not exist in the version I'm using.
Document document = new Document(pdfDoc);
// Add an image with alt text
Image img = new Image(ImageDataFactory.Create("path/to/image.png"))
.SetRole(StandardRoles.FIGURE)
.SetAltText("Description of the image for accessibility");
document.Add(img);
How to add AltText to an image using Itext 7 version 9. I found this code snippet on the NET but the SetAltText method does not exist in the version I'm using.
Document document = new Document(pdfDoc);
// Add an image with alt text
Image img = new Image(ImageDataFactory.Create("path/to/image.png"))
.SetRole(StandardRoles.FIGURE)
.SetAltText("Description of the image for accessibility");
document.Add(img);
Share
Improve this question
asked Feb 5 at 20:05
Andre RubnikowichAndre Rubnikowich
4751 gold badge4 silver badges11 bronze badges
0
1 Answer
Reset to default 1Your code should be something like:
Document document = new Document(pdfDoc);
iText.Layout.Element.Image img = new Image(ImageDataFactory
.Create("path/to/image.png"));
img.GetAccessibilityProperties()
.SetAlternateDescription("Description of the image for accessibility");
document.Add(img);
you can find an example on the official GitHub repo, and here is the API entry.