Exemplo n.º 1
0
        public static void SaveDesktop()
        {
            List <string> restore_settings = new List <string>();

            // Get the remembrances
            List <FrameworkElement> framework_elements = MainWindowServiceDispatcher.Instance.MainWindow.DockingManager.GetAllFrameworkElements();

            foreach (FrameworkElement framework_element in framework_elements)
            {
                {
                    LibraryControl library_control = framework_element as LibraryControl;
                    if (null != library_control)
                    {
                        Logging.Info("Remembering a library control " + library_control.Library.WebLibraryDetail.Id);
                        restore_settings.Add(String.Format("PDF_LIBRARY,{0}", library_control.Library.WebLibraryDetail.Id));
                    }
                }

                {
                    PDFReadingControl pdf_reading_control = framework_element as PDFReadingControl;
                    if (null != pdf_reading_control)
                    {
                        Logging.Info("Remembering a PDF reader " + pdf_reading_control.PDFRendererControlStats.pdf_document.Fingerprint);
                        restore_settings.Add(String.Format("PDF_DOCUMENT,{0},{1}", pdf_reading_control.PDFRendererControlStats.pdf_document.Library.WebLibraryDetail.Id, pdf_reading_control.PDFRendererControlStats.pdf_document.Fingerprint));
                    }
                }
            }


            // Store the remembrances
            File.WriteAllLines(Filename, restore_settings);
        }
Exemplo n.º 2
0
        private void CleanUp()
        {
            Dispatcher.ShutdownStarted -= Dispatcher_ShutdownStarted;

            pdf_reading_control = null;
            popup = null;
        }
        public JumpToSectionPopup(PDFReadingControl pdf_reading_control, PDFRendererControl pdf_render_control, PDFRendererControlStats pdf_renderer_control_stats)
        {
            InitializeComponent();

            this.pdf_reading_control        = pdf_reading_control;
            this.pdf_render_control         = pdf_render_control;
            this.pdf_renderer_control_stats = pdf_renderer_control_stats;
            this.popup = new AugmentedPopup(this);

            // Add the bit explaining how to use bookmarks
            {
                TextBlock tb = new TextBlock();
                tb.FontWeight = FontWeights.Bold;
                tb.Text       = "Bookmarks:";
                this.Children.Add(tb);
            }

            {
                {
                    MenuItem mi = new MenuItem();
                    mi.Header =
                        ""
                        + "You can create up to 9 bookmarks while reading a PDF by\n"
                        + "holding down CTRL+SHIFT and pressing a number from 1 to 9.";
                    this.Children.Add(mi);
                }
                {
                    MenuItem mi = new MenuItem();
                    mi.Header =
                        ""
                        + "You can later jump to a remembered bookmark by\n"
                        + "holding down CTRL and pressing a number from 1 to 9.";
                    this.Children.Add(mi);
                }
            }

            this.Children.Add(new AugmentedSpacer());

            // Then add the sections
            {
                TextBlock tb = new TextBlock();
                tb.FontWeight = FontWeights.Bold;
                tb.Text       = "Sections:";
                this.Children.Add(tb);
            }

            // First try from the PDF
            {
                BuildPopupFromPDF build_popup_from_pdf = new BuildPopupFromPDF(this);
                build_popup_from_pdf.BuildMenu();
            }

            // If there are not enough bookmarks, go the OCR route
            if (pdf_renderer_control_stats.pdf_document.PDFRenderer.PageCount < 100)
            {
                BuildPopupFromOCR build_popup_from_ocr = new BuildPopupFromOCR(this);
                build_popup_from_ocr.BuildMenu();
            }
        }
