mybin

my ~/bin
git clone https://a3nm.net/git/mybin/
Log | Files | Refs | README

commit 88d609be68f886134e85c1ad9c731b4669f49efe
parent b39d78e207dcbebee9ed48dbc0c3be62143a7757
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Wed, 29 Oct 2014 20:05:44 +0100

Merge branch 'master' of gitorious.org:mybin/mybin

Diffstat:
debdiffconf | 3+++
pdf-rect.pl | 42++++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/debdiffconf b/debdiffconf @@ -12,6 +12,9 @@ command -v apt-get >/dev/null 2>&1 || { command -v apt-file >/dev/null 2>&1 || { echo "Please install apt-file: sudo apt-get install apt-file. Aborting." >&2; exit 4; } +command -v realpath >/dev/null 2>&1 || { + echo "Please install realpath: sudo apt-get install realpath. Aborting." >&2; + exit 4; } FILE=$(realpath -m "$1") while read PACKAGE diff --git a/pdf-rect.pl b/pdf-rect.pl @@ -0,0 +1,42 @@ +#!/usr/bin/env perl + +# crop pdf pages to a rectangle +# requires libpdf-api2-perl +# see http://stackoverflow.com/a/8986981 +# usage: ./pdf-rect.pl INFILE OUTFILE X1 X2 Y1 Y2 NUMPAGES +# crop to [X1,X2] times [Y1,Y2] of original page dimensions +# process up to NUMPAGES (all pages if =0) + +use strict; use warnings; +use PDF::API2; +use POSIX; + +my $filename = shift; +my $ofilename = shift; +my $x1 = 1.*(shift); +my $y1 = 1.*(shift); +my $x2 = 1.*(shift); +my $y2 = 1.*(shift); +my $mypage = int(shift); +my $oldpdf = PDF::API2->open($filename); +my $newpdf = PDF::API2->new; +my $limit; +$limit = $oldpdf->pages if $mypage < 1; +$limit = $mypage if $mypage > 0; +for my $page_nb (1..($limit)) { + my ($page, @cropdata); + $page = $newpdf->importpage($oldpdf, $page_nb); + @cropdata = $page->get_mediabox; + print "$page_nb\n"; + print "$cropdata[0] $cropdata[1] $cropdata[2] $cropdata[3]\n"; + $cropdata[0] += $cropdata[2] * $x1; + $cropdata[1] += $cropdata[3] * $y1; + $cropdata[2] *= $x2; + $cropdata[3] *= $y2; + print "$cropdata[0] $cropdata[1] $cropdata[2] $cropdata[3]\n"; + $page->cropbox(@cropdata); + $page->trimbox(@cropdata); + $page->mediabox(@cropdata); +} +$newpdf->saveas($ofilename); +