shg / org-inline-pdf.el

Inline PDF previewing for Org
GNU General Public License v3.0
48 stars 8 forks source link
emacs org-mode

-- eval: (visual-line-mode 1) --

+STARTUP: showall

[[https://melpa.org/#/org-inline-pdf][file:https://melpa.org/packages/org-inline-pdf-badge.svg]] [[https://stable.melpa.org/#/org-inline-pdf][file:https://stable.melpa.org/packages/org-inline-pdf-badge.svg]]

Org-inline-pdf enables inline PDF preview in Org buffers.

** Installation

This program works only with Org 9.4 or later. You need to have [[https://cityinthesky.co.uk/opensource/pdf2svg/][pdf2svg]] installed in =exec-path=. You can install it using a package management system like Homebrew or APT.

+BEGIN_SRC sh

On macOS

brew install pdf2svg

On Debian Linux

sudo apt install pdf2svg

+END_SRC

You can install org-inline-pdf from MELPA. For manual installation, download =org-inline-pdf.el= into somewhere in your local directory and install it with =M-x package-install-file=.

Enable this feature in an Org buffer with =M-x org-inline-pdf-mode=. Add the following line to your init file to automatically enable the feature in newly opened Org buffers.

+BEGIN_SRC emacs-lisp

(add-hook 'org-mode-hook #'org-inline-pdf-mode)

+END_SRC

** Usage

You can place links to PDF files in the same way as ordinary inline images using double brackets like =[[./figs/plot.pdf]]= in Org buffers. Linked PDF files will be displayed inline by =org-display-inline-images= command.

For a multiple-page PDF, the first page is shown by default. You can specify the page to show using =:page= attribute for the link. The following is an example of specifying the page along with the display size.

+BEGIN_SRC org

,#+ATTR_ORG: :width 40% :page 3 [[./docs/report.pdf]]

+END_SRC

=org-inline-pdf.el= saves preview images in a temporary directory by default, which is removed on Emacs shutdown. To make images persist between Emacs sessions, you can change the variable =org-inline-pdf-cache-directory=.

Previous versions of org-inline-pdf display all images in the buffer when the minor mode is turned on. Versions 0.6 and later do not automatically do this by default. To get the similar behavior as before, set =org-startup-with-inline-images= to non-nil in your init file. You can also set inlineimages or noinlineimages in the STARTUP option of the file, which overrides the global setting.

*** Inline PDF in exported HTML file

This package also makes Org's HTML exporter ox-html to embed linked PDF files as images using =img= tag. Note that inline PDF using =img= tag is not standard and will be rendered only in particular browsers. Safari.app is only the one I know.

** Known issues

Users of [[https://github.com/jkitchin/scimax][Scimax]] need to turn off a feature of scimax-org-images with =scimax-toggle-image-advice= for org-inine-pdf to work. See [[/../../issues/5][#5]].