9

When I open pdf with emacs, it got frozen. And I installed pdf-tools, open pdf, it got frozen again.

What's the underlining process when emacs open a pdf? Is there a lot of converting work? What should I do to speed it up?

  • Emacs 24.4
  • Ubuntu 14.04 LTS
  • Intel 2.4GHz x 2
  • 4G RAM.

Update:

I just found this page:

"learnt a lesson. Never open a pdf in emacs. Never even do it accidentally."

https://twitter.com/ergoemacs/status/456088661059457024

It's a sad news to me! Isn't it a great idea to view pdf using Emacs?

Update 2

I thought it was because my pdf file is too large:

5.7M, 1313 pages

So I tried a small pdf file,

402K, 66 pages

it got frozen again.

Update 3

I open pdf file using C-c C-x from helm, and it opens the pdf file in an external viewer: zathura. Since there is no converting process, the file opens lighting fast. (As fast as mupdf. I guess zathura using mupdf as its back end.)

There are four points makes zathura outstanding:

  1. Lighting fast. (Both open and search)
  2. High quality display.
  3. Tab displays the chapter/section menu just like Adobe Reader.
  4. Good keyboard shortcuts support. (Actually, it uses vim-style keybinding, which make sense since there is no need to switch mode in pdf viewer.

Update 4

Screen shot for quality comparasion:

!Left: Zathura; Right: PDF in Emacs

I really got confused what Emacs uses for open PDF. (I've already removed pdf-tools)

  • Don't you want to tell us more about your Emacs config related to pdf files? – Nsukami _ Dec 24 '14 at 9:26
  • @Nsukami_ Thanks for asking. Actually I have nothing related to pdf file in my configuration. 1. I open pdf with default installation. 2. Installed pdf-tools, open pdf. – Nick Dec 24 '14 at 9:32
  • You can use Emacs as PDF reader fine. I now use Emacs to read PDF exclusively. I also use Ubuntu. But how large is your PDF file? – Tu Do Dec 24 '14 at 9:42
  • 4
    Clearly, it's time for emacs -Q again. – wasamasa Dec 24 '14 at 9:53
  • 2
    To install pdf-tools, you have to clone the repo, run ./autogen.sh and follow the standard procedure: ./configure && make && sudo make install. Then, it will produce a pdf-tools.tar.gz in the pdf-tools directory you cloned. Then, put (pdf-tools-install) somewhere in your init file. From now on, Emacs will use pdf-view-mdoe which gives better quality and better rendering speed. – Tu Do Dec 25 '14 at 15:26
12

You should disable linum-mode when opening a PDF file. Otherwise it will hang your Emacs. i.e. only add it to prog-mode for editing text:

(add-hook 'prog-mode-hook 'linum-on)

To install pdf-tools:

  • You have to clone the repository:

    git clone https://github.com/politza/pdf-tools.git

  • cd pdf-tools

  • Run make.

  • Then, it will produce a pdf-tools-${VERSION}.tar in the pdf-tools directory you cloned; in Emacs, M-x package-install-file RET pdf-tools-${VERSION}.tar RET

  • Then, put (pdf-tools-install) somewhere in your init file. From now on, Emacs will use pdf-view-mode which gives better quality and better rendering speed.

Here is a demo using pdf-tools. The PDF file is 28MB and it took a few seconds to open. Note that the quality of the images in the gif are a bit lower quality compared with the actual source, but as you can see the text is crystal clear. I did not record the whole screen to reduce the size of the gif, because it's already 13MB.

I use plain Isearch using C-s as in other buffers for searching. Don't press too fast, leave about 1 second delay between searches. You should use Isearch to search current page or nearby pages, basically something small. To search the whole document, use pdf-occur; the command is quite fast. You may want to keep the search results for later use (in the same session) by renaming the occur default *PDF-Occur* buffer to some other name to avoid it is overridden by future searches.

If you want the table of contents, in the PDF buffer press o to open it in outline-mode.

  • Hat tips to this great package (and answer). The difference is huge if you compare it with the default viewer. – KookieMonster Jun 5 '15 at 20:09
  • (add-hook 'prog-mode-hook 'linum-on) should be (add-hook 'prog-mode-hook 'linum-mode) on 24.5.1. – Yang Feb 19 '16 at 5:08
4

I’m using Emacs for reading documentation, scientific papers and books — all of that without issues.

My doc-view-mode uses mudraw (from mupdf) for rendering PDFs as you can see by checking doc-view-pdfdraw-program variable:

doc-view-pdfdraw-program is a variable defined in `doc-view.el'. Its value is "mudraw" Documentation: Name of MuPDF's program to convert PDF files to PNG. This variable was introduced, or its default value was changed, in version 24.4 of Emacs.

By default doc-view mode uses ghotscript’s gs for rendering which can be slow in comparison. You can read about switch from ghostscript’s gs to mupdf’s mudraw:

I've since been testing that patch and never looked back since the switch sped up the pdf->png conversion by a factor of two and brought anti-aliasing with it.

In your situation:

  1. install mupdf and open PDF in an emacs session without your configuration e.g.:

    env HOME=/tmp emacs -Q
    

    and check if doc-view-pdfdraw-program is set correctly to mudraw.

  2. report back if above improved your situation.

PS I have no experience with pdf-tools.

  • I have mupdf installed, and it's surprisingly fast. I run env HOME=/tmp emacs -Q, emacs sais "still converting…", and takes a while to convert. The speed is fine but the quality is poor. To my surprise, there's no variable named doc-view-pdfdraw-program. If Emacs can use mupdf, that would be really terrific! – Nick Dec 24 '14 at 22:45
  • Are you sure that you are using 24.4? doc-view-pdfdraw-program should be available in such case. Is mudraw available in your shell? – kmicu Dec 25 '14 at 0:25
  • Yes, I'm running Emacs 24.4. This is GNU Emacs 24.4.2 (x86_64-unknown-linux-gnu, GTK+ Version 3.10.8) mudraw is not availabe, so I installed. (the package mupdf-tools), thus I can run mudraw in shell. The converting speed is even more slow, and the pdf display quality is still poor. – Nick Dec 25 '14 at 1:32
  • "To my surprise, there's no variable named doc-view-pdfdraw-program." without knowing what is set in that variable we cannot be sure if you are really using mudraw in doc-view mode, maybe this is still gs. "pdf display quality is still poor" is a relative and subjective statement - can you update your question with some screenshots? For me Zathura (with mupdf backend) has exactly the same PDF rendering quality and speed as in Emacs. – kmicu Dec 25 '14 at 21:22
  • 1
    To get that variable, you have to load it: (require 'doc-view). I think mudraw is the default and the problem is that doc-view cannot fit the whole PDF page into the whole buffer. And I'm not sure about the quality. – Tu Do Dec 26 '14 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.