README-elpa (39206B)
1 ━━━━━━━━━━━━━━━━━━ 2 PDF TOOLS README 3 ━━━━━━━━━━━━━━━━━━ 4 5 6 Table of Contents 7 ───────────────── 8 9 1. About PDF Tools 10 2. Installing pdf-tools 11 .. 1. Installing the epdfinfo server 12 ..... 1. Installing the epdfinfo server from package managers 13 ..... 2. Installing the epdfinfo server from source on Windows (+ Gotchas) 14 ..... 3. Installing the epdfinfo server from source on macOS (+ Gotchas) 15 ..... 4. Common installation gotchas 16 ..... 5. Installing optional features 17 .. 2. Installing pdf-tools elisp code 18 .. 3. Updating pdf-tools 19 3. Features 20 .. 1. View and Navigate PDFs 21 ..... 1. Keybindings for navigating PDF documents 22 ..... 2. Keybindings for manipulating display of PDF 23 .. 2. Annotations 24 ..... 1. Keybindings for working with Annotations 25 .. 3. Working with AUCTeX 26 ..... 1. Keybindings for working with AUCTeX 27 .. 4. Miscellaneous features 28 ..... 1. Keybindings for miscellaneous features in PDF tools 29 .. 5. Easy Help for PDF Tools features 30 .. 6. Configuring PDF Tools features 31 4. Known problems 32 .. 1. linum-mode 33 .. 2. display-line-numbers-mode 34 .. 3. auto-revert 35 .. 4. sublimity 36 .. 5. Text selection is not transparent in PDFs OCRed with Tesseract 37 5. Key-bindings in PDF Tools 38 6. Tips and Tricks for Developers 39 .. 1. Turn on debug mode 40 .. 2. Run Emacs lisp tests locally 41 .. 3. Run server compilation tests locally 42 .. 4. Add a Dockerfile to automate server compilation testing 43 7. FAQs 44 .. 1. PDFs are not rendering well! 45 .. 2. What Emacs versions does pdf-tools support? 46 .. 3. I want to add support for pdf-tools on "My Fav OS". How do I do that? 47 .. 4. I am on a Macbook M1 and pdf-tools installation fails with a stack-trace 48 .. 5. I am a developer, making changes to the pdf-tools source code 49 50 51 [https://circleci.com/gh/vedang/pdf-tools.svg?style=svg] 52 [http://elpa.nongnu.org/nongnu/pdf-tools.svg] 53 [http://stable.melpa.org/packages/pdf-tools-badge.svg] 54 [http://melpa.org/packages/pdf-tools-badge.svg] 55 [https://ci.appveyor.com/api/projects/status/yqic2san0wi7o5v8/branch/master?svg=true] 56 57 The `pdf-tools' Wiki is maintained at <https://pdftools.wiki>. Head to 58 the site if you find it easier to navigate a website for reading a 59 manual. All the topics on the site are listed at 60 <https://pdftools.wiki/impulse>. 61 62 63 [https://circleci.com/gh/vedang/pdf-tools.svg?style=svg] 64 <https://app.circleci.com/pipelines/github/vedang/pdf-tools> 65 66 [http://elpa.nongnu.org/nongnu/pdf-tools.svg] 67 <https://elpa.nongnu.org/nongnu/pdf-tools.html> 68 69 [http://stable.melpa.org/packages/pdf-tools-badge.svg] 70 <https://stable.melpa.org/#/pdf-tools> 71 72 [http://melpa.org/packages/pdf-tools-badge.svg] 73 <https://melpa.org/#/pdf-tools> 74 75 [https://ci.appveyor.com/api/projects/status/yqic2san0wi7o5v8/branch/master?svg=true] 76 <https://ci.appveyor.com/project/vedang/pdf-tools> 77 78 79 1 About PDF Tools 80 ═════════════════ 81 82 PDF Tools is, among other things, a replacement of DocView for PDF 83 files. The key difference is that pages are not pre-rendered by, say, 84 `ghostscript' and stored in the file-system, but rather created 85 on-demand and stored in memory. 86 87 This rendering is performed by a special library named, for whatever 88 reason, `poppler', running inside a server program. This program is 89 called `epdfinfo' and its job is to successively read requests from 90 Emacs and produce the proper results, i.e. the PNG image of a PDF 91 page. 92 93 Actually, displaying PDF files is just one part of `pdf-tools'. Since 94 `poppler' can provide us with all kinds of information about a 95 document and is also able to modify it, there is a lot more we can do 96 with it. [Watch this video for a detailed demo!] 97 98 99 [Watch this video for a detailed demo!] 100 <https://www.dailymotion.com/video/x2bc1is> 101 102 103 2 Installing pdf-tools 104 ══════════════════════ 105 106 Installing this package via NonGNU ELPA or MELPA or any of the other 107 package managers is straightforward and should just work! You should 108 not require any manual changes. The documentation below is *only if 109 you are installing from source*, or for troubleshooting / debugging 110 purposes. 111 112 `pdf-tools' requires a server `epdfinfo' to run against, which it will 113 try to compile and build when it is activated for the first time. The 114 following steps need to be followed *in this order*, to install 115 `pdf-tools' and `epdfinfo' correctly: 116 117 • 118 • 119 120 121 2.1 Installing the epdfinfo server 122 ────────────────────────────────── 123 124 If you install `pdf-tools' via NonGNU ELPA or MELPA, *you don't need 125 to worry about this separate server installation at all*. 126 127 Note: You'll need GNU Emacs ≥ 26.3 and some form of a GNU/Linux 128 OS. Other operating systems are not officially supported, but 129 `pdf-tools' is known to work on many of them. 130 131 The `epdfinfo' install script takes care of installing all the 132 necessary pre-requisites on supported operating systems (see list 133 below). See the section on to learn how to add your favorite Operating 134 System to this list. 135 136 Similarly, package-managers are not officially supported, but 137 `pdf-tools' is known to be available on some of them. See the section 138 on to avoid manual installation of server / server prerequisites. 139 140 Installation Instructions for `epdfinfo': 141 ┌──── 142 │ $ git clone https://github.com/vedang/pdf-tools 143 │ $ cd /path/to/pdf-tools 144 │ $ make -s # If you don't have make installed, run ./server/autobuild and it will install make 145 └──── 146 147 This should give you no error and should compile the `epdfinfo' 148 server. If you face a problem, please report on the issue tracker! 149 150 The following Operating Systems / package managers are 151 supported. *Note*: The package manager used to install pre-requisites 152 should be installed on your OS for the script to work: 153 154 • Debian-based systems (`debian', `ubuntu'): `apt-get' 155 • Fedora: `dnf' 156 • macOS: `brew' 157 • Windows (MSYS2/ MingW): `pacman' 158 • NixOS: `nix-shell' 159 • openSUSE (Tumbleweed and Leap): `zypper' 160 • Void Linux: `xbps-install' 161 • Apline Linux: `apk' 162 • FreeBSD: `pkg' 163 • OpenBSD: `pkg_add' 164 • Arch Linux: `pacman' 165 • Gentoo: `emerge' 166 • CentOS: `yum' 167 168 169 2.1.1 Installing the epdfinfo server from package managers 170 ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ 171 172 `pdf-tools' can be directly installed from the package manager on some 173 operating systems. Note that the packages available on these package 174 managers are not maintained by the author and might be outdated. 175 176 • Debian: <https://packages.debian.org/buster/elpa-pdf-tools-server> 177 • Ubuntu: <https://packages.ubuntu.com/impish/elpa-pdf-tools-server> 178 • MSYS2 / MINGW (Windows): 179 <https://packages.msys2.org/package/mingw-w64-x86_64-emacs-pdf-tools-server?repo=mingw64> 180 • FreeBSD: 181 <https://repology.org/metapackages/?search=pdf-tools&inrepo=freebsd> 182 183 184 2.1.2 Installing the epdfinfo server from source on Windows (+ Gotchas) 185 ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ 186 187 If using the GNU binaries for Windows, support for PNG and `zlib' must 188 first be installed by copying the appropriate dlls into emacs' `bin/' 189 directory. Most third-party binaries come with this already done. 190 191 1. [install MSYS2] and update the package database and core packages 192 using the instructions provided. 193 2. Open `mingw64' shell (*Note:* You must use `mingw64.exe' and not 194 `msys2.exe') 195 3. Compile the `epdfinfo' server using Installation steps described in 196 4. This should produce a file `server/epdfinfo.exe'. Copy this file 197 into the `pdf-tools/' installation directory in your Emacs. 198 5. Make sure Emacs can find `epdfinfo.exe'. Either add the MINGW 199 install location (e.g. `C:/msys2/mingw64/bin') to the system path 200 with `setx PATH "C:\msys2\mingw64\bin;%PATH%"' or set Emacs's path 201 with `(setenv "PATH" (concat "C:\\msys64\\mingw64\\bin;" (getenv 202 "PATH")))'. Note that libraries from other GNU utilities, such as 203 Git for Windows, may interfere with those needed by 204 `pdf-tools'. `pdf-info-check-epdinfo' will succeed, but errors 205 occur when trying to view a PDF file. This can be fixed by ensuring 206 that the MSYS libraries are always preferred. 207 6. `pdf-tools' will successfully compile using Cygwin, but it will not 208 be able to open PDFs properly due to the way binaries compiled with 209 Cygwin handle file paths. Please use MSYS2. 210 211 212 [install MSYS2] <https://www.msys2.org/> 213 214 215 2.1.3 Installing the epdfinfo server from source on macOS (+ Gotchas) 216 ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ 217 218 On macOS, `autobuild' adjusts `PKG_CONFIG_PATH' so that `pdf-tools' 219 can find some of the keg-only packages installed by `brew'. It is 220 recommended that you review the output logs printed by `brew' during 221 the installation process to also export the relevant paths to the 222 appropriate ENV variables. 223 224 225 2.1.4 Common installation gotchas 226 ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ 227 228 In case you decide to install `libpoppler' from source, make sure to 229 run its configure script with the `--enable-xpdf-headers' option. 230 231 232 2.1.5 Installing optional features 233 ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ 234 235 One feature – following links of a PDF document by plain keystrokes – 236 requires `imagemagick''s convert utility. This requirement is 237 optional, the installation process will detect if you have 238 `imagemagick' installed or not. 239 240 241 2.2 Installing pdf-tools elisp code 242 ─────────────────────────────────── 243 244 `pdf-tools' requires `tablist' package (>= version 0.70) to be 245 installed, for it to work correctly. Please make sure that the latest 246 version of `tablist' is installed. 247 248 We have already run the steps necessary to install `pdf-tools' as part 249 of ! These are: 250 ┌──── 251 │ $ git clone https://github.com/vedang/pdf-tools 252 │ $ cd /path/to/pdf-tools 253 │ $ make -s 254 └──── 255 256 If the `make' command produced the ELP file `pdf-tools-${VERSION}.tar' 257 you are fine! This package contains all the necessary files for Emacs 258 and may be installed by either using 259 ┌──── 260 │ $ make install-package 261 └──── 262 or executing the Emacs command 263 ┌──── 264 │ M-x package-install-file RET pdf-tools-${VERSION}.tar RET 265 └──── 266 267 You can test if the package has been installed correctly, by running 268 ┌──── 269 │ M-x pdf-info-check-epdfinfo RET 270 └──── 271 272 To complete the installation process, you need to activate the package 273 by putting the code below somewhere in your `.emacs'. Alternatively, 274 and if you care about startup time, you may want to use the loader 275 version instead. 276 ┌──── 277 │ (pdf-tools-install) ; Standard activation command 278 │ (pdf-loader-install) ; On demand loading, leads to faster startup time 279 └──── 280 281 Once the Installation process is complete, check out and to get 282 started! 283 284 285 2.3 Updating pdf-tools 286 ────────────────────── 287 288 Some day you might want to update this package via `git pull' and then 289 reinstall it. Sometimes this may fail, especially if Lisp-Macros are 290 involved and the version hasn't changed. To avoid this kind of 291 problems, you should delete the old package via `list-packages', 292 restart Emacs, run `make distclean' and then reinstall the 293 package. Follow the steps described in . 294 295 This also applies when updating via MELPA / NonGNU ELPA (except for 296 running the `make distclean' step). 297 298 299 3 Features 300 ══════════ 301 302 View 303 View PDF documents in a buffer with DocView-like bindings. . 304 Isearch 305 Interactively search PDF documents like any other buffer, either 306 for a string or a PCRE. 307 Occur 308 List lines matching a string or regexp in one or more PDF 309 documents. 310 Follow 311 Click on highlighted links, moving to some part of a different 312 page, some external file, a website or any other URI. Links may 313 also be followed by keyboard commands. 314 Annotations 315 Display and list text and markup annotations (like underline), 316 edit their contents and attributes (e.g. color), move them 317 around, delete them or create new ones and then save the 318 modifications back to the PDF file. . 319 Attachments 320 Save files attached to the PDF-file or list them in a dired 321 buffer. 322 Outline 323 Use `imenu' or a special buffer (`M-x pdf-outline') to examine 324 and navigate the PDF's outline. 325 SyncTeX 326 Jump from a position on a page directly to the TeX source and 327 vice versa. 328 Virtual 329 Use a collection of documents as if it were one, big single PDF. 330 Misc 331 • Display PDF's metadata. 332 • Mark a region and kill the text from the PDF. 333 • Keep track of visited pages via a history. 334 • Apply a color filter for reading in low light conditions. 335 336 337 3.1 View and Navigate PDFs 338 ────────────────────────── 339 340 PDFView Mode is an Emacs PDF viewer. It displays PDF files as PNG 341 images in Emacs buffers. PDFs are navigable using DocView-like 342 bindings. Once you have installed `pdf-tools', opening a PDF in Emacs 343 will automatically trigger this mode. 344 345 346 3.1.1 Keybindings for navigating PDF documents 347 ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ 348 349 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 350 Navigation 351 ──────────────────────────────────────────────────────────────────────── 352 Scroll Up / Down by Page-full `space' / `backspace' 353 Scroll Up / Down by Line `C-n' / `C-p' 354 Scroll Right / Left `C-f' / `C-b' 355 First Page / Last Page `<', `M-<' / `>', `M->' 356 Next Page / Previous Page `n' / `p' 357 Incremental Search Forward / Backward `C-s' / `C-r' 358 Occur (list all lines containing a phrase) `M-s o' 359 Jump to Occur Line `RETURN' 360 Pick a Link and Jump `F' 361 Incremental Search in Links `f' 362 History Back / Forwards `l' / `r' 363 Display Outline `o' 364 Jump to Section from Outline `RETURN' 365 Jump to Page `M-g g' 366 Store position / Jump to position in register `m' / `'' 367 ──────────────────────────────────────────────────────────────────────── 368 369 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 370 Note that `pdf-tools' renders the PDF as images inside Emacs. This 371 means that all the keybindings of `image-mode' work on individual PDF 372 pages as well. 373 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 374 Image Mode 375 ───────────────────────────────────────────────────────────────────── 376 image-scroll-right `C-x >' / `<remap> <scroll-right>' 377 image-scroll-left `C-x <' / `<remap> <scroll-left>' 378 image-scroll-up `C-v' / `<remap> <scroll-up>' 379 image-scroll-down `M-v' / `<remap> <scroll-down>' 380 image-forward-hscroll `C-f' / `right' / `<remap> <forward-char>' 381 image-backward-hscroll `C-b' / `left' / `<remap> <backward-char>' 382 image-bob `<remap> <beginning-of-buffer>' 383 image-eob `<remap> <end-of-buffer>' 384 image-bol `<remap> <move-beginning-of-line>' 385 image-eol `<remap> <move-end-of-line>' 386 image-scroll-down `<remap> <scroll-down>' 387 image-scroll-up `<remap> <scroll-up>' 388 image-scroll-left `<remap> <scroll-left>' 389 image-scroll-right `<remap> <scroll-right>' 390 ───────────────────────────────────────────────────────────────────── 391 392 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 393 394 395 3.1.2 Keybindings for manipulating display of PDF 396 ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ 397 398 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 399 Display 400 ─────────────────────────────────────────────────────────── 401 Zoom in / Zoom out `+' / `-' 402 Fit Height / Fit Width / Fit Page `H' / `W' / `P' 403 Trim Margins (set slice to bounding box) `s b' 404 Reset Margins `s r' 405 Reset Zoom `0' 406 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 407 408 409 3.2 Annotations 410 ─────────────── 411 412 `pdf-tools' supports working with PDF Annotations. You can display and 413 list text and markup annotations (like squiggly, highlight), edit 414 their contents and attributes (e.g. color), move them around, delete 415 them or create new ones and then save the modifications back to the 416 PDF file. 417 418 419 3.2.1 Keybindings for working with Annotations 420 ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ 421 422 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 423 Annotations 424 ───────────────────────────────────────────────────────────────────────────────────────── 425 List Annotations `C-c C-a l' 426 Jump to Annotations from List `SPACE' 427 Mark Annotation for Deletion `d' 428 Delete Marked Annotations `x' 429 Unmark Annotations `u' 430 Close Annotation List `q' 431 Enable/Disable Following Annotations `C-c C-f' 432 ───────────────────────────────────────────────────────────────────────────────────────── 433 Add and Edit Annotations Select region via Mouse selection. 434 Then left-click context menu OR keybindings below 435 ───────────────────────────────────────────────────────────────────────────────────────── 436 Add a Markup Annotation `C-c C-a m' 437 Add a Highlight Markup Annotation `C-c C-a h' 438 Add a Strikeout Markup Annotation `C-c C-a o' 439 Add a Squiggly Markup Annotation `C-c C-a s' 440 Add an Underline Markup Annotation `C-c C-a u' 441 Add a Text Annotation `C-c C-a t' 442 ───────────────────────────────────────────────────────────────────────────────────────── 443 444 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 445 446 447 3.3 Working with AUCTeX 448 ─────────────────────── 449 450 3.3.1 Keybindings for working with AUCTeX 451 ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ 452 453 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 454 Syncing with AUCTeX 455 ──────────────────────────────────────────────────────────── 456 Refresh File (e.g., after recompiling source) `g' 457 Jump to PDF Location from Source `C-c C-g' 458 Jump Source Location from PDF `C-mouse-1' 459 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 460 461 462 3.4 Miscellaneous features 463 ────────────────────────── 464 465 3.4.1 Keybindings for miscellaneous features in PDF tools 466 ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ 467 468 ━━━━━━━━━━━━━━━━━━━━━━━━━━ 469 Miscellaneous 470 ────────────────────────── 471 Print File `C-c C-p' 472 ━━━━━━━━━━━━━━━━━━━━━━━━━━ 473 474 475 3.5 Easy Help for PDF Tools features 476 ──────────────────────────────────── 477 478 ┌──── 479 │ M-x pdf-tools-help RET 480 └──── 481 482 Run `M-x pdf-tools-help' inside Emacs, as shown above. It will list 483 all the features provided by `pdf-tools' as well as the key-bindings 484 for these features. 485 486 487 3.6 Configuring PDF Tools features 488 ────────────────────────────────── 489 490 Once you have read through the features provided by `pdf-tools', you 491 probably want to customize the behavior of the features as per your 492 requirements. Full customization of features is available by running 493 the following: 494 ┌──── 495 │ M-x pdf-tools-customize RET 496 └──── 497 498 499 4 Known problems 500 ════════════════ 501 502 4.1 linum-mode 503 ────────────── 504 505 `pdf-tools' does not work well together with `linum-mode' and 506 activating it in a `pdf-view-mode', e.g. via `global-linum-mode', 507 might make Emacs choke. 508 509 510 4.2 display-line-numbers-mode 511 ───────────────────────────── 512 513 This mode is an alternative to `linum-mode' and is available since 514 Emacs 26. `pdf-tools' does not work well with it. For example, it 515 makes horizontal navigation (such as `C-f', `C-b', `C-x <' or `C-x >' 516 ) in a document impossible. 517 518 519 4.3 auto-revert 520 ─────────────── 521 522 Autorevert works by polling the file-system every 523 `auto-revert-interval' seconds, optionally combined with some 524 event-based reverting via [file notification]. But this currently does 525 not work reliably, such that Emacs may revert the PDF-buffer while the 526 corresponding file is still being written to (e.g. by LaTeX), leading 527 to a potential error. 528 529 With a recent [AUCTeX] installation, you might want to put the 530 following somewhere in your dotemacs, which will revert the PDF-buffer 531 *after* the TeX compilation has finished. 532 ┌──── 533 │ (add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer) 534 └──── 535 536 537 [file notification] 538 <https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Notifications.html> 539 540 [AUCTeX] <https://www.gnu.org/software/auctex/> 541 542 543 4.4 sublimity 544 ───────────── 545 546 L/R scrolling breaks while zoomed into a pdf, with usage of sublimity 547 smooth scrolling features 548 549 550 4.5 Text selection is not transparent in PDFs OCRed with Tesseract 551 ────────────────────────────────────────────────────────────────── 552 553 In such PDFs the selected text becomes hidden behind the selection; 554 see [this issue], which also describes the workaround in detail. The 555 following function, which depends on the [qpdf.el] package, can be 556 used to convert such a PDF file into one where text selection is 557 transparent: 558 ┌──── 559 │ (defun my-fix-pdf-selection () 560 │ "Replace pdf with one where selection shows transparently." 561 │ (interactive) 562 │ (unless (equal (file-name-extension (buffer-file-name)) "pdf") 563 │ (error "Buffer should visit a pdf file.")) 564 │ (unless (equal major-mode 'pdf-view-mode) 565 │ (pdf-view-mode)) 566 │ ;; save file in QDF-mode 567 │ (qpdf-run (list 568 │ (concat "--infile=" 569 │ (buffer-file-name)) 570 │ "--qdf --object-streams=disable" 571 │ "--replace-input")) 572 │ ;; do replacements 573 │ (text-mode) 574 │ (read-only-mode -1) 575 │ (while (re-search-forward "3 Tr" nil t) 576 │ (replace-match "7 Tr" nil nil)) 577 │ (save-buffer) 578 │ (pdf-view-mode)) 579 └──── 580 Note that this overwrites the PDF file visited in the buffer from 581 which it is run! To avoid this replace the `--replace-input' with 582 `(concat "--outfile=" (file-truename (read-file-name "Outfile: ")))'. 583 584 585 [this issue] <https://github.com/vedang/pdf-tools/issues/149> 586 587 [qpdf.el] <https://github.com/orgtre/qpdf.el> 588 589 590 5 Key-bindings in PDF Tools 591 ═══════════════════════════ 592 593 • 594 • 595 • 596 • 597 • 598 599 600 6 Tips and Tricks for Developers 601 ════════════════════════════════ 602 603 6.1 Turn on debug mode 604 ────────────────────── 605 606 ┌──── 607 │ M-x pdf-tools-toggle-debug RET 608 └──── 609 Toggling debug mode prints information about various operations in the 610 `*Messages*' buffer, and this is useful to see what is happening 611 behind the scenes 612 613 614 6.2 Run Emacs lisp tests locally 615 ──────────────────────────────── 616 617 You can go to the `pdf-tools' folder and run `make test' to run the 618 ERT tests and check if the changes you have made to the code break any 619 of the tests. 620 621 The tests are written in ERT, which is the built-in testing system in 622 Emacs. However, they are run using `Cask' which you will have to 623 install first, if you don't have it already. You can install `Cask' by 624 following the instructions on their site at 625 <https://github.com/cask/cask> 626 627 628 6.3 Run server compilation tests locally 629 ──────────────────────────────────────── 630 631 You can go to the `pdf-tools' folder and run `make server-test' to 632 check if the changes you have made to the server code break 633 compilation on any of the supported operating systems. 634 635 The tests build `Podman' images for all supported operating systems, 636 so you will have to install `Podman' first, if you don't have 637 already. You can install `Podman' by following the instructions on 638 their site at <https://podman.io/getting-started/installation> 639 640 Podman is compatible with Docker, so if you already have `docker' 641 installed, you should be able to `alias podman=docker' on your shell 642 and run the tests, without having to install Docker. (Note: I have not 643 tested this) 644 645 646 6.4 Add a Dockerfile to automate server compilation testing 647 ─────────────────────────────────────────────────────────── 648 649 The `server/test/docker' folder contains Dockerfile templates used for 650 testing that the `epdfinfo' server compiles correctly on various 651 operating systems (). 652 653 To see the list of operating systems where compilation testing is 654 supported, run `make server-test-supported'. To see the list of 655 operating systems where testing is unsupported, run `make 656 server-test-unsupported'. To add support, look into the 657 `server/test/docker/templates' folder (`ubuntu' files are a good 658 example to refer to) 659 660 661 7 FAQs 662 ══════ 663 664 7.1 PDFs are not rendering well! 665 ──────────────────────────────── 666 667 `pdf-tools' version `1.1.0' release changed the default value of 668 `pdf-view-use-scaling' to `t' (previously, it was `nil'). This has 669 been done keeping in mind that most modern monitors are HiDPI screens, 670 so the default configuration should cater to this user. If you are not 671 using a HiDPI screen, you might have to change this value to `nil' in 672 your configuration 673 674 ┌──── 675 │ (setq pdf-view-use-scaling nil) 676 └──── 677 678 to scale the images correctly when rendering them. 679 680 681 7.2 What Emacs versions does pdf-tools support? 682 ─────────────────────────────────────────────── 683 684 `pdf-tools' supports the 3 latest versions of Emacs major releases. At 685 the moment of this writing, this means that the minimum supported 686 Emacs version is `26.3'. 687 688 689 7.3 I want to add support for pdf-tools on "My Fav OS". How do I do that? 690 ───────────────────────────────────────────────────────────────────────── 691 692 I'm working on automating `pdf-tools' installation as much as 693 possible, in order to improve the installation experience. If you want 694 to add support for a new / currently unsupported Operating System, 695 please modify the `server/autobuild' script. Say you want to support a 696 new Operating System called MyFavOS. You need to do the following 697 work: 698 699 1. Search for the `Figure out where we are' section. Here, add a call 700 to `os_myfavos' right below `handle_options' at the end of the 701 existing call chain. Here we try and pick up the correct Operating 702 System and install the relevant dependencies. 703 2. Add handling for the `--os' argument in `os_argument' for 704 `myfavos', so that the appropriate function can be called to 705 install pre-requisites. `--os' is the argument that we pass to the 706 script from the command-line to indicate which OS we are on. 707 3. Create a `os_myfavos' function. This function checks if we are 708 running on MyFavOS. If we are running on MyFavOS, it sets up 709 `PKGCMD', `PKGARGS' and `PACKAGES' variables so that the 710 appropriate package manager can install the dependencies as part of 711 the rest of the `autobuild' script. 712 4. If you are adding support for your favorite operating system, 713 consider adding automated testing support as well, to help me 714 ensure that `epdfinfo' continues to compile correctly. See for more 715 details. 716 717 The idea here is to make the `server/autobuild' file the single place 718 from which installation can happen on any Operating System. This makes 719 building `pdf-tools' dead simple via the `Makefile'. 720 721 This seems like a lot of work, but it is not. If you need a reference, 722 search for `os_gentoo' or `os_debian' in the `server/autobuild' file 723 and see how these are setup and used. The functions are used to 724 install dependencies on Gentoo and Debian respectively, and are simple 725 to copy / change. 726 727 When you make your changes, please be sure to test as well as as 728 described in the linked articles. 729 730 731 7.4 I am on a Macbook M1 and pdf-tools installation fails with a stack-trace 732 ──────────────────────────────────────────────────────────────────────────── 733 734 There have been a number of issues around `pdf-tools' installation 735 problems on M1. `M-x pdf-tools-install' throws the following stack 736 trace: 737 ┌──── 738 │ 1 warning generated. 739 │ ld: warning: ignoring file /opt/homebrew/opt/gettext/lib/libintl.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64 740 │ ld: warning: ignoring file /opt/homebrew/Cellar/glib/2.72.1/lib/libglib-2.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64 741 │ ld: warning: ignoring file /opt/homebrew/Cellar/poppler/22.02.0/lib/libpoppler-glib.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64 742 │ ld: warning: ignoring file /opt/homebrew/Cellar/glib/2.72.1/lib/libgobject-2.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64 743 │ ld: warning: ignoring file /opt/homebrew/Cellar/poppler/22.02.0/lib/libpoppler.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64 744 │ ld: warning: ignoring file /opt/homebrew/Cellar/cairo/1.16.0_5/lib/libcairo.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64 745 │ ld: warning: ignoring file /opt/homebrew/Cellar/libpng/1.6.37/lib/libpng16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64 746 │ ld: warning: ignoring file /opt/homebrew/Cellar/zlib/1.2.11/lib/libz.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64 747 │ Undefined symbols for architecture x86_64: 748 └──── 749 750 This happens because M1 architecture is `ARM64', whereas the Emacs App 751 you are using has been compiled for the `x86_64' architecture. The way 752 to solve this problem is to install a version of Emacs which has been 753 compiled for the M1. As of today, [2022-05-09 Mon], the latest version 754 of Emacs available on <https://emacsformacosx.com/> is natively 755 compiled and you will not face these issues on it. Please remove your 756 current Emacs App and install it from <https://emacsformacosx.com/>. 757 758 Thank you. 759 760 PS: How do I know if the Emacs I'm running has been compiled 761 correctly? 762 763 You can see this by opening the `Activity Monitor', selecting `Emacs', 764 clicking on the `Info' key, and then clicking on `Sample'. The `Code 765 Type' field in the Sample output will show you how your Application 766 has been compiled. Here is the output for EmacsForMacOSX (you can see 767 that it's `ARM64'): 768 ┌──── 769 │ Sampling process 61824 for 3 seconds with 1 millisecond of run time between samples 770 │ Sampling completed, processing symbols... 771 │ Analysis of sampling Emacs-arm64-11 (pid 61824) every 1 millisecond 772 │ Process: Emacs-arm64-11 [61824] 773 │ Path: /Applications/Emacs.app/Contents/MacOS/Emacs-arm64-11 774 │ Load Address: 0x1007f0000 775 │ Identifier: org.gnu.Emacs 776 │ Version: Version 28.1 (9.0) 777 │ Code Type: ARM64 778 │ Platform: macOS 779 └──── 780 781 If your Emacs is compiled for x86, the `Code Type' will be `x86_64'. 782 783 784 7.5 I am a developer, making changes to the pdf-tools source code 785 ───────────────────────────────────────────────────────────────── 786 787 Thank you for taking the time to contribute back to the code. You may 788 find some useful notes in the section. Please be sure to check it out!