pdf-tools icon indicating copy to clipboard operation
pdf-tools copied to clipboard

Can't open pdf files on macOS?

Open Prague2049 opened this issue 2 years ago • 10 comments

1.When I open the pdf file with pdf-tools, I get the following error: Debugger entered--Lisp error: (wrong-type-argument stringp number-or-marker-p) string-match(":Document is encrypted\'" number-or-marker-p nil t) pdf-info-encrypted-p() pdf-view-decrypt-document() pdf-view-mode() #(pdf-view-mode nil) apply(# (pdf-view-mode nil)) set-auto-mode-0(pdf-view-mode nil) set-auto-mode() normal-mode(t) after-find-file(nil t) find-file-noselect-1(#<buffer Test.pdf> "~/Downloads/Test.pdf" nil nil "~/Downloads/Test.pdf" ) find-file-noselect("~/Downloads/Test...") ns-find-file() ns-open-file-select-line() funcall-interactively(ns-open-file-select-line) command-execute(ns-open-file-select-line) The opened pdf file is garbled and the pdf-tools toolbar does not appear M1 Mac, emacs-plus@29, pdf-tools-20230611.239,poppler: stable 23.07.0 (bottled), HEAD

  1. M+x pdf-tools-install then get the following feedback:

Is case-sensitive searching enabled ? yes Is modifying text annotations enabled ? yes Is modifying markup annotations enabled ? yes

test -z "epdfinfo" || rm -f epdfinfo test -z "libsynctex.a" || rm -f libsynctex.a rm -f *.o epdfinfo.c:354:19: warning: 'tempnam' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tempnam(3), it is highly recommended that you use mkstemp(3) instead. [-Wdeprecated-declarations] filename = tempnam(NULL, "epdfinfo"); ^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdio.h:312:1: note: 'tempnam' has been explicitly marked deprecated here __deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inher... ^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg' #define __deprecated_msg(_msg) attribute((deprecated(_msg))) ^ epdfinfo.c:1576:5: warning: 'poppler_page_get_selection_region' is deprecated: Use poppler_page_get_selected_region instead [-Wdeprecated-declarations] poppler_page_get_selection_region (page, 1.0, selection_style, region); ^ /opt/local/include/poppler/glib/poppler-page.h:75:134: note: 'poppler_page_get_selection_region' has been explicitly marked deprecated here ...*page, gdouble scale, PopplerSelectionStyle style, PopplerRectangle *selection) G_GNUC_DEPRECATED_FOR(poppl... ^ /opt/local/include/glib-2.0/glib/gmacros.h:689:18: note: expanded from macro 'G_GNUC_DEPRECATED_FOR' attribute((deprecated("Use " #f " instead")))
^ 2 warnings generated.


   Installing          

