UglyToad / PdfPig

Read and extract text and other content from PDFs in C# (port of PDFBox)
https://github.com/UglyToad/PdfPig/wiki
Apache License 2.0
1.73k stars 241 forks source link

CS1501 No overload for method 'GetBlocks' #592

Closed sheneeb closed 1 year ago

sheneeb commented 1 year ago

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
        }
    }
}
gurustron commented 1 year ago

See 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);
gurustron commented 1 year ago

P.S. - created a pdfpig tag on SO if anybody in the community would be interested.

sheneeb commented 1 year ago

Thanks , The documentation needs to be updated to reflect this and i think that will happen when the release is final

BobLd commented 1 year ago

Documentation now updated, thanks for pointing that out