public void CloseDocument(DocumentClosingEventArgs e) { e.SaveDialogResult = MessageBoxResult.No; e.Handled = true; DictionaryBookmarks.Clear(); SaveRecentFile(CurrentDocumentPath); }
public void SelectDictionaryEntry(PdfAnnotationGotFocusEventArgs e) { if (e.Annotation.Name.StartsWith(DictionaryBookmark.DictionaryEntry)) { DictionaryBookmark bookmark = DictionaryBookmarks.FirstOrDefault(x => x.Name == e.Annotation.Name); if (bookmark != null) { DictionaryBookmarksView.MoveCurrentTo(bookmark); } } }
public void LoadDocument(IPdfDocument document) { ShowDefinitions = true; RecentFile recentFile = RecentFileCollection.FirstOrDefault(x => x.FilePath == CurrentDocumentPath); if (recentFile != null) { if (recentFile.PageNumber > 0) { CurrentPageNumber = recentFile.PageNumber; } if (!String.IsNullOrEmpty(recentFile.InputLanguage)) { InputCulture = new CultureInfo(recentFile.InputLanguage); } if (!String.IsNullOrEmpty(recentFile.InputLanguage)) { OutputCulture = new CultureInfo(recentFile.OutputLanguage); } } foreach (IPdfPage page in document.Pages) { if (page is PdfPageViewModel viewModel) { foreach (PdfAnnotation annotation in viewModel.Page.Annotations) { if (annotation is PdfTextMarkupAnnotation textMarkupAnnotation) { if (textMarkupAnnotation?.Name.StartsWith(DictionaryBookmark.DictionaryEntry) == false) { continue; } DictionaryBookmarks.Add(new DictionaryBookmark { PageNumber = page.PageNumber, Name = textMarkupAnnotation.Name, Word = textMarkupAnnotation.Title, WordClass = textMarkupAnnotation.Subject, Definition = textMarkupAnnotation.Contents }); } } } } }
public void DeleteMarkup(PdfAnnotationDeletingEventArgs e) { if (MessageBoxService.ShowMessage("Do you want to delete selected item?", "Confirm Delete", MessageButton.YesNo, MessageIcon.Question) == MessageResult.No) { e.Cancel = true; return; } DictionaryBookmark bookmark = DictionaryBookmarks.FirstOrDefault(x => x.Name == e.Annotation.Name); if (bookmark != null) { DictionaryBookmarks.Remove(bookmark); } }
public void CreateMarkup(PdfAnnotationCreatingEventArgs e) { if (e.Builder.AnnotationType == PdfAnnotationType.TextMarkup) { IPdfViewerTextMarkupAnnotationBuilder annotationBuilder = e.Builder.AsTextMarkupAnnotationBuilder(); if (String.IsNullOrWhiteSpace(annotationBuilder.SelectedText)) { e.Cancel = true; e.Handled = true; return; } SearchResult[] result = AsyncHelper.RunSync(() => DictionaryManager.Search(annotationBuilder.SelectedText, InputCulture, OutputCulture)); if (result == null || result.Length == 0) { e.Cancel = true; e.Handled = true; return; } annotationBuilder.Name = String.Format("{0}-{1}", DictionaryBookmark.DictionaryEntry, annotationBuilder.Name); annotationBuilder.Author = result[0].Word; annotationBuilder.Subject = result[0].WordClass; annotationBuilder.Contents = result[0].Definition; DictionaryBookmarks.Add(new DictionaryBookmark { PageNumber = annotationBuilder.PageNumber, Name = annotationBuilder.Name, Word = result[0].Word, WordClass = result[0].WordClass, Definition = result[0].Definition }); Cursor.Position = new System.Drawing.Point(Cursor.Position.X - 1, Cursor.Position.Y - 1); } }