Skip to content

Instantly share code, notes, and snippets.

@masak

masak/code.p6 Secret

Created November 4, 2014 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masak/3fb4eb7a42ca8ee0f28d to your computer and use it in GitHub Desktop.
Save masak/3fb4eb7a42ca8ee0f28d to your computer and use it in GitHub Desktop.
Perl 6 code calling Perl 5 code
method generate-pdf($input, :$outfilename) is export {
constant MAX_X = 32;
constant MAX_Y = 24;
constant CANVAS_WIDTH = 640;
constant CANVAS_HEIGHT = 480;
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="{CANVAS_WIDTH}"
height="{CANVAS_HEIGHT}">
END
my $SVG_FOOTER = q:to/END/;
</svg>
END
my @slides = self.slides($input);
for @slides.kv -> $n, $slide {
my $svg_file = "/tmp/awe.svg";
spurt($svg_file, [~] $SVG_HEADER, $SVG_FOOTER);
shell "inkscape --export-pdf=/tmp/slide{$n.fmt("%03d")}.pdf --export-background=white $svg_file";
}
# XXX: Might want to replace this with a call to a Perl 6 PDF library.
# (That we need to write.)
spurt "/tmp/concat.pl", q:to/EOF/;
#!/usr/bin/perl
use Getopt::Long;
use PDF::API2;
use strict;
use warnings;
my @input;
GetOptions(
'i|input=s' => \@input,
'o|output=s' => \(my $output = ''),
);
die "No input files specified."
unless @input;
die "No output files specified."
unless $output;
@input = map { split /,/ } @input;
my $pdf = PDF::API2->new(-file => $output);
my $import_page = 0;
for my $file (@input) {
my $input = PDF::API2->open($file);
for (1..$input->pages) {
$pdf->importpage($input, $_, ++$import_page);
}
}
$pdf->update;
$pdf->end;
EOF
my $inputs = (^@slides).map(-> $n { "/tmp/slide{$n.fmt("%03d")}.pdf" }).join(",");
shell "perl /tmp/concat.pl --input=$inputs --output=$outfilename"
or die "Concat script failed, aborting";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment