doc-view / pdf-view-mode integration (#4)
sportmacher opened 2 months ago

Reported by: Reddit user

Add integration with doc-view-mode (built-in) and optionally pdf-view-mode (pdf-tools) to display PDF pages as images in terminal Emacs via Kitty graphics.

Approach:

  • doc-view-mode already converts PDF pages to PNG — hook into its display path
  • Similar to the image-mode advice pattern: intercept when in terminal mode
  • Need to handle page navigation (next/prev page should update the displayed image)
  • pdf-tools uses its own rendering pipeline — may need separate integration

Considerations:

  • doc-view already works in terminal Emacs (text-based), so this would be an enhancement
  • Page-at-a-time rendering to avoid memory issues with large PDFs
  • sportmacher commented 2 months ago

    doc-view integration implemented with two advice functions:

    1. kitty-gfx--doc-view-mode-p-advice: Bypasses (display-graphic-p) guard in doc-view-mode-p. Checks for conversion tools (gs, mutool, pdftocairo) to ensure the pipeline can actually run.

    2. kitty-gfx--doc-view-insert-image-advice: Intercepts doc-view-insert-image to display page PNGs via Kitty graphics instead of Emacs image specs. Manages a per-buffer overlay (kitty-gfx--doc-view-overlay) so page navigation replaces the previous page image.

    The conversion pipeline (PDF→PNG via Ghostscript/MuPDF) works without GUI — only the display step assumes a graphical frame. Page navigation (next/prev) should work via the existing doc-view-goto-pagedoc-view-insert-image path.

    Byte-compiles and load-tests clean. Needs manual testing with a PDF file.

  • sportmacher changed state to 'In Review' 2 months ago
    Previous Value Current Value
    Open
    In Review
  • sportmacher commented 2 months ago

    Fixed in fec2c3b. PDF pages display via Kitty graphics with page navigation (n/p) and zoom (+/-/0). Centered display. User verified working. Known minor limitation: initial page may briefly flash before centering.

  • sportmacher changed state to 'Closed' 2 months ago
    Previous Value Current Value
    In Review
    Closed
issue 1/1
Type
New Feature
Priority
Normal
Assignees
Not assigned
Issue Votes (0)
Watchers (1)
Reference
cashmere/kitty-graphics#4
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover