Hacking Thy Fearful Symmetry

Making Simple Things Easy

February 8th, 2013
Perl
Hai!There is that web page listing a bunch of PDF files. Is there a way toget them all and, while we are at it, collate'em into a single document? Kthxbai
#syntax: perl
#!/usr/bin/env perl 

# usage: $0 <the_url>

use 5.16.0;

use Web::Query;
use LWP::Simple;
use Path::Tiny;
use List::AllUtils qw/ reduce /;
use CAM::PDF;

( reduce { $a->appendPDF($b); $a } @{
    wq( $ARGV[0] )
    ->find('a')
    ->filter( sub {
        $_[1]->attr('href') =~ /\.pdf$/;
    })
    ->map( sub {
        my $temp = Path::Tiny->tempfile;
        $temp->spew( get( $_[1]->attr('href') ) );
        CAM::PDF->new($temp);
    })
}) ->cleanoutput('aggregate.pdf');

You're welcome.

Seen a typo or an error? Submit an edit on GitHub!