make -s install /opt/local/bin/gmkdir -p '.emacs.d/elpa/pdf-tools-20230611.239' /opt/local/bin/ginstall -c epdfinfo '.emacs.d/elpa/pdf-tools-20230611.239' make[1]: Nothing to be done for `install-data-am'.

=========================== Build succeeded. :O)

Prague2049 avatar Aug 01 '23 23:08 Prague2049

I had a similar issue in macOS. In my case i solved the issue by upgrading all homebrew dependencies and recompiling. Might help to check whether epdfinfo runs at all or if running the binary from a terminal produces an error message (in my case, it couldn't load some homebrew libraries).

fbanados avatar Aug 22 '23 00:08 fbanados

I have exactly the same problem, did you solve it?

suckerSlayer avatar Mar 17 '24 15:03 suckerSlayer

@suckerSlayer : I deleted and re-installed pdf-tools and I can't seem to reproduce the problem. Could you try a fresh install and see if it solves the issue?

vedang avatar Mar 19 '24 06:03 vedang

Call me Ishmael. pdf-tools is my white whale. Call it my albatross, this elusive yet incredibly promising piece of software, whose installation eludes my grasp like the slippery fluke of the great white whale. Each attempt, a harpoon cast into the tempest of code, only to find my vessel dashed upon the rocks of error messages. Like Ahab, I pursue this digital Leviathan, but it slips through my fingers like mist upon the sea. It taunts me with its siren song, beckoning from the depths of elisp, yet remaining just beyond my reach, a phantom ever escaping through the corridors of my digital ship. Comrades, heed this distress call from the helm of my beleaguered vessel! Fellow pilots, lend me your expertise, your guidance, your wisdom!

I am running Sonoma 14.2.1 on an Apple M1 chip MacBook Pro. I'm running Emacs 29.2. I use doom emacs BUT I installed pdf-tools NOT through the :pdf option in init.el but invoking list-packages and installing the latest available version (namely, version 20240411.1703). I've installed the dependencies through homebrew; meaning poppler, etc.

Now up to the symptoms.

Upon pdf-tools-install I experience the same output and the same 2 warnings that @Prague2049 describes in the post at the top of this issue (and @suckerSlayer seems to have experienced as well). If I open a PDF, DocView displays it correctly. If I invoke pdf-view-mode however, I just see the text representation of the PDF file (weird characters, etc), even though "PDFView" is displayed in the modeline. I also get the following message in the *Messages* buffer:

pdf-info-encrypted-p: Wrong type argument: stringp, number-or-marker-p

and this is true no matter which PDF I open. And NO, my PDFs are NOT encrypted; external PDF readers (and even DocView) are able to load them correctly.

Moreover, if I try the command pdf-info-check-epdfinfo to check epdfinfo I get the following answer:

funcall-interactively: Wrong type argument: number-or-marker-p, "Bus error: 10"

BUT if I run epdfinfo from the command line (from its folder, obviously), I don't get any errors and I can do quit to exit it gracefully.

I'm lost for words here, the silly preface of this message is my attempt at describing how I really feel about this. pdf-tools is my white whale. I cannot seem to install it, and it has been a while since I started trying, and I've gone through many attempts on previous versions. It is a pity because I use PDFs all the time and this software seems to be a qualitatively and quantitatively better solution than DocView.

Thanks @vedang in advance for all your help.

gusgustavsohn avatar Apr 22 '24 11:04 gusgustavsohn

I hope my comment will be helpful but I am not sure that I experience the same issue (update: this https://github.com/vedang/pdf-tools/issues/269#issuecomment-2067658780 might be the same issue). I sympathize profoundly with Ishmael as I love pdf-tools when it works for me.

When I attempt opening a complex PDF, I get:

pdf-info-query: epdfinfo: Failed to render page 1

When I attempt opening a PDF compiled by org-mode (i.e. %PDF-1.5), I get:

Error running timer ‘pdf-cache--prefetch-start’: (error "The epdfinfo server quit")

It asks me then If I want to restart epdfinfo server. Restarting does not help - it keeps failing. If I say "no", it starts giving me a different error:

File mode specification error: (error The epdfinfo server quit)

Here is the backtrace for a simple PDF before saying "no" to restarting:

Debugger entered--Lisp error: (error "The epdfinfo server quit unexpectedly")
  error("The epdfinfo server quit unexpectedly")
  pdf-info-query(renderpage "/Users/sp/Documents/personal/docs/HEL-PhD/02-resea..." 1 2818)
  pdf-info-renderpage(1 1409)
  pdf-cache-renderpage(1 1409 2818)
  pdf-view-create-page(1 #<window 7 on 02-research-proposal.pdf>)
  pdf-view-display-page(1 #<window 7 on 02-research-proposal.pdf>)
  pdf-view-redisplay(#<window 7 on 02-research-proposal.pdf>)
  pdf-view-goto-page(1)
  pdf-view-new-window-function((#<window 7 on 02-research-proposal.pdf> (needs-redisplay) (page . 1) (overlay . #<overlay from 1 to 68619 in 02-research-proposal.pdf>)))
  image-mode-winprops(nil t)
  image-mode-reapply-winprops()
  redisplay_internal\ \(C\ function\)()

Here is the backtrace for the same file after saying "no" and doing M-x normal-mode:

Debugger entered--Lisp error: (error "The epdfinfo server quit")
  signal(error ("The epdfinfo server quit"))
  pdf-info-encrypted-p()
  pdf-view-decrypt-document()
  pdf-view-mode()
  set-auto-mode-0(pdf-view-mode nil)
  set-auto-mode()
  normal-mode()
  funcall-interactively(normal-mode)
  command-execute(normal-mode record)
  execute-extended-command(nil "normal-mode" nil)
  funcall-interactively(execute-extended-command nil "normal-mode" nil)
  command-execute(execute-extended-command)

M-x pdf-info-check-epdfinfo returns

The epdfinfo program appears to be working.

I am using the 94e9f20 version of pdf-tools installed with straight.

Please note, https://github.com/vedang/pdf-tools/commit/a1048bceb2bd3f635437b0f2bfac27cae8c2dabc did not solve the issue of compiling the epdfinfo on my machine. What did solve it for me is adding these to my init.el as suggested here https://github.com/minad/jinx/discussions/160#discussioncomment-9111820:

:init
(setenv "PKG_CONFIG_PATH" 
        (concat "/opt/homebrew/opt/poppler/lib/pkgconfig:" 
(getenv "PKG_CONFIG_PATH")))                                 
        (setenv "PKG_CONFIG_PATH" 
(concat "/opt/homebrew/opt/glib/lib/pkgconfig/:" 
        (getenv "PKG_CONFIG_PATH")))

I am using MBP with M2 chip, Sonoma 14.4.1. I use Emacs-plus 29.3. Here is what brew info outputs for the packages:

❯ brew info glib   
==> glib: stable 2.80.0 (bottled)
Core application library for C
https://developer.gnome.org/glib/
/opt/homebrew/Cellar/glib/2.80.0_2 (524 files, 36MB)
  Poured from bottle using the formulae.brew.sh API on 2024-03-29 at 15:54:16
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/g/glib.rb
License: LGPL-2.1-or-later
==> Dependencies
Build: bison ✘, gettext ✔, meson ✘, ninja ✘, pkg-config ✔, python-setuptools ✘
Required: pcre2 ✔, [email protected] ✔, gettext ✔
==> Analytics
install: 257,671 (30 days), 713,335 (90 days), 2,613,138 (365 days)
install-on-request: 78,534 (30 days), 201,327 (90 days), 747,348 (365 days)
build-error: 1,464 (30 days)

❯ brew info poppler
==> poppler: stable 24.04.0 (bottled), HEAD
PDF rendering library (based on the xpdf-3.0 code base)
https://poppler.freedesktop.org/
Conflicts with:
  pdf2image (because poppler, pdftohtml, pdf2image, and xpdf install conflicting executables)
  pdftohtml (because poppler, pdftohtml, pdf2image, and xpdf install conflicting executables)
  xpdf (because poppler, pdftohtml, pdf2image, and xpdf install conflicting executables)
Installed
/opt/homebrew/Cellar/poppler/24.04.0 (465 files, 29.3MB) *
  Poured from bottle using the formulae.brew.sh API on 2024-04-05 at 20:29:14
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/p/poppler.rb
License: GPL-2.0-only
==> Dependencies
Build: cmake ✘, gobject-introspection ✘, pkg-config ✔
Required: cairo ✔, fontconfig ✔, freetype ✔, gettext ✔, glib ✔, gpgme ✔, jpeg-turbo ✔, libpng ✔, libtiff ✔, little-cms2 ✔, nspr ✔, nss ✔, openjpeg ✔
==> Options
--HEAD
	Install HEAD version
==> Analytics
install: 30,839 (30 days), 92,330 (90 days), 319,617 (365 days)
install-on-request: 23,621 (30 days), 69,365 (90 days), 234,262 (365 days)
build-error: 427 (30 days)

paskn avatar Apr 22 '24 12:04 paskn

Thanks @paskn for your quick reply. The info on both our libraries from brew info looks very much the same. I tried with adding your code to my configuration for defining the PKG_CONFIG_PATH and re-run the pdf-tools-install. The install succeeded (as before) but left these messages in the *Messages* buffer:

Building the PDF Tools server succeeded error in process sentinel: pdf-tools-install-noverify: Symbol’s function definition is void: pdf-occur-global-minor-mode error in process sentinel: Symbol’s function definition is void: pdf-occur-global-minor-mode

After that, I tried opening a PDF; it still doesn't work (same as before, text representation of PDF instead of actual rendering of the PDF) BUT now the error message that I get is different:

File mode specification error: (wrong-type-argument stringp number-or-marker-p)

Thanks in advance for all your help.

PS Please don't hesitate to tell me if you need more info or how I can get more debug results from this (is there a debug mode?).

gusgustavsohn avatar Apr 22 '24 14:04 gusgustavsohn

Issue still open, maybe @vedang could guide me in how I can be useful in providing more details to debug this? Thanks in advance for all your help.

gusgustavsohn avatar Apr 25 '24 00:04 gusgustavsohn

Hi,

You can try to turn debugging on with the below snippet:

    (setq pdf-info-epdfinfo-error-filename "/tmp/pdf-tools-epdfinfo.log" ; for the server process
          pdf-info-log t) ; in the elisp side

To avoid confusion, I suggest to restart Emacs and open a pdf file, and then check these:

  1. If there is a process call epdfinfo running in the background, if it does, it should have the argument of the log file path configured above. And check that log file, see if there is something interesting.
  2. Check *pdf-info-log* buffer in Emacs

Ken

whatacold avatar May 19 '24 01:05 whatacold