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: Re: Make doc-view's pdf->png conversion customizable
Date: Sat, 25 Jun 2011 16:41:07 +0200	[thread overview]
Message-ID: <BANLkTimBqaonHW+ZC8xv_QzDVMHG9cUuNQ@mail.gmail.com> (raw)
In-Reply-To: <BANLkTi=3r_uwFxD2-=n2=mrHYDr3N4kD0A@mail.gmail.com>

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

On Sat, Jun 25, 2011 at 4:35 PM, Elias Pipping
<pipping.elias@googlemail.com> wrote:
> 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/

I attached an old version of the patch by mistake.

I've attached the new and correct version to this email.

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

From 870bacaa0e0db0f93d47c333349560fbae64f2fb 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 |   71 ++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 53 insertions(+), 18 deletions(-)

diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index af6e4f3..8a921a7 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -153,6 +153,26 @@
   :type 'file
   :group 'doc-view)
 
+(defcustom doc-view-pdfdraw-program (executable-find "pdfdraw")
+  "Program to convert PDF files to PNG."
+  :type 'file
+  :group 'doc-view)
+
+(defcustom doc-view-pdf->png-converter-invocation
+  'doc-view-pdf->png-converter-invocation-ghostscript
+  "Called to convert a PDF file into a PNG file"
+  :type '(radio (function-item doc-view-pdf->png-converter-invocation-ghostscript :doc "Use ghostscript")
+		(function-item doc-view-pdf->png-converter-invocation-mupdf :doc "Use mupdf")
+                function)
+  :group 'doc-view)
+
+(defcustom doc-view-ps->png-converter-invocation
+  'doc-view-ps->png-converter-invocation-ghostscript
+  "Called to convert a PS file into a PNG file"
+  :type '(radio (function-item doc-view-ps->png-converter-invocation-ghostscript :doc "Use ghostscript")
+                function)
+  :group 'doc-view)
+
 (defcustom doc-view-ghostscript-options
   '("-dSAFER" ;; Avoid security problems when rendering files from untrusted
 	      ;; sources.
@@ -692,15 +712,35 @@ Should be invoked when the cached images aren't up-to-date."
 			    (list "-o" pdf dvi)
 			    callback)))
 
+(defun doc-view-pdf->png-converter-invocation-ghostscript (resolution pdf png &optional page)
+  `((command . ,doc-view-ghostscript-program)
+    (arguments . (,@doc-view-ghostscript-options
+		  ,(format "-r%d" resolution)
+		  ,@(if page `(,(format "-dFirstPage=%d" page)))
+		  ,@(if page `(,(format "-dLastPage=%d" page)))
+		  ,(concat "-sOutputFile=" png)
+		  ,pdf))))
+
+(defalias 'doc-view-ps->png-converter-invocation-ghostscript
+  'doc-view-pdf->png-converter-invocation-ghostscript)
+
+(defun doc-view-pdf->png-converter-invocation-mupdf (resolution pdf png &optional page)
+  `((command . ,doc-view-pdfdraw-program)
+    (arguments . (,(concat "-o" png)
+		  ,(format "-r%d" resolution)
+		  ,pdf
+		  ,@(if page `(,(format "%d" page)))))))
 
 (defun doc-view-pdf/ps->png (pdf-ps png)
   "Convert PDF-PS to PNG asynchronously."
-  (doc-view-start-process
-   "pdf/ps->png" doc-view-ghostscript-program
-   (append doc-view-ghostscript-options
-           (list (format "-r%d" (round doc-view-resolution))
-                 (concat "-sOutputFile=" png)
-                 pdf-ps))
+  (let ((invocation (case doc-view-doc-type
+			  (pdf (funcall doc-view-pdf->png-converter-invocation
+					(round doc-view-resolution) pdf-ps png))
+			  (t   (funcall doc-view-ps->png-converter-invocation
+					(round doc-view-resolution) pdf-ps png)))))
+    (doc-view-start-process
+     "pdf/ps->png" (cdr (assoc 'command invocation))
+     (cdr (assoc 'arguments invocation))
    (lexical-let ((resolution doc-view-resolution))
      (lambda ()
        ;; Only create the resolution file when it's all done, so it also
@@ -712,7 +752,7 @@ Should be invoked when the cached images aren't up-to-date."
        (when doc-view-current-timer
          (cancel-timer doc-view-current-timer)
          (setq doc-view-current-timer nil))
-       (doc-view-display (current-buffer) 'force))))
+       (doc-view-display (current-buffer) 'force)))))
   ;; Update the displayed pages as soon as they're done generating.
   (when doc-view-conversion-refresh-interval
     (setq doc-view-current-timer
@@ -723,17 +763,12 @@ Should be invoked when the cached images aren't up-to-date."
 (defun doc-view-pdf->png-1 (pdf png page callback)
   "Convert a PAGE of a PDF file to PNG asynchronously.
 Call CALLBACK with no arguments when done."
-  (doc-view-start-process
-   "pdf->png-1" doc-view-ghostscript-program
-   (append doc-view-ghostscript-options
-           (list (format "-r%d" (round doc-view-resolution))
-                 ;; Sadly, `gs' only supports the page-range
-                 ;; for PDF files.
-                 (format "-dFirstPage=%d" page)
-                 (format "-dLastPage=%d" page)
-                 (concat "-sOutputFile=" png)
-                 pdf))
-   callback))
+  (let ((invocation (funcall doc-view-pdf->png-converter-invocation
+			     (round doc-view-resolution) pdf png page)))
+    (doc-view-start-process
+     "pdf/ps->png" (cdr (assoc 'command invocation))
+     (cdr (assoc 'arguments invocation))
+     callback)))
 
 (declare-function clear-image-cache "image.c" (&optional filter))
 
-- 
1.7.5.4


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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-25 14:35 Make doc-view's pdf->png conversion customizable Elias Pipping
2011-06-25 14:41 ` Elias Pipping [this message]
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=BANLkTimBqaonHW+ZC8xv_QzDVMHG9cUuNQ@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).