Created
January 9, 2015 02:23
-
-
Save jonathan-beard/26e4f90ae1abe69021df to your computer and use it in GitHub Desktop.
Stupid simple wrapper around ghostscript to join pdf's, I didn't feel like typing it over and over........
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/env perl | |
use strict; | |
use warnings; | |
## | |
# Stupid simple wrapper around ghostscript to join pdf's | |
## | |
## | |
# check for args < 2, just assume | |
# if 1 (i.e., help,etc.) are included | |
## | |
sub checkhelp($); | |
sub checkexists($); | |
sub checkgs(); | |
## check to see if ghostscript is installed | |
checkgs(); | |
checkhelp( \@ARGV ); | |
## | |
# get files | |
## | |
my $output = $ARGV[ 0 ]; | |
my @filestemp = @ARGV[1..(@ARGV-1)]; | |
my $files = join( ' ', checkexists( \@filestemp )); | |
`gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=$output $files`; | |
exit( 0 ); | |
## | |
# takes in all env args | |
## | |
sub checkhelp( $ ) | |
{ | |
my $arr = shift( @_ ); | |
if( @$arr < 2 ) | |
{ | |
print STDOUT "<outputfile> <joinfiles> [more join files]\n"; | |
exit( 0 ); | |
} | |
return; | |
} | |
## | |
# check for existence of all files, skip otherwise | |
## | |
sub checkexists( $ ) | |
{ | |
my $arr = shift; | |
my @exist; | |
for my $file ( @$arr ) | |
{ | |
chomp( $file ); | |
if( -e $file ) | |
{ | |
print "joining $file\n"; | |
push( @exist, $file ); | |
} | |
else | |
{ | |
print "File \"$file\" doesn't exist, skipping\n"; | |
} | |
} | |
if( @exist < 1 ) | |
{ | |
print( "Not enough files actually exist, try again!\n" ); | |
exit( -1 ); | |
} | |
return( @exist ); | |
} | |
## | |
# see if gs exists | |
## | |
sub checkgs() | |
{ | |
if( `which gs` eq '' ) | |
{ | |
print STDERR "\nERROR: requires ghostscript, install from http://ghostscript.com\n"; | |
exit( -1 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment