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); }
private static PageContent generatePageContent( Bitmap bitmap, int top, int bottom, double pageWidth, double PageHeight, PrintCapabilities capabilities ) { FixedPage printDocumentPage = new FixedPage(); printDocumentPage.Width = pageWidth; printDocumentPage.Height = PageHeight; int newImageHeight = bottom - top; Bitmap bmpPage = BitmapImageTools.CropBitmapRegion(bitmap, 0, top, bitmap.Width, newImageHeight); BitmapSource bmpSource = BitmapImageTools.FromBitmap(bmpPage); // Create a new bitmap for the contents of this page Image pageImage = new Image(); pageImage.Source = bmpSource; pageImage.VerticalAlignment = VerticalAlignment.Center; // Place the bitmap on the page printDocumentPage.Children.Add(pageImage); PageContent pageContent = new PageContent(); ((IAddChild)pageContent).AddChild(printDocumentPage); pageImage.Width = capabilities.PageImageableArea.ExtentWidth; pageImage.Height = capabilities.PageImageableArea.ExtentHeight; FixedPage.SetLeft(pageImage, capabilities.PageImageableArea.OriginWidth); FixedPage.SetTop(pageImage, capabilities.PageImageableArea.OriginHeight); return(pageContent); }
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); }); }