unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Make doc-view's pdf->png conversion customizable
@ 2011-06-25 14:35 Elias Pipping
  2011-06-25 14:41 ` Elias Pipping
  0 siblings, 1 reply; 4+ messages in thread
From: Elias Pipping @ 2011-06-25 14:35 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 618 bytes --]

Hello,

mupdf[1] provides the program "pdfdraw" that can convert pdf files to
png images. I've attached a patch to doc-view.el (against the emacs-23
branch, can be applied to 23.3 without any changes as well) that (most
prominently) adds a new (customizable) variable
doc-view-pdf->png-converter-invocation, which can be set to one of the
pre-defined functions

  doc-view-pdf->png-converter-invocation-ghostscript
  doc-view-pdf->png-converter-invocation-mupdf

or a user-specified function. doc-view-pdf/ps->png and
doc-view-pdf/ps->png-1 were made to use them.


Best regards,

Elias Pipping

[1] http://mupdf.com/

[-- Attachment #2: 0001-Make-doc-view-pdf-png-1-customizable.patch --]
[-- Type: text/x-patch, Size: 2855 bytes --]

From 86995ee5dcbc0ff0f0e919bfaa40b9ba325524e8 Mon Sep 17 00:00:00 2001
From: Elias Pipping <pipping@exherbo.org>
Date: Sat, 25 Jun 2011 13:50:11 +0200
Subject: [PATCH] Make doc-view-pdf->png-1 customizable

---
 lisp/doc-view.el |   28 ++++++++++++++++++++++++----
 1 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index af6e4f3..1576e9e 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -428,7 +428,7 @@ Can be `dvi', `pdf', or `ps'.")
       (when (and (not (file-exists-p file))
                  doc-view-current-converter-processes)
         ;; The PNG file hasn't been generated yet.
-        (doc-view-pdf->png-1 doc-view-buffer-file-name file page
+        (funcall doc-view-pdf->png-1 doc-view-buffer-file-name file page
                              (lexical-let ((page page)
                                            (win (selected-window))
                                            (file file))
@@ -720,8 +720,19 @@ Should be invoked when the cached images aren't up-to-date."
                        'doc-view-display
                        (current-buffer)))))
 
-(defun doc-view-pdf->png-1 (pdf png page callback)
-  "Convert a PAGE of a PDF file to PNG asynchronously.
+(defun doc-view-pdf->png-1-mupdf (pdf png page callback)
+  "Convert a PAGE of a PDF file to PNG asynchronously using pdfdraw from mupdf.
+Call CALLBACK with no arguments when done."
+  (doc-view-start-process
+   "pdf->png-1" "pdfdraw"
+   (list (format "-r%d" (round doc-view-resolution))
+	 (concat "-o" png)
+	 pdf
+	 (format "%d" page))
+   callback))
+
+(defun doc-view-pdf->png-1-ghostscript (pdf png page callback)
+  "Convert a PAGE of a PDF file to PNG asynchronously using ghostscript.
 Call CALLBACK with no arguments when done."
   (doc-view-start-process
    "pdf->png-1" doc-view-ghostscript-program
@@ -735,6 +746,15 @@ Call CALLBACK with no arguments when done."
                  pdf))
    callback))
 
+(defcustom doc-view-pdf->png-1
+  'doc-view-pdf->png-1-ghostscript
+  "Called to convert a single page of a PDF file into a PNG file"
+  :type '(radio (function-item doc-view-pdf->png-1-ghostscript :doc "Use ghostscript")
+		(function-item doc-view-pdf->png-1-mupdf :doc "Use mupdf")
+                function)
+  ;:type 'function
+  :group 'doc-view)
+
 (declare-function clear-image-cache "image.c" (&optional filter))
 
 (defun doc-view-pdf->png (pdf png pages)
@@ -747,7 +767,7 @@ Start by converting PAGES, and then the rest."
     ;; a single page anyway, and of the remaining 1%, few cases will have
     ;; consecutive pages, it's not worth the trouble.
     (lexical-let ((pdf pdf) (png png) (rest (cdr pages)))
-      (doc-view-pdf->png-1
+      (funcall doc-view-pdf->png-1
        pdf (format png (car pages)) (car pages)
        (lambda ()
          (if rest
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-06-26 10:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-25 14:35 Make doc-view's pdf->png conversion customizable Elias Pipping
2011-06-25 14:41 ` Elias Pipping
2011-06-25 21:09   ` Jambunathan K
2011-06-26 10:47     ` Elias Pipping

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).