title: ITextSharp 5.4.5 How can I set an ATL to an image of a document I’m creating from scratch?
body: <p>I’ve recently started evaluating ITextSharp 5.4.5 for use, and have read the IText in Action se book which has covered a large portion of the library.  It’s easy to use, and I’ve seen an uptick in use over the last year by the community, but I’ve run into an issue that I’m hoping someone can address.</p>
  
  <p>How can I set an ATL to an image of a document I’m creating from scratch?</p>
  
  <p>Approach 1 (Create the image and set the Alt property):</p>
  
  <pre><code>    private static void Main(string[] args)
      {
          using (Document doc = new Document(PageSize.A4, 36, 36, 36, 36))
          {
              using (PdfWriter pw = PdfWriter.GetInstance(doc, new FileStream("c:\\ImageTest.pdf", FileMode.Create)))
              {
                  pw.SetTagged();
                  pw.UserProperties = true;
                  doc.Open();
                  Image img = Image.GetInstance(@"c:\images\WA.png");
                  img.Alt = "Alt text for Image!";
                  doc.Add(img);
                  doc.Close();
              }
          }
      }
  </code></pre>
  
  <p>Approach 2 (Create the image and call SetAccessibleAttribute):</p>
  
  <pre><code>    private static void Main(string[] args)
      {
          using (Document doc = new Document(PageSize.A4, 36, 36, 36, 36))
          {
              using (PdfWriter pw = PdfWriter.GetInstance(doc, new FileStream("c:\\ImageTest.pdf", FileMode.Create)))
              {
                  pw.SetTagged();
                  pw.UserProperties = true;
                  doc.Open();
                  Image img = Image.GetInstance(@"c:\images\WA.png");
                  img.SetAccessibleAttribute(PdfName.ALT, new PdfString("Alt text for Image!"));
                  doc.Add(img);
                  doc.Close();
              }
          }
      }
  </code></pre>
  
  <p>Approach 3 (Create the image and use DirectContent.AddImage):</p>
  
  <pre><code>    private static void Main(string[] args)
      {
          using (Document doc = new Document(PageSize.A4, 36, 36, 36, 36))
          {
              using (PdfWriter pw = PdfWriter.GetInstance(doc, new FileStream("c:\\ImageTest.pdf", FileMode.Create)))
              {
                  pw.SetTagged();
                  pw.UserProperties = true;
                  doc.Open();
                  PdfDictionary dict = new PdfDictionary();
                  dict.Put(PdfName.LANG, new PdfString("en-us"));
                  dict.Put(PdfName.ALT, new PdfString("Alt text for Image!"));
                  pw.DirectContent.BeginMarkedContentSequence(PdfName.FIGURE, dict, true);
                  Image img = Image.GetInstance(@"c:\images\WA.png");
                  img.SetAbsolutePosition(36, 592);
                  pw.DirectContent.AddImage(img);
                  pw.DirectContent.EndMarkedContentSequence();
                  pw.Flush();
                  doc.Close();
              }
          }
      }
  </code></pre>
  
  <p>Still no Alt Text is rendered, any guidance would be appreciated.</p>
  
  <p>Thanks.</p>