public void ProcessKeyPress(KeyEventArgs e) { if (false) { } else if (Key.P == e.Key) { PDFAnnotation pdf_annotation = pdf_annotation_node_content.PDFAnnotation.Underlying; PDFDocument pdf_document = pdf_annotation_node_content.PDFDocument.Underlying; int target_resolution = 150; int actual_resolution = target_resolution; double resolution_rescale_factor = 1; Image annotation_image = PDFAnnotationToImageRenderer.RenderAnnotation(pdf_document, pdf_annotation, actual_resolution); BitmapSource cropped_image_page = BitmapImageTools.FromImage(annotation_image, (int)(annotation_image.Width * resolution_rescale_factor), (int)(annotation_image.Height * resolution_rescale_factor)); ImageIcon.Source = cropped_image_page; ImageIcon.Width = cropped_image_page.Width / 2; TextText.MaxWidth = ImageIcon.Width; e.Handled = true; } }
private void UpdateLibraryStatistics_Headers() { TextLibraryCount.Text = ""; PanelForHyperlinks.Visibility = Visibility.Collapsed; PanelForget.Visibility = Visibility.Collapsed; PanelLocateSyncPoint.Visibility = Visibility.Collapsed; PanelViewOnline.Visibility = Visibility.Collapsed; PanelInviteAndShare.Visibility = Visibility.Collapsed; PanelEditDelete.Visibility = Visibility.Collapsed; PanelTopUp.Visibility = Visibility.Collapsed; PanelPurge.Visibility = Visibility.Collapsed; ButtonAutoSync.Visibility = Visibility.Collapsed; ButtonReadOnly.Visibility = Visibility.Collapsed; if (null != web_library_detail) { TextLibraryCount.Text = String.Format("{0} document(s) in this library", web_library_detail.library.PDFDocuments_IncludingDeleted_Count); //TextLibraryCount.Text = // String.Format( // " ({0} documents, last synced on {1})", // web_library_detail.library.PDFDocuments.Count, // web_library_detail.LastSynced.HasValue ? web_library_detail.LastSynced.Value.ToString() : "Never" // ); // The wizard stuff if (web_library_detail.IsLocalGuestLibrary) { WizardDPs.SetPointOfInterest(ButtonIcon, "GuestLibraryOpenButton"); WizardDPs.SetPointOfInterest(TxtTitle, "GuestLibraryTitle"); } // The icon stuff { RenderOptions.SetBitmapScalingMode(ButtonIcon, BitmapScalingMode.HighQuality); ButtonIcon.Width = 64; ButtonIcon.Height = 64; if (web_library_detail.IsWebLibrary) { ButtonIcon.Source = Icons.GetAppIcon(Icons.LibraryTypeWeb); ButtonIcon.ToolTip = "This is a Web Library.\nYou can sync it via the cloud to access it online or on your other devices."; } else if (web_library_detail.IsIntranetLibrary) { ButtonIcon.Source = Icons.GetAppIcon(Icons.LibraryTypeIntranet); ButtonIcon.ToolTip = "This is an Intranet Library.\nYou can sync it via your Intranet to share with colleagues and across your company computers."; } else if (web_library_detail.IsLocalGuestLibrary) { ButtonIcon.Source = Icons.GetAppIcon(Icons.LibraryTypeGuest); ButtonIcon.ToolTip = "This is a Guest Library.\nIts contents remain local to this computer and can not be synced."; } else if (web_library_detail.IsBundleLibrary) { ButtonIcon.Source = Icons.GetAppIcon(Icons.LibraryTypeBundle); ButtonIcon.ToolTip = "This is a Bundle Library.\nIt's contents will be updated automatically when the Bundle is updates by it's administrator."; } else { ButtonIcon.Source = null; ButtonIcon.ToolTip = null; } } // The customization images stuff { string image_filename = CustomBackgroundFilename; if (File.Exists(image_filename)) { try { ObjTitleImage.Source = BitmapImageTools.FromImage(ImageLoader.Load(image_filename)); } catch (Exception ex) { Logging.Warn(ex, "Problem with custom library background."); } } else { ObjTitleImage.Source = null; } } { string image_filename = CustomIconFilename; if (File.Exists(image_filename)) { try { ButtonIcon.Source = BitmapImageTools.FromImage(ImageLoader.Load(image_filename)); } catch (Exception ex) { Logging.Warn(ex, "Problem with custom library icon."); } } } // The autosync stuff if (web_library_detail.IsWebLibrary || web_library_detail.IsIntranetLibrary) { ButtonAutoSync.Visibility = Visibility.Visible; ButtonAutoSync.IsChecked = web_library_detail.AutoSync; } // The readonly stuff if (web_library_detail.IsReadOnly) { ButtonReadOnly.Visibility = Visibility.Visible; } // The hyperlinks panel if (web_library_detail.IsWebLibrary) { PanelForHyperlinks.Visibility = Visibility.Visible; PanelViewOnline.Visibility = Visibility.Visible; PanelTopUp.Visibility = Visibility.Visible; if (web_library_detail.IsAdministrator) { PanelInviteAndShare.Visibility = Visibility.Visible; PanelEditDelete.Visibility = Visibility.Visible; } if (web_library_detail.Deleted) { PanelPurge.Visibility = Visibility.Visible; } } if (web_library_detail.IsIntranetLibrary) { PanelForHyperlinks.Visibility = Visibility.Visible; PanelForget.Visibility = Visibility.Visible; PanelLocateSyncPoint.Visibility = Visibility.Visible; } if (web_library_detail.IsBundleLibrary) { PanelForHyperlinks.Visibility = Visibility.Visible; PanelForget.Visibility = Visibility.Visible; } } }
private static void BackgroundRenderImages_BACKGROUND(FlowDocument flow_document, List <AnnotationWorkGenerator.AnnotationWork> annotation_works, AnnotationReportOptions annotation_report_options) { Thread.Sleep(annotation_report_options.InitialRenderDelayMilliseconds); PDFDocument last_pdf_document = null; StatusManager.Instance.ClearCancelled("AnnotationReportBackground"); for (int j = 0; j < annotation_works.Count; ++j) { StatusManager.Instance.UpdateStatus("AnnotationReportBackground", "Building annotation report image", j, annotation_works.Count, true); if (StatusManager.Instance.IsCancelled("AnnotationReportBackground")) { Logging.Warn("User cancelled annotation report generation"); break; } AnnotationWorkGenerator.AnnotationWork annotation_work = annotation_works[j]; PDFDocument pdf_document = annotation_work.pdf_document; // Clear down our previously caches pages if (null != last_pdf_document && last_pdf_document != pdf_document) { if (last_pdf_document.DocumentExists) { last_pdf_document.PDFRenderer.FlushCachedPageRenderings(); } } // Remember this PDF document so we can flush it if necessary last_pdf_document = pdf_document; // Now render each image PDFAnnotation pdf_annotation = annotation_work.pdf_annotation; if (null != pdf_annotation) { try { // Clear the waiting for processing text annotation_work.processing_error.Dispatcher.Invoke(new Action(() => { annotation_work.processing_error.Text = ""; } ), DispatcherPriority.Background); if (pdf_document.DocumentExists) { // Fill in the paragraph text if (null != annotation_work.annotation_paragraph) { annotation_work.processing_error.Dispatcher.Invoke( new Action(() => BuildAnnotationWork_FillAnnotationText(pdf_document, pdf_annotation, annotation_work)), DispatcherPriority.Background); } if (null != annotation_work.report_floater) { annotation_work.processing_error.Dispatcher.Invoke(new Action(() => { try { System.Drawing.Image annotation_image = PDFAnnotationToImageRenderer.RenderAnnotation(pdf_document, pdf_annotation, 80); BitmapSource cropped_image_page = BitmapImageTools.FromImage(annotation_image); annotation_work.report_image.Source = cropped_image_page; annotation_work.report_floater.Width = new FigureLength(cropped_image_page.PixelWidth / 1); } catch (Exception ex) { Logging.Warn(ex, "There was a problem while rendering an annotation."); annotation_work.report_image.Source = Icons.GetAppIcon(Icons.AnnotationReportImageError); annotation_work.processing_error.Text = "There was a problem while rendering this annotation."; } } ), DispatcherPriority.Background); } } else { annotation_work.processing_error.Dispatcher.Invoke(new Action(() => { if (null != annotation_work.report_image) { annotation_work.report_image.Source = Icons.GetAppIcon(Icons.AnnotationReportImageError); } annotation_work.processing_error.Text = "Can't show image: The PDF does not exist locally."; } ), DispatcherPriority.Background); } } catch (Exception ex) { Logging.Error(ex, "There was an error while rendering page {0} for document {1} for the annotation report", pdf_annotation.Page, pdf_annotation.DocumentFingerprint); annotation_work.processing_error.Dispatcher.Invoke(new Action(() => { if (null != annotation_work.report_image) { annotation_work.report_image.Source = Icons.GetAppIcon(Icons.AnnotationReportImageError); } annotation_work.processing_error.Text = "Can't show image: There was an error rendering the metadata image."; } ), DispatcherPriority.Background); } } } // And flush the rendering cache of the last document if (null != last_pdf_document) { if (last_pdf_document.DocumentExists) { last_pdf_document.PDFRenderer.FlushCachedPageRenderings(); } } StatusManager.Instance.ClearStatus("AnnotationReportBackground"); }
public static StandardFlowDocument DoExport(PDFDocument pdf_document) { StandardFlowDocument flow_document = new StandardFlowDocument(); flow_document.Background = Brushes.White; using (AugmentedPdfLoadedDocument doc = new AugmentedPdfLoadedDocument(pdf_document.DocumentPath)) { for (int page = 1; page <= pdf_document.PageCount; ++page) { string msg = $"Exporting page {page}/{pdf_document.PageCountAsString}"; StatusManager.Instance.UpdateStatus("ExportToWord", msg, page, Math.Max(1, pdf_document.PageCount)); try { Logging.Info(msg); // Add the header for the page { Bold bold = new Bold(); bold.Inlines.Add(String.Format("--- Page {0} ---", page)); flow_document.Blocks.Add(new Paragraph(bold)); } StringBuilder sb = new StringBuilder(); WordList words = pdf_document.GetOCRText(page); if (null != words) { Word last_word = null; foreach (Word word in words) { // Add a newline if we seem to have a linebreak if ( ( (null != last_word && last_word.Left > word.Left) && (word.Top > last_word.Top + 2 * last_word.Height) && (word.Text.Length > 0 && !Char.IsLower(word.Text[0])) ) || ( (null != last_word && last_word.Left > word.Left) && (word.Top > last_word.Top + 2.5 * last_word.Height) ) ) { sb.Append("\n\n"); } sb.Append(word.Text); sb.Append(' '); last_word = word; } } else { sb.AppendLine(String.Format("OCR text is not yet ready for page {0}. Please try again in a few minutes.", page)); } // Add the text from the page { Paragraph paragraph = new Paragraph(); paragraph.Inlines.Add(sb.ToString()); flow_document.Blocks.Add(paragraph); } // Add the images from the page PdfPageBase pdf_page = doc.Pages[page - 1]; Image[] images = pdf_page.ExtractImages(); if (null != images) { foreach (Image image in images) { BitmapSource bitmap_source = BitmapImageTools.FromImage(image); System.Windows.Controls.Image image_to_render = new System.Windows.Controls.Image(); image_to_render.Source = bitmap_source; BlockUIContainer image_container = new BlockUIContainer(image_to_render); Figure floater = new Figure(image_container); floater.HorizontalAnchor = FigureHorizontalAnchor.PageLeft; floater.WrapDirection = WrapDirection.None; floater.Width = new FigureLength(image.Width); { Paragraph paragraph = new Paragraph(); paragraph.Inlines.Add(floater); flow_document.Blocks.Add(paragraph); } } } // Add the annotations from the page #if false { Logging.Debug("This PDF has {0} annotations", pdf_page.Annotations.Count); Logging.Debug("The size of the page is {0}", pdf_page.Size); foreach (var annotation in pdf_page.Annotations) { PdfLoadedUriAnnotation uri_annotation = annotation as PdfLoadedUriAnnotation; if (null != uri_annotation) { Logging.Debug("There is a URL to '{0}' with text '{1}' with bounds '{2}'", uri_annotation.Uri, uri_annotation.Bounds, uri_annotation.Text, null); } } } #endif } catch (Exception ex) { Logging.Error(ex, "There was a problem exporting page {0}", page); } } } StatusManager.Instance.UpdateStatus("ExportToWord", "Finished exporting"); return(flow_document); }
private void UpdateLibraryStatistics_Headers() { WPFDoEvents.AssertThisCodeIsRunningInTheUIThread(); TextLibraryCount.Text = ""; PanelForHyperlinks.Visibility = Visibility.Visible; PanelForget.Visibility = Visibility.Collapsed; PanelSetSyncPoint.Visibility = Visibility.Collapsed; PanelLocateSyncPoint.Visibility = Visibility.Collapsed; PanelEdit.Visibility = Visibility.Collapsed; PanelDelete.Visibility = Visibility.Collapsed; PanelPurge.Visibility = Visibility.Collapsed; ButtonAutoSync.Visibility = Visibility.Collapsed; ButtonReadOnly.Visibility = Visibility.Collapsed; ObjTitleImage.Source = null; // Store the web library details WebLibraryDetail web_library_detail = DataContext as WebLibraryDetail; // No need to wait until the library has been completely loaded! drag_to_library_manager.DefaultLibrary = web_library_detail; if (null != web_library_detail) { if (!web_library_detail.IsIntranetLibrary) { TextLibraryCount.Text = String.Format("{0} document(s) in this library", web_library_detail.Xlibrary?.PDFDocuments_IncludingDeleted_Count ?? 0); } else { TextLibraryCount.Text = String.Format("{0} document(s) in this library, {1}", web_library_detail.Xlibrary?.PDFDocuments_IncludingDeleted_Count ?? 0, web_library_detail.LastSynced.HasValue ? $"which was last synced on {web_library_detail.LastSynced.Value}" : @"which has never been synced yet"); } // The wizard stuff if (ConfigurationManager.Instance.ConfigurationRecord.GUI_IsNovice) { WizardDPs.SetPointOfInterest(ButtonIcon, "GuestLibraryOpenButton"); WizardDPs.SetPointOfInterest(TxtTitle, "GuestLibraryTitle"); } // The icon stuff { RenderOptions.SetBitmapScalingMode(ButtonIcon, BitmapScalingMode.HighQuality); ButtonIcon.Width = 64; ButtonIcon.Height = 64; if (web_library_detail.IsIntranetLibrary) { ButtonIcon.Source = Icons.GetAppIcon(Icons.LibraryTypeWeb); //ButtonIcon.Source = Icons.GetAppIcon(Icons.LibraryTypeIntranet); ButtonIcon.ToolTip = "This is an Intranet Library.\nYou can sync it via your Intranet to share with colleagues and across your company computers. Alternatively you can sync to a folder in Cloud Storage such as DropBox, Google Drive or Microsoft OneDrive and anyone with access to that shared folder can sync with your library."; } else if (web_library_detail.IsBundleLibrary) { ButtonIcon.Source = Icons.GetAppIcon(Icons.LibraryTypeBundle); ButtonIcon.ToolTip = "This is a Bundle Library.\nIt's contents will be updated automatically when the Bundle is updated by it's administrator."; } else { ButtonIcon.Source = Icons.GetAppIcon(Icons.LibraryTypeGuest); ButtonIcon.ToolTip = "This is a local Library.\nIts contents are local to this computer. When you assign this library a Sync Point, it can be synchronized with that backup location and possibly shared with other people and machines."; } } // The customization images stuff { string image_filename = CustomBackgroundFilename(); if (File.Exists(image_filename)) { try { ObjTitleImage.Source = BitmapImageTools.FromImage(ImageLoader.Load(image_filename)); } catch (Exception ex) { Logging.Warn(ex, "Problem with custom library background."); } } } { string image_filename = CustomIconFilename(); if (File.Exists(image_filename)) { try { ButtonIcon.Source = BitmapImageTools.FromImage(ImageLoader.Load(image_filename)); } catch (Exception ex) { Logging.Warn(ex, "Problem with custom library icon."); } } } // The autosync stuff if (web_library_detail.IsIntranetLibrary) { ButtonAutoSync.Visibility = Visibility.Visible; ButtonAutoSync.IsChecked = web_library_detail.AutoSync; } // The readonly stuff if (web_library_detail.IsReadOnlyLibrary) { ButtonReadOnly.Visibility = Visibility.Visible; } // The hyperlinks panel PanelEdit.Visibility = Visibility.Visible; PanelDelete.Visibility = Visibility.Visible; PanelForget.Visibility = Visibility.Visible; //PanelSetSyncPoint.Visibility = Visibility.Visible; //PanelLocateSyncPoint.Visibility = Visibility.Visible; PanelEdit.Visibility = Visibility.Visible; PanelDelete.Visibility = Visibility.Visible; //PanelPurge.Visibility = Visibility.Visible; if (web_library_detail.Deleted) { PanelPurge.Visibility = Visibility.Visible; } if (web_library_detail.IsIntranetLibrary) { PanelLocateSyncPoint.Visibility = Visibility.Visible; } if (!web_library_detail.IsReadOnlyLibrary) { PanelSetSyncPoint.Visibility = Visibility.Visible; } } }