in reply to Determining a PDF's orientation
use strict; my $fh; open $fh, "<out.pdf" or die "$!"; binmode( $fh ); my %page; my @kids; my @pages; my $root; my ( $line, $buf ); while( read($fh, $buf, 256) ){ $line .= $buf; my (@lines) = split /endobj/, $line; $line = $lines[-1]; foreach ( @lines ){ my $obj; my $pf = 0; my $cf = 0; my $parent = ""; my $rotation = 0; s/\r|\n/ /g; if ( /(\d+\s+\d+\s+obj)/ ){ $obj = $1; } if ( /Rotate\s+(\d+)/ ){ $rotation = $1; } if ( /Pages\s+/){ $pf = 1; } if ( /Parent\s+(\d+\s+\d+\s+R)/ ){ $parent = $1; } if ( /Catalog/ ){ $cf = 1; } if ( /Pages\s+(\d+\s+\d+\s+R)/ && $cf == 1 ){ push @kids, "1st Pages obj: $1"; } if ( /Kids\s+\[([^\]]+)\]/ && $pf ==1 ){ push @kids, "$obj", $1; } if ( /MediaBox\s+\[([^\]]+)\]/ ){ $page{$obj} = "$1 R:$rotation"; push @pages, $obj; } } } print "$_\n" for @kids; print "$_ $page{$_}\n" for @pages; __END__ Output: 1st Pages obj: 4 0 R <- root pages object 4 0 obj 5 0 R 8 0 R <- Kids of root pages (page 1 is obj 5 0 R ) 5 0 obj 0 0 612 792 R:0 <- ( 0 0 612 792 ) MediaBox 8 0 obj 0 0 612 792 R:0
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Determining a PDF's orientation
by friedo (Prior) on Aug 22, 2005 at 07:13 UTC | |
by JamesNC (Chaplain) on Aug 22, 2005 at 21:29 UTC |