unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Elias Pipping <pipping.elias@googlemail.com>
To: emacs-devel@gnu.org
Subject: Make doc-view's pdf->png conversion customizable
Date: Sat, 25 Jun 2011 16:35:06 +0200	[thread overview]
Message-ID: <BANLkTi=3r_uwFxD2-=n2=mrHYDr3N4kD0A@mail.gmail.com> (raw)

[-- 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


             reply	other threads:[~2011-06-25 14:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-25 14:35 Elias Pipping [this message]
2011-06-25 14:41 ` Make doc-view's pdf->png conversion customizable Elias Pipping
2011-06-25 21:09   ` Jambunathan K
2011-06-26 10:47     ` Elias Pipping

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='BANLkTi=3r_uwFxD2-=n2=mrHYDr3N4kD0A@mail.gmail.com' \
    --to=pipping.elias@googlemail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).