private static void Export_Directories_Authors(WebLibraryDetail web_library_detail, string base_path, Dictionary <string, PDFDocumentExportItem> pdf_document_export_items) { WshShell shell = new WshShell(); string authors_base_path = Path.GetFullPath(Path.Combine(base_path, @"authors")); Directory.CreateDirectory(authors_base_path); foreach (var item in pdf_document_export_items.Values) { try { List <NameTools.Name> names = NameTools.SplitAuthors(item.pdf_document.AuthorsCombined); foreach (var name in names) { string author_base_path = Path.GetFullPath(Path.Combine(authors_base_path, name.LastName_Initials)); Directory.CreateDirectory(author_base_path); string filename = Path.GetFullPath(Path.Combine(author_base_path, FileTools.MakeSafeFilename(item.pdf_document.TitleCombined) + ".lnk")); CreateShortcut(shell, item.filename, filename); } } catch (Exception ex) { Logging.Error(ex, "Error creating shortcut for " + item.filename); } } }
public static string MakeExportFilename(PDFDocument pdf_document) { string year = pdf_document.YearCombined; if (year == Constants.UNKNOWN_YEAR) { year = ""; } string authors = ""; List<NameTools.Name> author_names = NameTools.SplitAuthors(pdf_document.AuthorsCombined); if (0 < author_names.Count) { authors = author_names[0].last_name; } string title = pdf_document.TitleCombined; string filename = String.Format("{0}{1} - {2}", authors, year, title); filename = filename.Trim(); filename = FileTools.MakeSafeFilename(filename); filename = filename + ".pdf"; return filename; }
private static void Export_Directories_Authors(Library library, string base_path, Dictionary <string, PDFDocumentExportItem> pdf_document_export_items) { WshShell shell = new WshShell(); string authors_base_path = base_path + @"authors\"; Directory.CreateDirectory(authors_base_path); foreach (var item in pdf_document_export_items.Values) { try { List <NameTools.Name> names = NameTools.SplitAuthors(item.pdf_document.AuthorsCombined, PDFDocument.UNKNOWN_AUTHORS); foreach (var name in names) { string author_base_path = authors_base_path + name.LastName_Initials + @"\"; Directory.CreateDirectory(author_base_path); string filename = author_base_path + FileTools.MakeSafeFilename(item.pdf_document.TitleCombined) + ".lnk"; CreateShortcut(shell, item.filename, filename); } } catch (Exception ex) { Logging.Error(ex, "Error creating shortcut for " + item.filename); } } }
public static bool DoesBibTeXMatchDocument(BibTexItem bibtex_item, PDFDocument pdf_document, out PDFSearchResultSet search_result_set) { try { string authors_string = BibTexTools.GetAuthor(bibtex_item); if (!String.IsNullOrEmpty(authors_string)) { List <NameTools.Name> names = NameTools.SplitAuthors(authors_string, PDFDocument.UNKNOWN_AUTHORS); StringBuilder sb = new StringBuilder(); foreach (NameTools.Name name in names) { sb.AppendFormat("\"{0}\" ", name.last_name); } string names_search_string = sb.ToString(); if (!String.IsNullOrEmpty(names_search_string)) { search_result_set = PDFSearcher.Search(pdf_document, 1, names_search_string, PDFSearcher.MATCH_CONTAINS); if (0 < search_result_set.Count) { return(true); } } } } catch (Exception) { } search_result_set = new PDFSearchResultSet(); return(false); }
public static List <NameTools.Name> GetAuthorsForPDFDocument(PDFDocument pdf_document) { string authors = pdf_document.AuthorsCombined; if (String.IsNullOrEmpty(authors) || Constants.UNKNOWN_AUTHORS == authors) { return(EMPTY_NAMES); } List <NameTools.Name> names = NameTools.SplitAuthors(authors); return(names); }
private static void Export_HTML_Authors(StringBuilder html, Library library, string base_path, Dictionary <string, PDFDocumentExportItem> pdf_document_export_items) { MultiMap <string, PDFDocumentExportItem> items_sliced = new MultiMap <string, PDFDocumentExportItem>(false); foreach (var item in pdf_document_export_items.Values) { List <NameTools.Name> names = NameTools.SplitAuthors(item.pdf_document.AuthorsCombined); foreach (var name in names) { items_sliced.Add(name.LastName_Initials, item); } } Export_HTML_XXX(html, "Authors", items_sliced); }
public static string MakeExportFilename(PDFDocument pdf_document) { string year = pdf_document.YearCombined; if (year == PDFDocument.UNKNOWN_YEAR) { year = ""; } string authors = ""; List <NameTools.Name> author_names = NameTools.SplitAuthors(pdf_document.AuthorsCombined, PDFDocument.UNKNOWN_AUTHORS); if (0 < author_names.Count) { authors = author_names[0].last_name; } int MAX_TITLE_LENGTH = 100; string title = pdf_document.TitleCombined; if (title.Length > MAX_TITLE_LENGTH) { title = title.Substring(0, MAX_TITLE_LENGTH); } string filename = String.Format( "{0}{1} - {2}", authors, year, title, null); filename = filename.Trim(); filename = FileTools.MakeSafeFilename(filename); filename = filename + ".pdf"; return(filename); }
private string CreatePaperTweet() { var pdf_document_bindable = DataContext as AugmentedBindable <PDFDocument>; if (null == pdf_document_bindable) { return(null); } PDFDocument pdf_document = pdf_document_bindable.Underlying; BibTexItem bibtex_item = pdf_document.BibTexItem; if (!BibTexTools.HasTitle(bibtex_item)) { return(null); } if (!BibTexTools.HasAuthor(bibtex_item)) { return(null); } List <NameTools.Name> names = NameTools.SplitAuthors(BibTexTools.GetAuthor(bibtex_item)); if (0 == names.Count) { return(null); } string tweet = String.Format("I'm reading {1}'s '{0}' with @Qiqqa http://qiqqa.com", BibTexTools.GetTitle(bibtex_item), names[0].last_name); if (140 < tweet.Length) { return(null); } return(tweet); }
public PDFReadingControl OpenDocument(PDFDocument pdf_document, int?page, string search_terms, bool open_again) { if (pdf_document.IsVanillaReference) { var dialog = new AssociatePDFWithVanillaReferenceWindow(pdf_document); dialog.ShowDialog(); return(null); } FeatureTrackingManager.Instance.UseFeature( Features.Document_Open, "DocumentFingerprint", pdf_document.Fingerprint, "LibraryId", pdf_document.Library.WebLibraryDetail.Id ); // If the document doesn't exist, check if it has a url bibtex field. If so, prompt to go there to find the doc if (!File.Exists(pdf_document.DocumentPath)) { string URL_FIELD = "url"; if (null != pdf_document.BibTexItem && pdf_document.BibTexItem.ContainsField(URL_FIELD)) { if (MessageBoxes.AskQuestion("You do not have the PDF file associated with this document. However the document metadata has a URL link. Do you want to visit that web page to perhaps download it?")) { string url = pdf_document.BibTexItem[URL_FIELD]; Instance.OpenUrlInBrowser(url); } } else { MessageBoxes.Info("You do not have the PDF file associated with this document. Perhaps you need to sync with your Web/Intranet Library to fetch it?"); } return(null); } // Mark as recently read pdf_document.Library.RecentlyReadManager.AddRecentlyRead(pdf_document); // Add to most recently used pdf_document.DateLastRead = DateTime.UtcNow; pdf_document.Bindable.NotifyPropertyChanged(() => pdf_document.DateLastRead); // Set the opening page, if necessary if (page.HasValue) { pdf_document.PageLastRead = page.Value; } // Cause all pages to be OCRed pdf_document.PDFRenderer.CauseAllPDFPagesToBeOCRed(); // Create a title for the window string title = "PDF " + pdf_document.Fingerprint; { StringBuilder sb = new StringBuilder(); List <NameTools.Name> names = NameTools.SplitAuthors(pdf_document.AuthorsCombined, PDFDocument.UNKNOWN_AUTHORS); if (0 < names.Count && names[0] != NameTools.Name.UNKNOWN_NAME) { sb.Append(names[0].last_name); } if (!String.IsNullOrEmpty(pdf_document.YearCombined)) { sb.Append(pdf_document.YearCombined); } if (!String.IsNullOrEmpty(pdf_document.TitleCombined)) { if (0 < sb.Length) { sb.Append(", "); } sb.Append(pdf_document.TitleCombined); } if (0 < sb.Length) { title = sb.ToString(); } } // Open the window PDFReadingControl pdf_reading_control = null; if (!open_again && main_window.DockingManager.Contains(pdf_document.UniqueId)) { Logging.Info("Activating existing PDF viewer for '{0}' with fingerprint {1}", title, pdf_document.Fingerprint); FrameworkElement fe = main_window.DockingManager.MakeActive(pdf_document.UniqueId); pdf_reading_control = fe as PDFReadingControl; } else { Logging.Info("Opening new PDF viewer for {0}", title); pdf_reading_control = new PDFReadingControl(pdf_document); // Shall we colour the tab header? Color?header_color = pdf_document.Color; main_window.DockingManager.AddContent(pdf_document.UniqueId, title, Icons.GetAppIcon(Icons.ModulePDFViewer), true, true, pdf_reading_control, header_color); } // Select the current search terms if (null != pdf_reading_control) { if (!String.IsNullOrEmpty(search_terms)) { pdf_reading_control.SetSearchKeywords(search_terms); } if (page.HasValue) { pdf_reading_control.SelectPage(page.Value); } } return(pdf_reading_control); }