コード例 #1
0
        internal static void WriteToDisk(PDFDocument_ThreadUnsafe pdf_document)
        {
            string json = pdf_document.GetHighlightsAsJSON();

            if (!String.IsNullOrEmpty(json))
            {
                pdf_document.Library.LibraryDB.PutString(pdf_document.Fingerprint, PDFDocumentFileLocations.HIGHLIGHTS, json);
            }
        }
コード例 #2
0
        internal static void WriteToDisk(PDFDocument_ThreadUnsafe pdf_document)
        {
            byte[] data = pdf_document.GetInksAsJSON();

            if (null != data)
            {
                pdf_document.Library.LibraryDB.PutBlob(pdf_document.Fingerprint, PDFDocumentFileLocations.INKS, data);
            }
        }
コード例 #3
0
        public static string GetAbstractForDocument(PDFDocument_ThreadUnsafe pdf_document)
        {
            // Try on the first two pages (sometimes there is a cover page)
            for (int page = 1; page <= 3; ++page)
            {
                string result = GetAbstractForDocument(pdf_document, page);
                if (CANT_LOCATE != result)
                {
                    return(result);
                }
            }

            return(CANT_LOCATE);
        }
コード例 #4
0
        internal static void WriteToDisk(PDFDocument_ThreadUnsafe pdf_document, bool force_flush_no_matter_what)
        {
            if (!force_flush_no_matter_what)
            {
                WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();
            }

            byte[] data = pdf_document.GetInksAsJSON();

            if (null != data)
            {
                pdf_document.Library.LibraryDB.PutBlob(pdf_document.Fingerprint, PDFDocumentFileLocations.INKS, data);
            }
        }
コード例 #5
0
        /// <summary>
        /// Gets the password associated with the PDFDocument.  Returns null if there is no associated password.
        /// </summary>
        /// <param name="pdf_document"></param>
        /// <returns></returns>
        public string GetPassword(PDFDocument_ThreadUnsafe pdf_document)
        {
            string fingerprint = pdf_document.Fingerprint;

            if (Passwords.ContainsKey(fingerprint))
            {
                ReversibleEncryption re = new ReversibleEncryption();
                return(re.DecryptString(Passwords[fingerprint]));
            }
            else
            {
                return(null);
            }
        }
コード例 #6
0
        internal static void WriteToDisk(PDFDocument_ThreadUnsafe pdf_document)
        {
            // A little hack to make sure the legacies are updated...
            pdf_document.Tags = pdf_document.Tags;
            pdf_document.DateAddedToDatabase = pdf_document.DateAddedToDatabase;
            pdf_document.DateLastModified    = pdf_document.DateLastModified;
            pdf_document.DateLastRead        = pdf_document.DateLastRead;
            // A little hack to make sure the legacies are updated...

            string json = pdf_document.GetAttributesAsJSON();

            pdf_document.Library.LibraryDB.PutString(pdf_document.Fingerprint, PDFDocumentFileLocations.METADATA, json);
            Logging.Debug("Update metadata DB for PDF document {1}: JSON =\n{0}", json, pdf_document.Fingerprint);
        }
コード例 #7
0
        internal static void WriteToDisk(PDFDocument_ThreadUnsafe pdf_document, bool force_flush_no_matter_what)
        {
            if (!force_flush_no_matter_what)
            {
                WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();
            }

            string json = pdf_document.GetAnnotationsAsJSON();

            if (!String.IsNullOrEmpty(json))
            {
                pdf_document.Library.LibraryDB.PutString(pdf_document.Fingerprint, PDFDocumentFileLocations.ANNOTATIONS, json);
            }
        }
コード例 #8
0
        internal static void ReadFromStream(PDFDocument_ThreadUnsafe pdf_document, PDFHightlightList highlights, Dictionary <string, byte[]> /* can be null */ library_items_highlights_cache)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            byte[] highlights_data = null;

            if (null != library_items_highlights_cache)
            {
                library_items_highlights_cache.TryGetValue(pdf_document.Fingerprint, out highlights_data);
            }
            else
            {
                List <LibraryDB.LibraryItem> library_items = pdf_document.Library.LibraryDB.GetLibraryItems(pdf_document.Fingerprint, PDFDocumentFileLocations.HIGHLIGHTS);
                if (0 < library_items.Count)
                {
                    highlights_data = library_items[0].data;
                }
            }

            if (null != highlights_data)
            {
                try
                {
                    List <PDFHighlight> highlights_list = null;

                    // First try normal
                    try
                    {
                        highlights_list = ReadFromStream_JSON(highlights_data);
                    }
                    catch (Exception)
                    {
                        highlights_list = ReadFromStream_PROTOBUF(highlights_data);
                        FeatureTrackingManager.Instance.UseFeature(Features.Legacy_Highlights_ProtoBuf);
                    }

                    if (null != highlights_list)
                    {
                        foreach (PDFHighlight highlight in highlights_list)
                        {
                            highlights.AddUpdatedHighlight(highlight);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "There was a problem loading the Highlights for document {0}", pdf_document.Fingerprint);
                }
            }
        }
