XImage TrySetAlternativeText returns true, but alt text not present

I am creating a PDF programmatically that includes images that need Alt Text. I am able to add the image to the document, save the document to a memory stream, get the appropriate page and XImage object, call the TrySetAlternativeText method, and have it return true. But when I open the PDF, the alt text on the image is not present.

I have tried converting it to PDF UA 1 prior to saving and running the TrySetAlternativeText and while it does make the PDF tagged, the alt text is still not present.

Is there some other requirement I am missing to make this work?

@trstephenerickson

It sounds like you’re encountering an issue with setting alternative text for images in a PDF document programmatically. Here are some steps and considerations that might help you resolve the issue:

  1. Ensure Proper PDF Version: Make sure that the PDF version you are using supports accessibility features. PDF/UA (PDF Universal Accessibility) is a good choice, but ensure that your PDF library fully supports it.

  2. Check Image Tagging: When you convert to PDF UA, ensure that the images are properly tagged. The TrySetAlternativeText method may return true, but if the image is not tagged correctly, the alt text may not be applied.

  3. Verify the Image Object: After calling TrySetAlternativeText, check the properties of the XImage object to see if the alternative text is indeed set. You might have a method to retrieve the alt text to confirm it was applied.

  4. Use Correct Method: Ensure that you are using the correct method to set the alternative text. Some libraries may have specific methods or properties for setting alt text that need to be used in conjunction with TrySetAlternativeText.

  5. Check PDF Reader Compatibility: Sometimes, the PDF reader you are using to view the document may not display the alt text correctly. Try using different PDF readers or tools that can inspect the PDF structure to verify if the alt text is present.

  6. Library Documentation: Review the documentation of the PDF library you are using. There may be specific requirements or additional steps needed to ensure that alt text is properly set and recognized.

  7. Update Library: If you are using an older version of the PDF library, consider updating to the latest version. There may have been bug fixes or improvements related to accessibility features.

  8. Debugging: If possible, enable logging or debugging in your PDF library to see if there are any warnings or errors when setting the alt text.

  9. Sample Code: If you can, provide a minimal code sample that reproduces the issue. This can help in diagnosing the problem more effectively.

  10. Contact Support: If you continue to have issues, consider reaching out to the support team of the PDF library you are using. They may have encountered similar issues and can provide specific guidance.

By following these steps, you should be able to identify the root cause of the issue and successfully set the alternative text for images in your PDF document.