Exemplo n.º 4
0
        public JumpToSectionItem(JumpToSectionPopup jtsp, PDFReadingControl pdf_reading_control, string section, int page)
        {
            InitializeComponent();

            this.jtsp = jtsp;
            this.pdf_reading_control = pdf_reading_control;
            this.section             = section;
            this.page = page;

            ButtonSection.Header = section;
            ButtonSection.Click += ButtonSection_Click;
        }
        private void DoConvert(string[] filenames)
        {
            foreach (string filename in filenames)
            {
                Logging.Info("Processing {0}", filename);
                if (DocumentConversion.CanConvert(filename))
                {
                    string pdf_filename = TempFile.GenerateTempFilename("pdf");
                    DocumentConversion.Convert(filename, pdf_filename);

                    if (ObjAddToGuest.IsChecked ?? false)
                    {
                        Application.Current.Dispatcher.Invoke(
                            new Action(() =>
                        {
                            PDFDocument pdf_document = WebLibraryManager.Instance.Library_Guest.AddNewDocumentToLibrary_SYNCHRONOUS(pdf_filename, filename, null, null, null, true, false);
                            PDFReadingControl pdf_reading_control = MainWindowServiceDispatcher.Instance.OpenDocument(pdf_document);
                            pdf_reading_control.EnableGuestMoveNotification();
                        }),
                            DispatcherPriority.Background);
                    }

                    if (ObjPromptToSave.IsChecked ?? false)
                    {
                        string recommended_filename = TempFile.GenerateTempFilename("pdf");

                        SaveFileDialog save_file_dialog = new SaveFileDialog();
                        save_file_dialog.AddExtension     = true;
                        save_file_dialog.CheckPathExists  = true;
                        save_file_dialog.DereferenceLinks = true;
                        save_file_dialog.OverwritePrompt  = true;
                        save_file_dialog.ValidateNames    = true;
                        save_file_dialog.DefaultExt       = "pdf";
                        save_file_dialog.Filter           = "PDF files (*.pdf)|*.pdf|All files (*.*)|*.*";
                        save_file_dialog.FileName         = recommended_filename;

                        if (true == save_file_dialog.ShowDialog())
                        {
                            string target_filename = save_file_dialog.FileName;
                            File.Copy(pdf_filename, target_filename);
                        }
                    }

                    File.Delete(pdf_filename);
                }
                else
                {
                    StatusManager.Instance.UpdateStatus("DOC_CONV", String.Format("Unable to convert a file of type {0}", Path.GetExtension(filename)));
                }
            }
        }
Exemplo n.º 6
0
        void streamListener_Completed(object sender, EventArgs e)
        {
            try
            {
                StreamListenerTee stream_listener_tee = (StreamListenerTee)sender;

                byte[] captured_data = stream_listener_tee.GetCapturedData();
                if (0 == captured_data.Length)
                {
                    if (!have_notified_about_installing_acrobat)
                    {
                        have_notified_about_installing_acrobat = true;

                        NotificationManager.Instance.AddPendingNotification(
                            new NotificationManager.Notification(
                                "We notice that your PDF files are not loading in your browser.  Please install Acrobat Reader for Qiqqa to be able to automatically add PDFs to your libraries.",
                                "We notice that your PDF files are not loading in your browser.  Please install Acrobat Reader for Qiqqa to be able to automatically add PDFs to your libraries.",
                                NotificationManager.NotificationType.Info,
                                Icons.DocumentTypePdf,
                                "Download",
                                DownloadAndInstallAcrobatReader
                                ));
                    }

                    Logging.Error("We seem to have been notified about a zero-length PDF");
                    return;
                }

                string temp_pdf_filename = TempFile.GenerateTempFilename("pdf");
                File.WriteAllBytes(temp_pdf_filename, captured_data);

                string      pdf_source_url = null; // Can we find this?!!
                PDFDocument pdf_document   = Library.GuestInstance.AddNewDocumentToLibrary_SYNCHRONOUS(temp_pdf_filename, pdf_source_url, null, null, null, true, true);
                File.Delete(temp_pdf_filename);

                Application.Current.Dispatcher.Invoke
                (
                    new Action(() =>
                {
                    PDFReadingControl pdf_reading_control = MainWindowServiceDispatcher.Instance.OpenDocument(pdf_document);
                    pdf_reading_control.EnableGuestMoveNotification(potential_attachment_pdf_document);
                }),
                    DispatcherPriority.Background
                );
            }

            catch (Exception ex)
            {
                Logging.Error(ex, "There was a problem while intercepting the download of a PDF.");
            }
        }
