Last active
October 23, 2024 03:29
-
-
Save afresh1/ecac56c617306d135497b0c26990c057 to your computer and use it in GitHub Desktop.
Convert an [s5](https://meyerweb.com/eric/tools/s5/) slideshow to PDF with images of the actual slides.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use v5.36; | |
use Firefox::Marionette; | |
use File::Copy qw< cp >; | |
use MIME::Base64 qw< encode_base64 >; | |
my $url = 'https://cvs.afresh1.com/~andrew/talks/2024-EuroBSDcon/'; | |
my $firefox = Firefox::Marionette->new( visible => 1 ); | |
$firefox->resize(1920, 1080); | |
$firefox->go($url); | |
sleep 3; # make sure everything loads | |
for ( my $i = 0; $i < 250; $i++ ) { | |
my $slide = 0; | |
if ( my $e = $firefox->has_id("csHere") ) { | |
$slide = $e->text; | |
} | |
my $image = encode_base64 do { local $/; readline $firefox->selfie }, ''; | |
$firefox->script(<<~"EOL"); | |
const img = document.createElement("img"); | |
img.setAttribute("src", "data:image/png;base64,$image"); | |
document.getElementById("slide$i").prepend(img); | |
EOL | |
last if $slide && $slide == $firefox->has_id("csTotal")->text; | |
$firefox->script("go(1)"); | |
} | |
$firefox->script(<<'EOL'); | |
toggle(); | |
var sheet = document.createElement('style') | |
sheet.innerHTML = ".slide { break-after: always; }"; | |
document.body.appendChild(sheet); | |
EOL | |
cp $firefox->pdf( landscape => 0, size => 'A4' ), "index.pdf"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment