Case Study: See how Formable built DOCX redlining with Apryse in two months

Home

All Blogs

Saving Alt Text When Making a PDF/UA Compliant Document

Published November 10, 2026

Updated November 10, 2026

Read time

6 min

email
linkedIn
twitter
link

Saving Alt Text When Making a PDF/UA Compliant Document

Sanity Image

Roger Dunham

Retagging a PDF for PDF/UA compliance can pass automated validation while quietly wiping out the Alt text someone carefully wrote in Word. Acrobat, Xodo PDF Studio, and Nutrient all behave this way, because autoConvert rebuilds the tag tree from scratch. This article shows how to use the Apryse SDK to preserve that work. You’ll see why tag IDs and MCIDs can’t be used to link old and new tags, and how matching images by page location solves the problem.

The six-step Node.js approach extracts the existing Alt text, retags the document, matches old and new image tags by overlap, and copies the Alt text across. You’ll also see how unmatched items are logged for manual review.

Sanity Image

Introduction

Copied to clipboard

In the previous article, we saw how you can use the Apryse SDK to make a document PDF/UA compliant by adding tag information automatically using PDFUA.compliance.autoConvert(inputFile, outputFile).

Overall, that produces a well-structured PDF/UA document (though you should still verify that the PDF is actually accessible, such as with meaningful Alt text and correct reading order).

AutoConvert works by rebuilding the document's structure and generating a new tag tree based on the document contents. That’s useful if the existing tags were wrong, but unhelpful if they were correct since not only were the tags discarded but also any information that they contained such as Alt text.

It’s not just Apryse that does this: Adobe Acrobat, Xodo PDF Studio and Nutrient all do the same.

Blog image

Figure 1: A document created by Nutrient that claims PDF/UA compliance. Not only has the image text been discarded, but a table has incorrectly been detected.

That means that while the generated PDF might pass PDF/UA validation using tools such as PAC or veraPDF, in reality, the meaningless Alt text may make the document inaccessible, even if it passes automated PDF/UA validation.

Generating generic Alt text for an untagged or poorly tagged PDF is understandable. But that would be annoying if the Alt text had already been carefully created (in Microsoft Word for example) before the PDF was created.

This is one place that the Apryse SDK can really help. It is hugely flexible and allows low level access to the contents of the PDF, so you can control exactly what happens when you re-apply tags to a PDF.

In this article, we will see how we can use the SDK to extract the existing Alt text, so that it can be reapplied to the PDF at a later time.

The code is not comprehensive, but provides a valid solution in many situations.

Blog image

Figure 2: The initial document. The Alt text was specified in Microsoft Word and exported to the PDF.

Why Can't You Just Copy Data from the Old Tags to the New Ones?

Copied to clipboard

Under the hood, the link between a tag and the content that it is associated with uses a "Marked Content Identifier" (or MCID).

The process of retagging results in both the object number (which we will call ID) of each tag, and the MCID that links it to the actual content being regenerated. There is no guarantee that this will be the same before and after retagging, so neither the object ID nor the MCID can be used to reliably identify the new tag that relates to a specific image.

Blog image

Figure 3: Retagging rebuilds the structure tree and regenerates MCIDs. Since neither the structure element identifiers nor MCIDs remain stable, they cannot be relied upon to map tags before and after retagging. The image location, however, remains unchanged and can be used for matching.

What will stay constant is the location of the image within the PDF. We can determine that location from the content associated with both the original and regenerated tags, giving us a way to match them.

Retaining the Alt text

Copied to clipboard

We’re going to do that by parsing the “tag tree” (also known as the "Structure Tree" or "StructTree"), finding the image tags then extracting the Alt text from their properties.

The approach we will follow is:

  1. Extract existing Alt text and locations.
  2. Retag the document.
  3. Find the new image tags.
  4. Match old and new image locations.
  5. Copy Alt text into the regenerated tags.

You can get the full code for this from https://github.com/DocRog-maker/autotag.git. The code is not production ready, and contains logging intended to show how it works.

