From 86995ee5dcbc0ff0f0e919bfaa40b9ba325524e8 Mon Sep 17 00:00:00 2001 From: Elias Pipping 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