Exemplo n.º 7
0
        public static void TestPDFReadingControl()
        {
            Library library = Library.GuestInstance;

            Thread.Sleep(1000);

            while (!library.LibraryIsLoaded)
            {
                Logging.Info("Waiting for library");
                Thread.Sleep(100);
            }

            PDFDocument          pdf_document        = library.PDFDocuments[0];
            PDFReadingControl    pdf_reading_control = new PDFReadingControl(pdf_document);
            ControlHostingWindow window = new ControlHostingWindow("PDF Reading Control", pdf_reading_control);

            window.Show();
        }
        internal static void GrabWebPage_REMOTE(string title, string url, bool may_try_again_on_exception)
        {
            StatusManager.Instance.UpdateStatus("HTMLToPDF", "Converting HTML to PDF");

            // Strip off the trailing # cos Web2PDF hates is
            if (url.Contains('#'))
            {
                string old_url = url;
                url = url.Substring(0, url.IndexOf('#'));
                Logging.Info("Stripping the # off the original, from '{0}' to '{1}'", old_url, url);
            }

            string filename = Path.GetTempFileName() + ".pdf";

            try
            {
                // Spawn the conversion process
                {
                    string user_override_global = "";
                    string user_override_page   = "";

                    string process_parameters = String.Format(
                        "{0} {1} --footer-right \"Page [page] of [topage]\" {2} --footer-left \"{3}\" --header-left \"{4}\" --header-right \"Created using www.qiqqa.com\" \"{5}\""
                        , user_override_global
                        , url
                        , user_override_page
                        , url.Replace('"', '\'')
                        , title.Replace('"', '\'')
                        , filename
                        );

                    // STDOUT/STDERR
                    using (Process process = ProcessSpawning.SpawnChildProcess(ConfigurationManager.Instance.ProgramHTMLToPDF, process_parameters, ProcessPriorityClass.Normal))
                    {
                        using (ProcessOutputReader process_output_reader = new ProcessOutputReader(process))
                        {
                            process.WaitForExit();

                            Logging.Info("HTMLToPDF:\n{0}", process_output_reader.GetOutputsDumpString());
                        }
                    }
                }

                StatusManager.Instance.UpdateStatus("HTMLToPDF", "Converting HTML to PDF: adding to library");
                PDFDocument pdf_document = Library.GuestInstance.AddNewDocumentToLibrary_SYNCHRONOUS(filename, url, url, null, null, null, true, true);
                pdf_document.Title            = title;
                pdf_document.Year             = Convert.ToString(DateTime.Now.Year);
                pdf_document.DownloadLocation = url;

                WPFDoEvents.InvokeInUIThread(() =>
                {
                    PDFReadingControl pdf_reading_control = MainWindowServiceDispatcher.Instance.OpenDocument(pdf_document);
                    pdf_reading_control.EnableGuestMoveNotification();
                },
                                             priority: DispatcherPriority.Background
                                             );
            }
            catch (Exception ex)
            {
                // Give it a 2nd try...
                if (may_try_again_on_exception)
                {
                    GrabWebPage_REMOTE(title, url, false);
                }
                else
                {
                    throw new UsefulTextException("Problem converting HTML page to PDF.  Please try again later.", String.Format("There has been a problem converting this web page '{0}' with title '{1}' to a PDF.", url, title), ex);
                }
            }
            finally
            {
                FileTools.Delete(filename);
            }

            StatusManager.Instance.UpdateStatus("HTMLToPDF", "Converting HTML to PDF: done");
        }
Exemplo n.º 9
0
        public JumpToSectionPopup(PDFReadingControl pdf_reading_control)
        {
            InitializeComponent();

            this.pdf_reading_control = pdf_reading_control;
            popup = new AugmentedPopup(this);

            // Add the bit explaining how to use bookmarks
            {
                TextBlock tb = new TextBlock();
                tb.FontWeight = FontWeights.Bold;
                tb.Text       = "Bookmarks:";
                Children.Add(tb);
            }

            {
                {
                    MenuItem mi = new MenuItem();
                    mi.Header =
                        ""
                        + "You can create up to 9 bookmarks while reading a PDF by\n"
                        + "holding down CTRL+SHIFT and pressing a number from 1 to 9.";
                    Children.Add(mi);
                }
                {
                    MenuItem mi = new MenuItem();
                    mi.Header =
                        ""
                        + "You can later jump to a remembered bookmark by\n"
                        + "holding down CTRL and pressing a number from 1 to 9.";
                    Children.Add(mi);
                }
            }

            Children.Add(new AugmentedSpacer());

            // Then add the sections
            {
                TextBlock tb = new TextBlock();
                tb.FontWeight = FontWeights.Bold;
                tb.Text       = "Sections:";
                Children.Add(tb);
            }

            // If there are not enough bookmarks, go the OCR route
            PDFDocument pdf_document = pdf_reading_control.GetPDFDocument();

            ASSERT.Test(pdf_document != null);

            // First try from the PDF
            if (pdf_document != null)
            {
                BuildPopupFromPDF build_popup_from_pdf = new BuildPopupFromPDF(this, pdf_document);
                build_popup_from_pdf.BuildMenu();
            }

            if (pdf_document != null /* && pdf_document.PDFRenderer.PageCount < 100  -- plenty thesis papers out there with more than 100 pages... removed this arbitrary heuristic */)
            {
                BuildPopupFromOCR build_popup_from_ocr = new BuildPopupFromOCR(this, pdf_document);
                build_popup_from_ocr.BuildMenu();
            }

            //Unloaded += JumpToSectionPopup_Unloaded;
            Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;
        }
 internal void ClosePDFReadingControl(PDFReadingControl pdf_reading_control)
 {
     main_window.DockingManager.CloseContent(pdf_reading_control);
 }
        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);
        }