emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/doc-toc 719f6a03a7 64/84: Return page text when pdfxmet


From: ELPA Syncer
Subject: [elpa] externals/doc-toc 719f6a03a7 64/84: Return page text when pdfxmeta fails
Date: Mon, 26 Sep 2022 13:58:39 -0400 (EDT)

branch: externals/doc-toc
commit 719f6a03a7a7f34a8c7a57bd89f1211cb87b31f8
Author: Daniel Nicolai <dalanicolai@gmail.com>
Commit: Daniel Nicolai <dalanicolai@gmail.com>

    Return page text when pdfxmeta fails
---
 README.org  |  3 ++-
 toc-mode.el | 33 ++++++++++++++++++++++++++-------
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/README.org b/README.org
index a80e0ad9a0..e343f59dbd 100644
--- a/README.org
+++ b/README.org
@@ -166,10 +166,11 @@ all-modes (i.e. all steps)
 | ~C-c C-c~     | dispatch (next step) |
 toc-cleanup-mode
 | ~C-c C-j~ | toc-join-next-unnumbered-lines |
+| =C-c C-s= | toc--roman-to-arabic           |
 toc-mode (tablist)
 | ~TAB~            | preview/jump-to-page                                      
           |
 | ~right/left~     | toc-in/decrease-remaining                                 
           |
-| ~C-right/C-left~ | toc-in/decrease-remaining and view page                   
        |
+| ~C-right/C-left~ | toc-in/decrease-remaining and view page                   
           |
 | ~S-right/S-left~ | in/decrease pagenumber current entry                      
           |
 | ~C-down/C-up~    | scroll document other window (only when other buffer 
shows document) |
 | ~S-down/S-up~    | full page scroll document other window ( idem )           
           |
diff --git a/toc-mode.el b/toc-mode.el
index 1f339623f3..bf8cfa3c4c 100644
--- a/toc-mode.el
+++ b/toc-mode.el
@@ -36,8 +36,8 @@
 ;; respectively.
 
 ;; Requirements: To use the pdf.tocgen functionality that software has to be
-;; installed (see URL `https://krasjet.com/voice/pdf.tocgen/'). For the other
-;; remaining functionality the package requires the `pdftotext' (part of
+;; installed (see URL `https://krasjet.com/voice/pdf.tocgen/'). For the
+;; remaining functions the package requires the `pdftotext' (part of
 ;; poppler-utils), `pdfoutline' (part of fntsample) and `djvused' (part of
 ;; http://djvu.sourceforge.net/) command line utilities to be available.
 ;; Extraction with OCR requires the tesseract command line utility to be
@@ -262,11 +262,30 @@ document's directory. You will be prompted to enter the 
LEVEL
 number. The highest level should have number 1, the next leve
 number 2 etc."
   (interactive "nWhich level you are setting (number): ")
-  (shell-command (format "pdfxmeta --auto %s --page %s '%s' \"%s\" >> 
recipe.toml"
-                         level
-                         (pdf-view-current-page)
-                         (url-filename (url-generic-parse-url 
buffer-file-name))
-                         (car (pdf-view-active-region-text)))))
+  (let* ((page (pdf-view-current-page))
+         (filename (url-filename (url-generic-parse-url buffer-file-name)))
+         (pdfxmeta-result (shell-command
+                           (format "pdfxmeta --auto %s --page %s '%s' \"%s\" 
>> recipe.toml"
+                                   level
+                                   page
+                                   filename
+                                   (car (pdf-view-active-region-text))))))
+    (when (eq pdfxmeta-result 1)
+      (let ((page-text (shell-command-to-string
+                        (format "mutool draw -F text '%s' %s"
+                                filename
+                                page
+                                ))))
+        (pop-to-buffer "page-text")
+        (insert
+         "COULD NOT SET HEADING LEVEL. MUPDF EXTRACTED FOLLOWING PAGE TEXT 
FROM PAGE:\n")
+        (add-text-properties 1 (point) '(face font-lock-warning-face))
+        (let ((beg (point)))
+          (insert "(try to select partial word)\n\n")
+          (add-text-properties beg (point) '(face font-lock-warning-face)))
+        (insert page-text)
+        (beginning-of-buffer)))))
+
 
 (defun toc-extract-with-pdf-tocgen ()
   "Extract Table of Contents with `pdf-tocgen'.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]