Commits

Virgil Dupras  committed a503ab7

Added demo limitations.

  • Participants
  • Parent commits a588e00

Comments (0)

Files changed (2)

     
     PROMPT_NAME = __appname__
     NAME = PROMPT_NAME
+    DEMO_LIMITATION = "will only be able load the 10 first pages of a PDF"
     
     def __init__(self, view):
         Broadcaster.__init__(self)
                 self.notify('file_opened')
                 self.opened_file_label.refresh()
                 self.notify('elements_changed')
+                if self.should_apply_demo_limitation and len(self.pages) == 10:
+                    # Yes, I know, the message is mistakenly displayed when the PDF read contains
+                    # excactly 10 pages, but the alternative is to significantly complicate
+                    # our code only for this case. It's not worth it.
+                    msg = "PdfMasher being in demo mode, only the first 10 pages of the PDF were read."
+                    self.view.show_message(msg)
             else:
                 self.view.show_message("This file is not a PDF.")
     
         path = self.view.query_load_path("Select a PDF to work with", ['pdf'])
         if not path:
             return
+        demo_mode = self.should_apply_demo_limitation
         
         def do(j):
             self.last_file_was_invalid = False
             try:
-                self.pages, self.elements = extract_text_elements_from_pdf(path, j)
+                self.pages, self.elements = extract_text_elements_from_pdf(path, demo_mode, j)
                 self.current_path = path
             except PDFSyntaxError:
                 self.last_file_was_invalid = True
         self.height = height
     
     
-def extract_text_elements_from_pdf(path, j=nulljob):
+def extract_text_elements_from_pdf(path, demo_mode, j=nulljob):
     """Opens a PDF and extract every element that is text based (LTText).
     """
     fp = open(path, 'rb')
     pages = []
     all_elements = []
     enumerated_pages = list(enumerate(doc.get_pages()))
+    if demo_mode:
+        enumerated_pages = enumerated_pages[:10]
     progress_msg = "Reading page %i of %i"
     for pageno, page in j.iter_with_progress(enumerated_pages, progress_msg):
         interpreter.process_page(page)