title: Tagged PDF with PDFBox
body: <p>Is it possible to create tagged PDF(PDF/UA) with PDFBox? It looks like PDFBox has an API for that (package <code>org.apache.pdfbox.pdmodel.documentinterchange.taggedpdf</code>), but I can't find any tutorials or code examples.</p>
  
  <p>Using the code below, I generated a PDF file containing an image, and the screen reader NVDA (in my case) recognizes it and reads '... graphic Alternate Description'. However, the accessibility checker <a href="http://access-for-all.ch/en/pdf-lab/pdf-accessibility-checker-pac.html" rel="nofollow">PAC 2</a> shows an error: 'Image object not tagged'.</p>
  
  <pre><code>        PDDocument doc = new PDDocument();
          PDPage page = new PDPage();
          doc.addPage(page);
          PDDocumentCatalog documentCatalog = doc.getDocumentCatalog();
  
          PDImageXObject pdImage = PDImageXObject.createFromFile(imagePath, doc);
          PDPageContentStream contents = new PDPageContentStream(doc, page);
          contents.drawImage(pdImage, 100, 600, pdImage.getWidth() / 2, pdImage.getHeight() / 2);
          contents.close();
  
          PDStructureTreeRoot treeRoot = new PDStructureTreeRoot();
          PDStructureElement structureElement = new PDStructureElement(StandardStructureTypes.Figure, treeRoot);
          structureElement.setPage(page);
  
          PDMarkedContent markedImg = new PDMarkedContent(COSName.IMAGE, new COSDictionary());
          markedImg.addXObject(pdImage);
  
          structureElement.appendKid(markedImg);
          structureElement.setAlternateDescription("Alternate Description");
          treeRoot.appendKid(structureElement);
          documentCatalog.setStructureTreeRoot(treeRoot);
          // ....
          doc.save(fileName);
  </code></pre>
  
  <p>Can you provide some explanations or/and code examples about this subject? </p>