Class: Przn::ScreenshotPdfExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/przn/screenshot_pdf_exporter.rb

Overview

Renders each slide live to the user’s terminal, asks the terminal to save the current pane as a vector PDF via Echoes’ OSC 7772 ‘capture` command, then concatenates the per-slide PDFs into a single multi-page PDF.

Trade-off vs the Prawn-based PdfExporter:

- Pixel-perfect match with what's on screen (gradients, fonts, OSC 66
  sized text, bullet glyphs, the lot) — but vector, so the result is
  small, sharp at any zoom, and text stays selectable.
- Requires running inside a terminal that implements OSC 7772 capture
  to a `.pdf` path (i.e. Echoes). Won't work in CI or any terminal that
  doesn't honor the command.

Echoes-side wire format (independent of przn):

ESC ] 7772 ; capture ; <absolute_path> BEL
On receipt, Echoes saves the current pane to the path. The file
extension picks the format — `.pdf` produces a single-page vector PDF
by replaying the same drawing pipeline into a CGPDFContext instead of
the screen's NSGraphicsContext.

Constant Summary collapse

OSC =
"\e]7772".freeze
BEL =
"\a".freeze
POLL_INTERVAL =

seconds between file-existence checks

0.05
CAPTURE_TIMEOUT =

seconds per slide before giving up

10

Instance Method Summary collapse

Constructor Details

#initialize(presentation, base_dir: '.', theme: nil, terminal: nil) ⇒ ScreenshotPdfExporter

Returns a new instance of ScreenshotPdfExporter.



46
47
48
49
50
51
52
# File 'lib/przn/screenshot_pdf_exporter.rb', line 46

def initialize(presentation, base_dir: '.', theme: nil, terminal: nil)
  @presentation = presentation
  @base_dir = base_dir
  @theme = theme || Theme.default
  @terminal = terminal || Terminal.new
  @renderer = Renderer.new(@terminal, base_dir: base_dir, theme: theme)
end

Instance Method Details

#export(output_path) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/przn/screenshot_pdf_exporter.rb', line 54

def export(output_path)
  require 'hexapdf'

  Dir.mktmpdir('przn-capture') do |dir|
    pdf_paths = capture_all_slides(dir)
    merge_pdfs(pdf_paths, output_path)
  end
end