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

Wrong type argument in pdf-virtual.el when using cropped pages in virtual mode

Open mochar opened this issue 4 months ago • 0 comments

Describe the bug When viewing a virtual PDF that specifies a cropped region of a page (e.g., (0 0 1 0.9)), Emacs becomes unresponsive and throws a Wrong type argument: number-or-marker-p, edges error. This error appears to originate from an asynchronous callback related to processing page links. The issue does not occur when displaying a full page without a crop region.

Steps to Reproduce the behaviour Create a virtual pdf buffer with the following content, replacing the path with a real PDF file that has links on page 5:

;; %VPDF 1.0
(("/path/to/your/document.pdf" (5 . (0 0 1 0.9))))

Open it: buffer will attempt to render, but will become janky. Error in messages buffer: Error while processing tq callback: Wrong type argument: number-or-marker-p, edges error.

Desktop Please complete the following information:

  • OS: Ubuntu
  • Emacs Version: GNU Emacs 30.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.41, cairo version 1.18.0) of 2025-07-09
  • Poppler Version: i dont know how to get this

Your pdf-tools install Please complete the following information:

 Status: Installed in ‘pdf-tools-20240429.407/’ (unsigned).
Version: 20240429.407
 Commit: 30b50544e55b8dbf683c2d932d5c33ac73323a16

Additional context The bug is in pdf-virtual-pagelinks where pdf-virtual--filter-edges is called with an incorrect :key function ('car). This passes the wrong data structure to the filtering logic, causing a type error when it expects a list of coordinates (edges) but receives a property like (type . goto-dest).

Patch

A one-line fix in pdf-virtual.el resolves the issue by providing the correct key to extract the link's edges.

--- a/pdf-virtual.el +++ b/pdf-virtual.el @@ -1039,4 +1039,4 @@ ,@(pdf-virtual--transform-goto-dest link filename region)))))

  •   (pdf-virtual--filter-edges region (car links) 'car)))))
    
  •   (pdf-virtual--filter-edges region (car links) (lambda (link) (cdr (assq 'edges link))))))))
    

mochar avatar Sep 07 '25 00:09 mochar