The code was written using Node 24 on a Windows 11 machine, using Apryse SDK v12.0. Similar results should be achieved with other platforms.

Step 1: Extracting the Alt Text from the PDF

Copied to clipboard

In the previous blog we saw how we could parse the tag tree using the Apryse SDK running within the browser. The Apryse SDK can also be used on the server-side.

We can reuse that code here, even though we will now use it on the server to iterate through the original tagged PDF that was exported from Word. When a figure (or image) tag is found, the Alt text is printed.

Blog image

Figure 4: We can see the Alt text that we want to use by parsing the existing tags.

That’s a great start. We can now programmatically extract the existing Alt text.

We could do that for a document that has many images, generate a document that contains just the Alt text, then use that to copy and paste content back into the PDF when we have re-tagged it. That might be a little slow, but at least we wouldn’t need to retype the information.

You could even use the mechanism described in the previous blog to view the location of each tag in the PDF and have a friendly editor into which you could copy text.

Step 2: Get the Tagged Locations

Copied to clipboard

While we have extracted the Alt text from the tags, we can also determine where the content associated with each tag appears in the PDF.

By following the tag's references to the underlying page content, our code determines the page number and bounding rectangle of the tagged content. Together, these give us the location of the image associated with the tag.

This location will give us a way to match an image before and after the document is retagged.

Blog image

Figure 5: We can easily get location information for the tags.

Step 3: Retag the Document

Copied to clipboard

Retagging is simple as we saw in the previous article.

This discards the old tags (but we have already stored the information that we need from them) and will create new tags based on the contents of the PDF.

Step 4: Get the Locations of the New Tags

Copied to clipboard

With the creation of new tags, there will be a new “tag tree.” We can repeat step 2, but this time finding the location of the newly created tags. These tags will also have Alt text, but that is not currently meaningful.

Blog image

Figure 6: After generating new tags, we can walk through the tag tree and find where the image tags are.

Step 5: Match the Locations of the Original and Regenerated Tags

Copied to clipboard

We can use the location of the original and regenerated tags as a way of identifying the matching “before” and “after” tags that relate to a specific image.

We can't use the IDs of the tags, since the tag tree has been rebuilt and the previous IDs won't match the new ones.

For this article, I chose instead to match tags based on their locations, which should not have changed (or at least not have changed much). The current matching algorithm is very simple, ignoring very small graphics and considering that locations having at least an (arbitrary) 85% overlap indicate a match.

A more complex mechanism could be created if this does not work for you.

This code has been tested with PDFs exported from Word where the Alt text has already been specified. For PDFs created by other methods, or where Alt text was added manually, this may not work, since the original document may have tags that do not map one-to-one with the regenerated tags.

Having mapped pairs of before and after tags, the code can then copy the Alt text from the before tag into the regenerated one.

Step 6: Fallback for Any Unmatched Tags

Copied to clipboard

It may not be possible to match before and after tags perfectly. As such, any Alt text that cannot be automatically mapped can be written to a log file (as we did in step 1) and be applied manually as part of the process of reviewing the Alt text throughout the document.

Blog image

Figure 7: When working on a complex document, 61 of the images were correctly matched. Although 8 very small, and 11 very complex graphics were not, and would need to be handled manually (or require updates to the matching algorithm).

Blog image

Figure 8: The final result. The PDF has been retagged, but the Alt text has been kept.

Where Next?

Copied to clipboard

We have only just scratched the surface of what you can achieve with the Apryse SDK. Not only is it providing a solution to a problem that would be tedious (and manually intensive) to resolve with many other tools, it also offers access to a wealth of other functionality such as redaction, document generation, conversion from PDF to Office and so on.

Why not get a trial license and try out the sample for yourself?

Note that if you use a trial license then you may get dummy pages inserted into your final document which will confuse the tag matching algorithm. These dummy pages are not added with a production license.

Wrapping Up

Copied to clipboard

Give this a try in your own app, then bring your questions and discoveries to the Apryse Community, where other developers are working through similar challenges.

Ready to get started?

Sign up for a free trial to begin implementing the Apryse SDK in your application!