Search code examples
c#pdfpig

CS1501 No overload for method 'GetBlocks'


I am using this code from pdfpig and I am getting the error

CS1501 No overload for method 'GetBlocks'

Code:

using UglyToad.PdfPig;
using UglyToad.PdfPig.Content;
using UglyToad.PdfPig.DocumentLayoutAnalysis.PageSegmenter;
using UglyToad.PdfPig.DocumentLayoutAnalysis.WordExtractor;

using (PdfDocument document = PdfDocument.Open(@"C:\Temp\file.pdf"))
{
    for (var i = 0; i < document.NumberOfPages; i++)
    {
        var page = document.GetPage(i + 1);
        var words = page.GetWords();
        var blocks = DocstrumBoundingBoxes.Instance.GetBlocks(words,
                new DocstrumBoundingBoxes.DocstrumBoundingBoxesOptions()
                {
                    WithinLineBounds = new DocstrumBoundingBoxes.AngleBounds(-45, 45),
                    BetweenLineBounds = new DocstrumBoundingBoxes.AngleBounds(35, 170),
                    BetweenLineMultiplier = 1.5
                });

        foreach (var block in blocks)
        {
            // Do something
        }
    }
}

I referred to the wiki page and the code mentioned is the same under this link Document-Layout-Analysis

How to resolve this error? I know GetBlocks can only take 1 argument, but the advanced case the same code is used:

var blocks = DocstrumBoundingBoxes.Instance.GetBlocks(words,
                new DocstrumBoundingBoxes.DocstrumBoundingBoxesOptions()
                {
                    WithinLineBounds = new DocstrumBoundingBoxes.AngleBounds(-45, 45),
                    BetweenLineBounds = new DocstrumBoundingBoxes.AngleBounds(35, 170),
                    BetweenLineMultiplier = 1.5
                });

Solution

  • The project is still not in the release version, so the API can change, as mentioned in the Migration to 0.1.6 guide:

    In summary methods such as GetWords and GetBlocks taking options arguments have changed to take the options in the class constructor.

    You can try creating an instance and providing it the options instead of using a shared one:

    var boxes = new DocstrumBoundingBoxes(new DocstrumBoundingBoxes.DocstrumBoundingBoxesOptions()
    {
        WithinLineBounds = new DocstrumBoundingBoxes.AngleBounds(-45, 45),
        BetweenLineBounds = new DocstrumBoundingBoxes.AngleBounds(35, 170),
        BetweenLineMultiplier = 1.5
    });
    boxes.GetBlocks(words);