Skip to content

DocNetExtended is a small extension library built upon the DocNet library, designed to extract text in a readable order from PDFs

License

Notifications You must be signed in to change notification settings

talrand/DocnetExtended

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DocNetExtended

DocNetExtended is a small extension library built upon the DocNet library, designed to extract text in a readable order from PDFs.

Features

  • Get text
  • Get lines of text
  • Get words
  • Split lines of text into blocks

Usage

Extracting all text

using (var docReader = DocLib.Instance.GetDocReader(pdfFileName, new PageDimensions(2480, 3508)))
{
    using (var pageReader = new OrderedPageTextReader(docReader, 0))
    {
        Console.WriteLine(pageReader.GetTextInReadableOrder());
    }
}

Extracting lines of text

using (var docReader = DocLib.Instance.GetDocReader(pdfFileName, new PageDimensions(2480, 3508)))
{
    using (var pageReader = new OrderedPageTextReader(docReader, 0))
    {
        var textLines = pageReader.GetTextLines();

        foreach (var textLine in textLines)
        {
            Console.WriteLine(textLine.Text);
        }

    }
}

Extracting all words

using (var docReader = DocLib.Instance.GetDocReader(pdfFileName, new PageDimensions(2480, 3508)))
{
    using (var pageReader = new OrderedPageTextReader(docReader, 0))
    {
        var words = pageReader.GetWords();

        foreach (var word in words)
        {
            Console.WriteLine(word.Value);
        }
    }
}

Extracting blocks of text

When extracting text from a PDF, you may only be interested in a certain section of the page.

The GetTextBlocks method will split lines of text into blocks of text by dividing the page width by the block size, and then checking the position of each word to determine which block it should be in.

Note: Blocks are currently calculated per TextLine.

using (var docReader = DocLib.Instance.GetDocReader(pdfFileName, new PageDimensions(2480, 3508)))
{
   using (var pageReader = new OrderedPageTextReader(docReader, 0))
   {
       var textBlocks = pageReader.GetTextBlocks(300);

       foreach (var textBlock in textBlocks)
       {
           Console.WriteLine(textBlock.Text);
       }
   }
}

Disclaimer

Whilst every attempt is made to extract data in the order it appears in the PDF, this is very much a work in progress and may not support the structure of all PDFs.

Credit

This project wouldn't be possible without the work done by the DocNet team

About

DocNetExtended is a small extension library built upon the DocNet library, designed to extract text in a readable order from PDFs

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages