コード例 #1
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;
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        private void UpdateLibraryStatistics_Stats_Background_CoverFlow()
        {
            // The list of recommended items
            DocumentDisplayWorkManager ddwm = new DocumentDisplayWorkManager();
            {
                {
                    int ITEMS_IN_LIST = 5;

                    // Upcoming reading is:
                    //  interrupted
                    //  top priority
                    //  read again
                    //  recently added and no status

                    List <PDFDocument> pdf_documents_all = web_library_detail.library.PDFDocuments;
                    pdf_documents_all.Sort(PDFDocumentListSorters.DateAddedToDatabase);

                    foreach (string reading_stage in new string[] { Choices.ReadingStages_INTERRUPTED, Choices.ReadingStages_TOP_PRIORITY, Choices.ReadingStages_READ_AGAIN })
                    {
                        foreach (PDFDocument pdf_document in pdf_documents_all)
                        {
                            if (!pdf_document.DocumentExists)
                            {
                                continue;
                            }

                            if (pdf_document.ReadingStage == reading_stage)
                            {
                                if (!ddwm.ContainsPDFDocument(pdf_document))
                                {
                                    ddwm.AddDocumentDisplayWork(DocumentDisplayWork.StarburstColor.Pink, reading_stage, pdf_document);

                                    if (ddwm.Count >= ITEMS_IN_LIST)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                {
                    int ITEMS_IN_LIST = 3;

                    // Recently added
                    {
                        List <PDFDocument> pdf_documents = web_library_detail.library.PDFDocuments;
                        pdf_documents.Sort(PDFDocumentListSorters.DateAddedToDatabase);

                        int num_added = 0;
                        foreach (PDFDocument pdf_document in pdf_documents)
                        {
                            if (!pdf_document.DocumentExists)
                            {
                                continue;
                            }

                            if (!ddwm.ContainsPDFDocument(pdf_document))
                            {
                                ddwm.AddDocumentDisplayWork(DocumentDisplayWork.StarburstColor.Green, "Added Recently", pdf_document);

                                if (++num_added >= ITEMS_IN_LIST)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    // Recently read
                    {
                        List <PDFDocument> pdf_documents = web_library_detail.library.PDFDocuments;
                        pdf_documents.Sort(PDFDocumentListSorters.DateLastRead);

                        int num_added = 0;
                        foreach (PDFDocument pdf_document in pdf_documents)
                        {
                            if (!pdf_document.DocumentExists)
                            {
                                continue;
                            }

                            if (!ddwm.ContainsPDFDocument(pdf_document))
                            {
                                ddwm.AddDocumentDisplayWork(DocumentDisplayWork.StarburstColor.Blue, "Read Recently", pdf_document);

                                if (++num_added >= ITEMS_IN_LIST)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }


                // And fill the placeholders
                WPFDoEvents.InvokeInUIThread(() => UpdateLibraryStatistics_Stats_Background_GUI_AddAllPlaceHolders(ddwm.ddws));

                // Now render each document
                using (Font font = new Font("Times New Roman", 11.0f))
                {
                    using (StringFormat string_format = new StringFormat
                    {
                        Alignment = StringAlignment.Center,
                        LineAlignment = StringAlignment.Center
                    })
                    {
                        var color_matrix = new ColorMatrix();
                        color_matrix.Matrix33 = 0.9f;
                        using (var image_attributes = new ImageAttributes())
                        {
                            image_attributes.SetColorMatrix(color_matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                            foreach (DocumentDisplayWork ddw in ddwm.ddws)
                            {
                                try
                                {
                                    using (MemoryStream ms = new MemoryStream(ddw.pdf_document.PDFRenderer.GetPageByHeightAsImage(1, PREVIEW_IMAGE_HEIGHT / PREVIEW_IMAGE_PERCENTAGE)))
                                    {
                                        Bitmap page_bitmap = (Bitmap)System.Drawing.Image.FromStream(ms);
                                        page_bitmap = page_bitmap.Clone(new RectangleF {
                                            Width = page_bitmap.Width, Height = (int)Math.Round(page_bitmap.Height * PREVIEW_IMAGE_PERCENTAGE)
                                        }, page_bitmap.PixelFormat);

                                        using (Graphics g = Graphics.FromImage(page_bitmap))
                                        {
                                            int CENTER = 60;
                                            int RADIUS = 60;

                                            {
                                                BitmapImage starburst_bi = null;
                                                switch (ddw.starburst_color)
                                                {
                                                case DocumentDisplayWork.StarburstColor.Blue:
                                                    starburst_bi = Icons.GetAppIcon(Icons.PageCornerBlue);
                                                    break;

                                                case DocumentDisplayWork.StarburstColor.Green:
                                                    starburst_bi = Icons.GetAppIcon(Icons.PageCornerGreen);
                                                    break;

                                                case DocumentDisplayWork.StarburstColor.Pink:
                                                    starburst_bi = Icons.GetAppIcon(Icons.PageCornerPink);
                                                    break;

                                                default:
                                                    starburst_bi = Icons.GetAppIcon(Icons.PageCornerOrange);
                                                    break;
                                                }

                                                Bitmap starburst_image = BitmapImageTools.ConvertBitmapSourceToBitmap(starburst_bi);
                                                g.SmoothingMode = SmoothingMode.AntiAlias;
                                                g.DrawImage(
                                                    starburst_image,
                                                    new Rectangle(CENTER - RADIUS, CENTER - RADIUS, 2 * RADIUS, 2 * RADIUS),
                                                    0,
                                                    0,
                                                    starburst_image.Width,
                                                    starburst_image.Height,
                                                    GraphicsUnit.Pixel,
                                                    image_attributes
                                                    );
                                            }

                                            using (Matrix mat = new Matrix())
                                            {
                                                mat.RotateAt(-50, new PointF(CENTER / 2, CENTER / 2));
                                                g.Transform = mat;

                                                string wrapped_caption = ddw.starburst_caption;
                                                wrapped_caption = wrapped_caption.ToLower();
                                                wrapped_caption = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(wrapped_caption);
                                                wrapped_caption = wrapped_caption.Replace(" ", "\n");
                                                g.DrawString(wrapped_caption, font, Brushes.Black, new PointF(CENTER / 2, CENTER / 2), string_format);
                                            }
                                        }

                                        BitmapSource page_bitmap_source = BitmapImageTools.CreateBitmapSourceFromImage(page_bitmap);

                                        ddw.page_bitmap_source = page_bitmap_source;
                                    }

                                    WPFDoEvents.InvokeInUIThread(() => UpdateLibraryStatistics_Stats_Background_GUI_FillPlaceHolder(ddw));
                                }
                                catch (Exception ex)
                                {
                                    Logging.Warn(ex, "There was a problem loading a preview image for document {0}", ddw.pdf_document.Fingerprint);
                                }
                            }
                        }
                    }
                }

                if (0 == ddwm.ddws.Count)
                {
                    WPFDoEvents.InvokeAsyncInUIThread(() =>
                    {
                        ButtonCoverFlow.IsChecked = false;
                        UpdateLibraryStatistics();
                    }
                                                      );
                }
            }
        }