コード例 #9
0
        // ------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Associates a password with the PDFDocument.
        /// Pass in numm or empty string to clear the password.
        /// </summary>
        /// <param name="pdf_document"></param>
        /// <param name="password"></param>
        public void AddPassword(PDFDocument_ThreadUnsafe pdf_document, string password)
        {
            if (null == pdf_document)
            {
                Logging.Warn("Can't associate a password with a null PDFDocument.");
            }

            if (String.IsNullOrEmpty(password))
            {
                RemovePassword(pdf_document);
            }
            else
            {
                ReversibleEncryption re = new ReversibleEncryption();
                Passwords[pdf_document.Fingerprint] = re.EncryptString(password);
                WritePasswordFile(Filename_Store, Passwords);
            }
        }
コード例 #10
0
        internal static void WriteToDisk(PDFDocument_ThreadUnsafe pdf_document, bool force_flush_no_matter_what)
        {
            if (!force_flush_no_matter_what)
            {
                WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();
            }

            // A little hack to make sure the legacies are updated...
            pdf_document.Tags = pdf_document.Tags;
            pdf_document.DateAddedToDatabase = pdf_document.DateAddedToDatabase;
            pdf_document.DateLastModified    = pdf_document.DateLastModified;
            pdf_document.DateLastRead        = pdf_document.DateLastRead;
            // A little hack to make sure the legacies are updated...

            string json = pdf_document.GetAttributesAsJSON();

            pdf_document.Library.LibraryDB.PutString(pdf_document.Fingerprint, PDFDocumentFileLocations.METADATA, json);
            Logging.Debug("Update metadata DB for PDF document {1}: JSON =\n{0}", json, pdf_document.Fingerprint);
        }
コード例 #11
0
        internal static void ReadFromDisk(PDFDocument_ThreadUnsafe pdf_document, ref PDFAnnotationList annotations, Dictionary <string, byte[]> library_items_annotations_cache)
        {
            byte[] annotations_data = null;

            // Try the cache
            if (null != library_items_annotations_cache)
            {
                library_items_annotations_cache.TryGetValue(pdf_document.Fingerprint, out annotations_data);
            }
            else // Try to load the annotations from file if they exist
            {
                var items = pdf_document.Library.LibraryDB.GetLibraryItems(pdf_document.Fingerprint, PDFDocumentFileLocations.ANNOTATIONS);
                if (0 < items.Count)
                {
                    annotations_data = items[0].data;
                }
            }

            // If we actually have some annotations, load them
            if (null != annotations_data)
            {
                List <DictionaryBasedObject> annotation_dictionaries = null;
                try
                {
                    annotation_dictionaries = ReadFromStream_JSON(annotations_data);
                }
                catch (Exception)
                {
                    annotation_dictionaries = ReadFromStream_BINARY(annotations_data);
                }

                if (null != annotation_dictionaries)
                {
                    foreach (DictionaryBasedObject annotation_dictionary in annotation_dictionaries)
                    {
                        PDFAnnotation pdf_annotation = new PDFAnnotation(annotation_dictionary, false);
                        annotations.AddUpdatedAnnotation(pdf_annotation);
                    }
                }
            }
        }
