public void RebuildVisual()
        {
            //Logging.Info("+HighlightsRenderer RebuildVisual() on page {0}", page);

            if (null == pdf_document)
            {
                Source = null;
                return;
            }

            if (double.IsNaN(Width) || double.IsNaN(Height))
            {
                Source = null;
                return;
            }

            // We use a smaller image than necessary as we do not need high resolution to represent the highlights
            double scaled_capped_width  = Math.Min(Width, 300);
            double scaled_capped_height = Height * scaled_capped_width / Width;

            using (Bitmap raster_bitmap = PDFOverlayRenderer.RenderHighlights((int)scaled_capped_width, (int)scaled_capped_height, pdf_document, page))
            {
                Source = BitmapImageTools.FromBitmap(raster_bitmap);
            }

            //Logging.Info("-HighlightsRenderer RebuildVisual() on page {0}", page);
        }
Example #2
0
        private void DisplayThumbnail()
        {
            ImageThumbnail.Source = null;
            TxtAbstract.Text      = "";

            if (null == pdf_document)
            {
                return;
            }

            try
            {
                if (pdf_document.DocumentExists)
                {
                    const double IMAGE_PERCENTAGE = 0.5;

                    using (MemoryStream ms = new MemoryStream(pdf_document.PDFRenderer.GetPageByHeightAsImage(page, ImageThumbnail.Height / IMAGE_PERCENTAGE)))
                    {
                        Bitmap image = (Bitmap)Image.FromStream(ms);
                        PDFOverlayRenderer.RenderAnnotations(image, pdf_document, page, specific_pdf_annotation);
                        PDFOverlayRenderer.RenderHighlights(image, pdf_document, page);
                        PDFOverlayRenderer.RenderInks(image, pdf_document, page);

                        image = image.Clone(new RectangleF {
                            Width = image.Width, Height = (int)Math.Round(image.Height * IMAGE_PERCENTAGE)
                        }, image.PixelFormat);
                        BitmapSource image_page = BitmapImageTools.CreateBitmapSourceFromImage(image);
                        ImageThumbnail.Source = image_page;
                    }
                }
                else
                {
                    string abstract_text = pdf_document.Abstract;
                    if (PDFAbstractExtraction.CANT_LOCATE != abstract_text)
                    {
                        TxtAbstract.Text = abstract_text;
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "There was a problem showing the PDF thumbnail");
            }

            if (null != ImageThumbnail.Source)
            {
                ImageThumbnail.Visibility = Visibility.Visible;
            }
            else
            {
                ImageThumbnail.Visibility = Visibility.Collapsed;
            }
        }
Example #3
0
        public static Image RenderAnnotation(PDFDocument pdf_document, PDFAnnotation pdf_annotation, float dpi)
        {
            Image image = Image.FromStream(new MemoryStream(pdf_document.PDFRenderer.GetPageByDPIAsImage(pdf_annotation.Page, dpi)));

            PDFOverlayRenderer.RenderHighlights(image, pdf_document, pdf_annotation.Page);
            PDFOverlayRenderer.RenderInks(image, pdf_document, pdf_annotation.Page);

            // We rescale in the Drawing.Bitmap world because the WPF world uses so much memory
            Image cropped_image = BitmapImageTools.CropImageRegion(image, pdf_annotation.Left, pdf_annotation.Top, pdf_annotation.Width, pdf_annotation.Height);

            return(cropped_image);
        }
        public static Image RenderAnnotation(PDFDocument pdf_document, PDFAnnotation pdf_annotation, int dpi)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            using (MemoryStream ms = new MemoryStream(pdf_document.GetPageByDPIAsImage(pdf_annotation.Page, dpi)))
            {
                Image image = Image.FromStream(ms);
                PDFOverlayRenderer.RenderHighlights(image, pdf_document, pdf_annotation.Page);
                PDFOverlayRenderer.RenderInks(image, pdf_document, pdf_annotation.Page);

                // We rescale in the Drawing.Bitmap world because the WPF world uses so much memory
                Image cropped_image = BitmapImageTools.CropImageRegion(image, pdf_annotation.Left, pdf_annotation.Top, pdf_annotation.Width, pdf_annotation.Height);
                return(cropped_image);
            }
        }
Example #5
0
        public override DocumentPage GetPage(int page_zero_based)
        {
            // Hackity hack
            WPFDoEvents.DoEvents();

            if (null != last_document_page)
            {
                last_document_page.Dispose();
                last_document_page = null;
            }

            int page = page_from + page_zero_based;

            StatusManager.Instance.UpdateStatus("PDFPrinter", String.Format("Printing page {0} of {1}", page_zero_based + 1, this.PageCount), page_zero_based + 1, this.PageCount, true);

            // Render a page at 300 DPI...
            using (Image image = Image.FromStream(new MemoryStream(pdf_renderer.GetPageByDPIAsImage(page, 300))))
            {
                PDFOverlayRenderer.RenderAnnotations(image, pdf_document, page, null);
                PDFOverlayRenderer.RenderHighlights(image, pdf_document, page);
                PDFOverlayRenderer.RenderInks(image, pdf_document, page);
                BitmapSource image_page = BitmapImageTools.CreateBitmapSourceFromImage(image);
                image_page.Freeze();

                DrawingVisual dv = new DrawingVisual();
                using (DrawingContext dc = dv.RenderOpen())
                {
                    // Rotate the image if its orientation does not match the printer
                    if (
                        page_size.Width < page_size.Height && image_page.Width > image_page.Height ||
                        page_size.Width > page_size.Height && image_page.Width < image_page.Height
                        )
                    {
                        image_page = new TransformedBitmap(image_page, new RotateTransform(90));
                        image_page.Freeze();
                    }

                    dc.DrawImage(image_page, new Rect(0, 0, page_size.Width, page_size.Height));
                }

                ++total_pages_printed;

                last_document_page = new DocumentPage(dv);
                return(last_document_page);
            }
        }
        public void RebuildVisual()
        {
            WPFDoEvents.AssertThisCodeIsRunningInTheUIThread();

            //Logging.Info("+HighlightsRenderer RebuildVisual() on page {0}", page);

            if (null == pdf_document)
            {
                Source = null;
                return;
            }

            if (double.IsNaN(Width) || double.IsNaN(Height))
            {
                Source = null;
                return;
            }

            // We use a smaller image than necessary as we do not need high resolution to represent the highlights
            double scaled_capped_width  = Math.Min(Width, 300);
            double scaled_capped_height = Height * scaled_capped_width / Width;

            SafeThreadPool.QueueUserWorkItem(o =>
            {
                BitmapSource bmp;

                using (Bitmap raster_bitmap = PDFOverlayRenderer.RenderHighlights((int)scaled_capped_width, (int)scaled_capped_height, pdf_document, page))
                {
                    bmp = BitmapImageTools.FromBitmap(raster_bitmap);
                }

                WPFDoEvents.InvokeAsyncInUIThread(() =>
                {
                    Source = bmp;
                });

                //Logging.Info("-HighlightsRenderer RebuildVisual() on page {0}", page);
            });
        }