Exemplo n.º 1
0
        public Bitmap DrawContours(int page, string pathToPdf)
        {
            using (var reader = new PdfReader(pathToPdf))
            {
                var strategy = new TableExtractionStrategy();
                var parser   = new PdfReaderContentParser(reader);
                parser.ProcessContent(page, strategy);
                var size = reader.GetPageSize(page);
                var bmp  = new Bitmap((int)size.Width, (int)size.Height);
                var h    = bmp.Height;
                using (var gp = Graphics.FromImage(bmp))
                {
                    gp.Clear(Color.White);
                    strategy.GetAllInLines().ForEach(l =>
                    {
                        gp.DrawLine(Pens.Black, l.GetStartPoint()[0], h - l.GetStartPoint()[1]
                                    , l.GetEndPoint()[0], h - l.GetEndPoint()[1]);
                    });
                    strategy.GetAllInPoints().ForEach(p =>
                    {
                        gp.DrawEllipse(Pens.Black, p.X - 2, h - p.Y - 2, 4, 4);
                    });
                }

                return(bmp);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Exact table from page
 /// </summary>
 public IEnumerable <string> ExactTables(int page, string pathToPdf)
 {
     using (var reader = new PdfReader(pathToPdf))
     {
         var strategy = new TableExtractionStrategy();
         var parser   = new PdfReaderContentParser(reader);
         parser.ProcessContent(page, strategy);
         foreach (var table in strategy.GetTables())
         {
             yield return(GetSimpleHTMLTable(table));
         }
     }
 }
Exemplo n.º 3
0
        public Bitmap PrintTableSkeletonInPage(int page, string pathToPdf, bool drawAxis = false)
        {
            using (var reader = new PdfReader(pathToPdf))
            {
                var strategy = new TableExtractionStrategy();
                var parser   = new PdfReaderContentParser(reader);
                parser.ProcessContent(page, strategy);
                var size = reader.GetPageSize(page);
                var bmp  = new Bitmap((int)size.Width, (int)size.Height);
                using (var gp = Graphics.FromImage(bmp))
                {
                    gp.Clear(Color.White);
                    //gp.ScaleTransform(1, -1);
                    //gp.TranslateTransform(0, -bmp.Height);
                    var h  = bmp.Height;
                    var ft = new Font("arial", 8);
                    foreach (var line in strategy.Lines)
                    {
                        gp.DrawLine(Pens.Black, line.GetStartPoint()[0], h - line.GetStartPoint()[1], line.GetEndPoint()[0], h - line.GetEndPoint()[1]);
                        if (drawAxis)
                        {
                            gp.DrawString(string.Format("({0},{1})", line.GetStartPoint()[0], h - line.GetStartPoint()[1]), ft, Brushes.Black, new PointF(line.GetStartPoint()[0], h - line.GetStartPoint()[1]));
                            gp.DrawString(string.Format("({0},{1})", line.GetEndPoint()[0], h - line.GetEndPoint()[1]), ft, Brushes.Black, new PointF(line.GetEndPoint()[0], h - line.GetEndPoint()[1]));
                        }
                    }
                    foreach (var rect in strategy.Rects)
                    {
                        gp.DrawRectangle(Pens.Black, rect.Left, h - rect.Top - rect.Height, rect.Width, rect.Height);
                        if (drawAxis)
                        {
                            gp.DrawString(string.Format("({0},{1})", rect.Left, h - rect.Top - rect.Height), ft, Brushes.Red, new PointF(rect.Left, h - rect.Top - rect.Height));
                            gp.DrawString(string.Format("w:{0}", rect.Width), ft, Brushes.Red, new PointF(rect.Left + rect.Width / 2, h - rect.Top - rect.Height));
                            gp.DrawString(string.Format("h:{0}", rect.Height), ft, Brushes.Red, new PointF(rect.Left, h - rect.Top - rect.Height / 2));
                        }
                    }
                }

                return(bmp);
            }
        }