最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

itext7 - Add AltText to image Itext 7 version9 - Stack Overflow

programmeradmin0浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 1

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

发布评论

评论列表(0)

  1. 暂无评论