ITextSharp using different X & Y axis orientation for different pdf files?

658 Views Asked by At

I am implementing a functionality in which I scan the bottom right corner of input pdfs and extract the text present their.I have about 100 pdfs, which have 2160*3024 dimensions(Crop Box).And I am using the following code:

Rectangle pagesize = reader.GetCropBox(1);
Rectangle rect = new Rectangle((float)(0.903 * pagesize.Width), (float)(0.91 * pagesize.Height), pagesize.Width, pagesize.Height);

ITextExtractionStrategy strategy;
RenderFilter[] filter = { new RegionTextRenderFilter(rect) };
strategy = new FilteredTextRenderListener(new LocationTextExtractionStrategy(), filter);
string capturedText = PdfTextExtractor.GetTextFromPage(reader, 1, strategy);

The problem is that in some cases this code starts to return text which is in the top left corner of the pdf. I checked the rotation of the pages and the pdfs where this codes works has rotation of 90 and the case where it does not work has rotation 270. So,I wrote the code to change the rotation of page to 90.But even after changing the rotation , it is still giving the text in the top left corner rather than bottom right. I am able to get the bottom right corner text for pdf with 270 rotation using the following code:

Rectangle rect = new Rectangle((float)(0 * pagesize.Width), (float)(0 * pagesize.Height),(float)(pagesize.Width * 0.1),(float)(pagesize.Height * 0.1));
0

There are 0 best solutions below