Read PDF text inside a ref Aspose.Pdf.Drawing.Rectangle


#1

Note: I also asked this question here: https://github.com/aspose-free-consulting/projects/issues/8

I have the Aspose.Pdf.Drawing.Rectangle;
Now I want to find text inside that Rectangle.
So, I need a Aspose.Pdf.Rectangle to do that.
How do I convert between them?

I am trying to get both CreateRect() to work correctly. The are not working now.

static Aspose.Pdf.Rectangle CreateRect(Aspose.Pdf.Drawing.Rectangle rectangle, Page page)
{
    var llx = rectangle.Left - (float)page.PageInfo.Margin.Left;
    var lly = page.PageInfo.Height - rectangle.Bottom;
    var urx = rectangle.Left + rectangle.Width;
    var ury = lly - rectangle.Height;
    return new Aspose.Pdf.Rectangle(llx, lly, urx, ury);
}

static Aspose.Pdf.Drawing.Rectangle CreateRect(Aspose.Pdf.Rectangle rectangle, Page page)
{
    var l = (float)rectangle.ToRect().Left;
    var b = (float)page.PageInfo.Height - (float)rectangle.ToRect().Bottom;
    var w = (float)rectangle.ToRect().Width;
    var h = (float)rectangle.ToRect().Height;
    return new Aspose.Pdf.Drawing.Rectangle(l, b, w, h);
}

I am using this to read:

static string Read(Aspose.Pdf.Drawing.Rectangle rectangle, string path)
{
    using (var doc = new Document(path))
    {
        var page = doc.Pages.First();
        var rect = CreateRect(rectangle, page);
        var options = new TextSearchOptions(rect, false);
        var text_absorber = new TextAbsorber(options);
        doc.Pages.First().Accept(text_absorber);
        return text_absorber.Text;
    }
}

Thank you.


#2

@JerryNixon2

Would you kindly share your sample PDF document with us. We will test the scenario in our environment and address it accordingly.


#3

I am using this PDF right now.

sample1.pdf (286.4 KB)


#4

@JerryNixon2

Thanks for sharing sample PDF document.

Would you also share the value of (Aspose.Pdf.Drawing.Rectangle rectangle) so that we can test the code snippet accordingly.