예제 #1
0
        public static void TestHarness_TEXT_RENDER_ONE(string PDF_FILENAME, int PAGE)
        {
            SolidColorBrush BRUSH_EDGE       = new SolidColorBrush(Colors.Red);
            SolidColorBrush BRUSH_BACKGROUND = new SolidColorBrush(ColorTools.MakeTransparentColor(Colors.GreenYellow, 64));

            // Load the image graphic
            MemoryStream ms           = RenderPDFPage(PDF_FILENAME, PAGE, 150, null, ProcessPriorityClass.Normal);
            BitmapSource bitmap_image = BitmapImageTools.LoadFromBytes(ms.ToArray());
            Image        image        = new Image();

            image.Source  = bitmap_image;
            image.Stretch = Stretch.Fill;

            // Load the image text
            Canvas           canvas      = new Canvas();
            List <TextChunk> text_chunks = GetEmbeddedText(PDF_FILENAME, "" + PAGE, null, ProcessPriorityClass.Normal);
            List <Rectangle> rectangles  = new List <Rectangle>();

            foreach (TextChunk text_chunk in text_chunks)
            {
                Rectangle rectangle = new Rectangle();
                rectangle.Stroke = BRUSH_EDGE;
                rectangle.Fill   = BRUSH_BACKGROUND;
                rectangle.Tag    = text_chunk;
                rectangles.Add(rectangle);
                canvas.Children.Add(rectangle);
            }

            RectanglesManager rm = new RectanglesManager(rectangles, canvas);

            Grid grid = new Grid();

            grid.Children.Add(image);
            grid.Children.Add(canvas);

            ControlHostingWindow window = new ControlHostingWindow("PDF", grid);

            window.Show();
        }
        void ObjButtonGO_Click(object sender, RoutedEventArgs e)
        {
            int pdf_number  = Convert.ToInt32(ObjTextDoc.Text);
            int page_number = Convert.ToInt32(ObjTextPage.Text);

            string pdf_filename = String.Format(@"C:\temp\{0}.pdf", pdf_number);

            Logging.Info("+Rendering page");
            MemoryStream ms           = MuPDFRenderer.RenderPDFPage(pdf_filename, page_number, 200, null, ProcessPriorityClass.Normal);
            BitmapSource bitmap_image = BitmapImageTools.LoadFromBytes(ms.ToArray());
            Bitmap       bitmap       = new Bitmap(ms);

            Logging.Info("-Rendering page");

            this.Image = bitmap_image;

            Logging.Info("+Finding regions");
            this.region_locator = new PDFRegionLocator(bitmap);
            Logging.Info("-Finding regions");

            Recalc();
        }