Read PDF tags

This code sample enumerates the tags in an existing PDF document.

static private void EnumTagStructure(Tag tag, int depth)
{
  Console.WriteLine(new string(' ', 2*depth) + tag.Type);

  foreach (var child in tag.Childs)
  {
     if (child is Tag)
     {
        EnumTagStructure(child as Tag, depth + 1);
     }
  }
}

static void Main(string[] args)
{
  using (FileStream fs = new FileStream(@"..\..\..\InputDocuments\TaggedPDF.pdf", FileMode.Open))
  {
    Document document = new Document(fs);
    EnumTagStructure(document.LogicalStructure.RootTag, 0);
  }
}

This will output the following:

Document
    Part
      P
        Span
        bold
          Span
        Span
        Span
          Span
        Span
        Span
          Span
        Span
        bold
          Span
        Span
    Document
      Figure
        Caption
      P
        H1
        Span
        Div
        Span
        Span
        Div
Download PDFKit.NET 5.0
We will send you a download link
Why do we ask your email address?
We send tips that speed up your evaluation
We let you know about bug fixes
You can always unsubscribe with one click
We never share your address with a 3rd party
Thank you for your download

We have sent an email with a download link. Alternatively, you may want to use the NuGet package manager to install our library.

Nuget ID

Use the NugetID and start right away, or download the package and install it handmatically