iTextSharp.text.pdf.parser.PdfContentStreamProcessor.ProcessContent C# (CSharp) Method

ProcessContent() public method

public ProcessContent ( byte contentBytes, PdfDictionary resources ) : void
contentBytes byte
resources PdfDictionary
return void
        public void ProcessContent(byte[] contentBytes, PdfDictionary resources)
        {
            this.resources.Push(resources);
            PRTokeniser tokeniser = new PRTokeniser(contentBytes);
            PdfContentParser ps = new PdfContentParser(tokeniser);
            List<PdfObject> operands = new List<PdfObject>();
            while (ps.Parse(operands).Count > 0){
                PdfLiteral oper = (PdfLiteral)operands[operands.Count-1];
                if ("BI".Equals(oper.ToString())){
                    // we don't call invokeOperator for embedded images - this is one area of the PDF spec that is particularly nasty and inconsistent
                    PdfDictionary colorSpaceDic = resources != null ? resources.GetAsDict(PdfName.COLORSPACE) : null;
                    ImageRenderInfo renderInfo = ImageRenderInfo.CreateForEmbeddedImage(Gs().ctm, InlineImageUtils.ParseInlineImage(ps, colorSpaceDic), colorSpaceDic);
                    renderListener.RenderImage(renderInfo);
                } else {
                    InvokeOperator(oper, operands);
                }
            }
            this.resources.Pop();
        }

Usage Example

        /**
         * Put all data from given day into given table
         */
        public static void collectDataforDay(DateTime dateTime, SQLiteConnection m_dbConnection)
        {
            string zeroMonth = dateTime.Month < 10 ? "0" : "";
              string zeroDay = dateTime.Day < 10 ? "0" : "";
              string date = zeroMonth + dateTime.Month + "/" + zeroDay + dateTime.Day + "/" + dateTime.Year;

              PdfReader reader;
              try
              {
            reader = new PdfReader("http://www.equibase.com/premium/eqbPDFChartPlus.cfm?RACE=A&BorP=P&TID=SAR&CTRY=USA&DT=" + date + "&DAY=D&STYLE=EQB");
              }
              catch (Exception e)
              {
            Console.WriteLine("CAPTCHA TIME");
            Console.ReadKey();
            Console.ReadKey();

            reader = new PdfReader("http://www.equibase.com/premium/eqbPDFChartPlus.cfm?RACE=A&BorP=P&TID=SAR&CTRY=USA&DT=" + date + "&DAY=D&STYLE=EQB");
              }
              StringBuilder builder = new StringBuilder();

              for (int x = 1; x <= reader.NumberOfPages; x++)
              {
            PdfDictionary page = reader.GetPageN(x);
            IRenderListener listener = new SBTextRenderer(builder);
            PdfContentStreamProcessor processor = new PdfContentStreamProcessor(listener);
            PdfDictionary pageDic = reader.GetPageN(x);
            PdfDictionary resourcesDic = pageDic.GetAsDict(PdfName.RESOURCES);
            processor.ProcessContent(ContentByteUtils.GetContentBytesForPage(reader, x), resourcesDic);
              }

              if (pages.Count != 0)
              {

            DataHandler handler = new DataHandler(dateTime, pages, m_dbConnection);
            Thread thread = new Thread(new ThreadStart(handler.extractPdfData));

            thread.Start();
            thread.Join();
            reader.Dispose();
            pages.Clear();
              }
              else
              {
            // If there were no races on this particular day, simply skip it! :D
            Console.WriteLine("Invalid Date: " + date);
              }
        }
All Usage Examples Of iTextSharp.text.pdf.parser.PdfContentStreamProcessor::ProcessContent