コード例 #12
0
        internal static void ReadFromDisk(PDFDocument_ThreadUnsafe pdf_document, PDFInkList inks, Dictionary <string, byte[]> library_items_inks_cache)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            try
            {
                byte[] inks_data = null;
                if (null != library_items_inks_cache)
                {
                    library_items_inks_cache.TryGetValue(pdf_document.Fingerprint, out inks_data);
                }
                else
                {
                    List <LibraryDB.LibraryItem> library_items = pdf_document.Library.LibraryDB.GetLibraryItems(pdf_document.Fingerprint, PDFDocumentFileLocations.INKS);
                    if (0 < library_items.Count)
                    {
                        inks_data = library_items[0].data;
                    }
                }

                if (null != inks_data)
                {
                    Dictionary <int, byte[]> page_ink_blobs = SerializeFile.ProtoLoadFromByteArray <Dictionary <int, byte[]> >(inks_data);

                    if (null != page_ink_blobs)
                    {
                        foreach (var pair in page_ink_blobs)
                        {
                            inks.AddPageInkBlob(pair.Key, pair.Value);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "There was a problem loading the Inks for document {0}", pdf_document.Fingerprint);
            }
        }
コード例 #13
0
        private static string GetAbstractForDocument(PDFDocument_ThreadUnsafe pdf_document, int page)
        {
            if (pdf_document.DocumentExists)
            {
                // Get the OCR
                WordList word_list = pdf_document.PDFRenderer.GetOCRText(page);
                if (null == word_list)
                {
                    return(CANT_LOCATE);
                }

                // First find all the locations
                int abstract_start = -1;
                int intro_start    = -1;
                int keywords_start = -1;
                int one_start      = -1;

                if (true)
                {
                    for (int i = 0; i < word_list.Count; ++i)
                    {
                        string test_word       = word_list[i].Text;
                        string test_word_lower = test_word.ToLower();

                        if (-1 == abstract_start && test_word_lower.Contains("abstract") && 'A' == test_word[0])
                        {
                            abstract_start = i;
                        }

                        if (-1 == intro_start && test_word_lower.Contains("introduction") && 'I' == test_word[0])
                        {
                            intro_start = i;
                        }

                        if (-1 == keywords_start && test_word_lower.Contains("keywords") && 'K' == test_word[0])
                        {
                            keywords_start = i;
                        }

                        if (-1 == one_start)
                        {
                            if
                            (
                                false ||
                                "1" == test_word_lower ||
                                "1." == test_word_lower ||
                                "1)" == test_word_lower ||
                                "(1)" == test_word_lower
                            )
                            {
                                one_start = i;
                            }
                        }
                    }

                    // Check that the word just before "introduction" isn't the section number 1
                    if (0 < intro_start && word_list[intro_start - 1].Text.ToLower().Contains("1"))
                    {
                        --intro_start;
                    }
                }

                // Look for ABSTRACT and INTRODUCTION and take everything in between...
                if (true)
                {
                    if (-1 != intro_start && -1 != abstract_start && abstract_start < intro_start)
                    {
                        return(BuildFromRange(word_list, abstract_start + 1, intro_start));
                    }
                }

                // If we don't have the word ABSTRACT, but we do have the word INTRODUCTION, run with that...
                if (true)
                {
                    if (-1 != intro_start)
                    {
                        return(BuildFromRange(word_list, 0, intro_start));
                    }
                }

                // Look for ABSTRACT and KEYWORDS and take everything in between...
                if (true)
                {
                    if (-1 != keywords_start && -1 != abstract_start && abstract_start < keywords_start)
                    {
                        return(BuildFromRange(word_list, abstract_start + 1, keywords_start));
                    }
                }

                // If we don't have the word ABSTRACT, but we do have the number 1 appearing somewhere into the page (15 words)
                if (true)
                {
                    if (-1 != one_start && one_start > 15)
                    {
                        return(BuildFromRange(word_list, 0, one_start));
                    }
                }

                // If we do have the word ABSTRACT, just run with it!
                if (true)
                {
                    if (-1 != abstract_start)
                    {
                        return(BuildFromRange(word_list, abstract_start + 1, word_list.Count));
                    }
                }
            }

            // If we get here we have failed...
            return(CANT_LOCATE);
        }
コード例 #14
0
 public void RemovePassword(PDFDocument_ThreadUnsafe pdf_document)
 {
     Passwords.Remove(pdf_document.Fingerprint);
     WritePasswordFile(Filename_Store, Passwords);
 }
コード例 #15
0
 private PDFDocument(LockObject _lock, Library library, DictionaryBasedObject dictionary)
 {
     access_lock = _lock;
     doc         = new PDFDocument_ThreadUnsafe(library, dictionary);
 }
コード例 #16
0
 private PDFDocument(LockObject _lock, Library library)
 {
     access_lock = _lock;
     doc         = new PDFDocument_ThreadUnsafe(library);
 }