I have a pdf files that have many pages (1000 +) each page as a barcode that needs to be read (bitmap 2D data matrix). This is not a technical problem, I loop through all the image on a page and scan each one until I find the barcode. What I’m faced with is performance issue. Instead of checking every image is there way to get an image base on its location?
Below is how I’m checking the images, I’m checking the location of every image until I get the one in the location of the barcode. This just seems a long way to do it. public class MyImageRenderListener : IRenderListener { public void RenderText(TextRenderInfo renderInfo) { } public void BeginTextBlock() { } public void EndTextBlock() { } public List<byte[]> Images = new List<byte[]>(); // public List<string> ImageNames = new List<string>(); private Boolean doExit = false; public void RenderImage(ImageRenderInfo renderInfo) { PdfImageObject image = renderInfo.GetImage(); try { if (doExit) return; var matrix = renderInfo.GetImageCTM(); float left = matrix[6]; float top = matrix[7]; float width = matrix[0]; float height = matrix[4]; image = renderInfo.GetImage(); if (image == null) return; if (left == 516.0 && top == 18.0) { doExit = true; using (MemoryStream ms = new MemoryStream(image.GetImageAsBytes())) { Images.Add(ms.ToArray()); } } } catch (IOException ie) { /* * pass-through; image type not supported by iText[Sharp]; e.g. jbig2 */ } } } public string BarScanner(int page) { string results = String.Empty; PdfReaderContentParser parser = new PdfReaderContentParser(pdfReader); MyImageRenderListener listener = new MyImageRenderListener(); parser.ProcessContent(page, listener); for (int i = 0; i < listener.Images.Count; ++i) { Stream stream = new MemoryStream(listener.Images[i]); string[] data = BarcodeScanner.Scan(stream/*, BarCodeType.DataMatrix*/); foreach (string bar in data) { //Debug.WriteLine("The scanning result is: {0}.", bar); if (QuickMatch(bar)) { results = bar; break; } } if (results.Length > 0) break; } return results; } -- View this message in context: http://itext-general.2136553.n4.nabble.com/Get-image-by-location-tp4660544.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php