<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#! /bin/sh
eval '(exit $?0)' &amp;&amp; eval 'PERL_BADLANG=x;export PERL_BADLANG;: \
;exec perl -x -S -- "$0" ${1+"$@"};#'if 0;
eval 'setenv PERL_BADLANG x;exec perl -x -S -- "$0" $argv:q;#'.q+
#!perl -w
package Htex::img_bbox;  $0=~/(.*)/s;unshift@INC,'.';do($1);die$@if$@;__END__+if !1;
# This Perl script was generated by JustLib2 at Sun Feb  9 23:57:24 2003.
# Don't touch/remove any lines above; http://www.inf.bme.hu/~pts/justlib
package just; BEGIN{$INC{'just.pm'}='just.pm'}
BEGIN{ $just::VERSION=2 }
sub end(){1}
sub main(){}

BEGIN{$ INC{'integer.pm'}='integer.pm'} {
package integer;
use just;
# by pts@fazekas.hu at Wed Jan 10 12:42:08 CET 2001
sub import   { $^H |= 1 }
sub unimport { $^H &amp;= ~1 }
just::end}

BEGIN{$ INC{'strict.pm'}='strict.pm'} {
package strict;
use just;
# by pts@fazekas.hu at Wed Jan 10 12:42:08 CET 2001
require 5.002;
sub bits {
  (grep{'refs'eq$_}@_ &amp;&amp; 2)|
  (grep{'subs'eq$_}@_ &amp;&amp; 0x200)|
  (grep{'vars'eq$_}@_ &amp;&amp; 0x400)|
  ($@ || 0x602)
}
sub import { shift; $^H |= bits @_ }
sub unimport { shift; $^H &amp;= ~ bits @_ }
just::end}

BEGIN{$ INC{'Pts/string.pm'}='Pts/string.pm'} {
package Pts::string;
# by pts@fazekas.hu at Sat Dec 21 21:32:18 CET 2002
use just;
use integer;
use strict;

#** @param $_[0] a string
#** @param $_[1] index of first bit to return. Bit 128 of byte 0 is index 0.
#** @param $_[2] number of bits to return (&lt;=32)
#** @return an integer (negative on overflow), bit at $_[1] is its MSB
sub get_bits_msb($$$) {
  # assume: use integer;
  my $loop=$_[1];
  my $count=$_[2];
  my $ret=0;
  ($ret+=$ret+(1&amp;(vec($_[0],$loop&gt;&gt;3,8)&gt;&gt;(7-($loop&amp;7)))), $loop++) while $count--!=0;
  $ret
}

#** @param $_[0] a string
#** @return value if $_[0] represents a floating point numeric constant
#**   in the C language (without the LU etc. modifiers) -- or undef. Returns
#**   undef for integer constants
sub c_floatval($) {
  my $S=$_[0];
  no integer; # very important; has local scope
  return 0.0+$S if $S=~/\A[+-]?(?:[0-9]*\.[0-9]+|[0-9]+\.])(?:[eE][+-]?[0-9]+)?\Z(?!\n)/;
  undef
}

#** @param $_[0] a string
#** @return value if $_[0] represents a floating point or integer numeric
#**   constant in the C language (without the LU etc. modifiers) -- or undef
sub c_numval($) {
  my $S=$_[0];
  no integer; # very important; has local scope
  return 0+$S if $S=~/\A[+-]?(?:[0-9]*\.[0-9]+(?:[eE][+-]?[0-9]+)?|[0-9]+\.?)\Z(?!\n)/;
  undef
}

#** @param $_[0] a string
#** @return the integer value of $_[0] in C -- or undef
sub c_intval($) {
  my $S=$_[0];
  my $neg=1;
  $neg=-1 if $S=~s@\A([+-])@@ and '-'eq$1;
  return $neg*hex $1 if $S=~/\A0[xX]([0-9a-fA-F]+)\Z(?!\n)/;
  return $neg*oct $1 if $S=~/\A0([0-7]+)\Z(?!\n)/;
  return $neg*$1     if $S=~/\A([0-9]+)\Z(?!\n)/;
  undef
}

sub import {
  no strict 'refs';
  my $package = (caller())[0];
  shift; # my package
  for my $p (@_ ? @_ : qw{get_bits_msb c_floatval c_numval c_intval}) { *{$package."::$p"}=\&amp;{$p} }
}

just::end}

BEGIN{$ INC{'Htex/dimen.pm'}='Htex/dimen.pm'} {
package Htex::dimen;
# by pts@fazekas.hu at Sat Dec 21 21:26:15 CET 2002
use just;
use integer;
use strict;
use Pts::string qw(c_numval);

my %bp_mul;
{ no integer; %bp_mul=(
  'bp'=&gt;1, # 1 bp = 1 bp (big point)
  'in'=&gt;72, # 1 in = 72 bp (inch)
  'pt'=&gt;72/72.27, # 1 pt = 72/72.27 bp (point)
  'pc'=&gt;12*72/72.27, # 1 pc = 12*72/72.27 bp (pica)
  'dd'=&gt;1238/1157*72/72.27, # 1 dd = 1238/1157*72/72.27 bp (didot point) [about 1.06601110141206 bp]
  'cc'=&gt;12*1238/1157*72/72.27, # 1 cc = 12*1238/1157*72/72.27 bp (cicero)
  'sp'=&gt;72/72.27/65536, # 1 sp = 72/72.27/65536 bp (scaled point)
  'cm'=&gt;72/2.54, # 1 cm = 72/2.54 bp (centimeter)
  'mm'=&gt;7.2/2.54, # 1 mm = 7.2/2.54 bp (millimeter)
) }

#** @param $_[0] a (real or integer) number, optionally postfixed by a
#**        TeX dimension specifier (default=bp)
#** @return the number in bp, or undef
sub dimen2bp($) {
  no integer;
  my $S=$_[0];
  my $mul;
  $mul=$bp_mul{$1} if $S=~s/\s*([a-z][a-z0-9]+)\Z(?!\n)// and exists $bp_mul{$1};
  my $val=c_numval($S);
  $val*=$mul if defined $val and defined $mul;
  $val
}

just::end}

BEGIN{$ INC{'Htex/ImgBBox.pm'}='Htex/ImgBBox.pm'} {
package Htex::ImgBBox;
#
# ImgBBox -- extract file format and size from image files
# by pts@fazekas.hu at Sat Dec  7 21:31:01 CET 2002
# JustLib2 at Sat Dec 21 21:29:21 CET 2002
#
# Dat: we know most of xloadimage-1.16, most of of file(1)-debian-potato,
#   all of sam2p-0.40, all of xv-3.10
# Dat: only in xloadimage: g3Ident,        g3Load,        "G3 FAX Image", (hard to identify file format)
# Dat: only in xloadimage: macIdent,       macLoad,       "MacPaint Image", (stupid, black-white)
# Imp: multiple paper sizes
#
use just;
use integer;
use strict;
use Htex::dimen;
use Pts::string;
# use Data::Dumper;

# Dat: BBoxInfo is a hashref:
# Dat: Info.* keys has FileFormat-dependent meaning (thus Info.depth may have
#      different meanings for different FileFormats)
# { 'FileFormat' =&gt; 'TIFF' # ...
#   'SubFormat' =&gt; 'PPM'
#   'Error' =&gt; 0
#   'LLX' =&gt; ... # lower left x (usually 0)
#   'LLY' =&gt; ... # lower left y (usually 0)
#   'URX' =&gt; ... # upper right x (usually width)
#   'URY' =&gt; ... # upper right y (usually height)
# }

# Dat: \usepackage[hiresbb]{graphicx}
# Dat: pdfTeX graphicx.sty doesn't respect PDF CropBox. For
#      /MediaBox[a b c d], \ht=d, \wd=c, and no overwrite below (a,b)

# ---

#** import will set them
my $have_pdf;
my $have_paper;

#** May moves the file offset, but only relatively (SEEK_CUR).
#** @param $_[0] \*FILE
#** @return BBoxInfo
sub calc($) {
  my $F=$_[0];
  my $dummy;
  my @L;
  my $head;
  #** BBoxInfo to return
  my $bbi={
    # 'FileFormat' =&gt; '.IO.error',
    'FileFormat' =&gt; 'unknown',
    'LLX' =&gt; 0, 'LLY' =&gt; 0, # may be float; in `bp'
    # 'URX' =&gt; 0, 'URY' =&gt; 0 # default: missing; may be float; in `bp'
  };
  binmode $F;
  if (0&gt;read $F, $head, 256) { IOerr: $bbi-&gt;{Error}="IO: $!"; goto done }
  if (length($head)==0) { $bbi-&gt;{FileFormat}='Empty'; return $bbi }
  if ($head=~m@\A\s*/[*]\s+XPM\s+[*]/@) { # XPM
    $bbi-&gt;{FileFormat}='XPM';
    goto IOerr if !seek $F, -length($head), 1;
    select($F); $/='"'; select(STDOUT); &lt;$F&gt;;
    $head=&lt;$F&gt;;
    if ($head!~/\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+).*"\Z(?!\n)/s) { SYerr: $bbi-&gt;{Error}='syntax'; goto done }
    # width, height, length(palette), length(pixelchar)
    $bbi-&gt;{URX}=0+$1;
    $bbi-&gt;{URY}=0+$2;
  } elsif ($head=~m@\A\s*\/\*\s*Format_version=\S*\s+@i) {
    $bbi-&gt;{FileFormat}='XBM1'; # ??
    goto IOerr if 0&gt;read $F, $head, 256-length($head), length($head);
    $head=~s@\*\/.*@@s; # keep only header
    goto SYerr if $head!~m@\s+Width=(\d+)@i;
    $bbi-&gt;{URX}=0+$1;
    goto SYerr if $head!~m@\s+Height=(\d+)@i;
    $bbi-&gt;{URY}=0+$1;
  } elsif ($head=~m@\A(?:/[*].*?[*]/)?\s*#define\s+.*?_width\s+(\d+)\s*#define\s+.*?_height\s+(\d+)\s*@) { # XBM (1)
    # Dat: this `if' must be after checking XPM
    # Imp: recognise a longer comment (that does not fit into $head)
    $bbi-&gt;{FileFormat}='XBM';
    $bbi-&gt;{URX}=0+$1;
    $bbi-&gt;{URY}=0+$2;
  } elsif ($head=~m@\A(?:/[*].*?[*]/)?\s*#define\s+.*?_height\s+(\d+)\s*#define\s+.*?_width\s+(\d+)\s*@) { # XBM (2)
    $bbi-&gt;{FileFormat}='XBM';
    $bbi-&gt;{URX}=0+$2;
    $bbi-&gt;{URY}=0+$1;
  } elsif ($head=~m@\AP([1-6])[\s#]@) { # PNM
    $bbi-&gt;{FileFormat}='PNM';
    my @subformats=qw{- PBM.text PGM.text PPM.text PBM.raw PGM.raw PPM.raw};
    $bbi-&gt;{SubFormat}=$subformats[0+$1];
    goto IOerr if 0&gt;read $F, $head, 1024-length($head), length($head);
    $head=~s@#.*@@g; # remove comments
    goto SYerr if ($head!~/\AP[1-6]\s+(\d+)\s+(\d+)\s/);
    $bbi-&gt;{URX}=0+$1; $bbi-&gt;{URY}=0+$2;
  } elsif (substr($head, 0, 4) eq "MM\000\052" or substr($head, 0, 4) eq "II\052\000") {
    $bbi-&gt;{FileFormat}='TIFF';
    my $LONG="N";
    my $SHORT="n";
    if (substr($head, 0, 1) eq "I") {
      $bbi-&gt;{SubFormat}='LSBfirst';
      $LONG="V"; $SHORT="v";
    } else {
      $bbi-&gt;{SubFormat}='MSBfirst';
    }
    my($dummy,$ifd_ofs)=unpack $LONG.$LONG, $head;
    goto IOerr if !seek $F, $ifd_ofs-length($head), 1;
    my $ifd_len;
    goto IOerr if 2!=read $F, $ifd_len, 2;
    $ifd_len=unpack($SHORT,$ifd_len);
    while ($ifd_len--!=0) {
      my($entry,$tag,$type,$count,$value);
      goto IOerr if 12!=read $F, $entry, 12;
      ($tag,$type,$count)=unpack($SHORT.$SHORT.$LONG, $entry);
      # vvv Dat: we discard tags with $value longer than 4 bytes
      #     Unfortunately BitsPerSample may be such a tag for RGB
         if ($type==3) { $value=unpack($SHORT,substr($entry,8,2)) }
      elsif ($type==4) { $value=unpack($LONG, substr($entry,8,4)) }
      else { $value=vec($entry,8,8); }
         if ($tag==256 and $count==1) { $bbi-&gt;{URX}=$value } # ImageWidth
      elsif ($tag==257 and $count==1) { $bbi-&gt;{URY}=$value } # ImageLength
      elsif ($tag==258 and $count&lt;=2) { $bbi-&gt;{BitsPerSample}=$value }
      elsif ($tag==259) { $bbi-&gt;{"Info.Compression"}=$value }
      elsif ($tag==254) { $bbi-&gt;{"Info.NewSubfileType"}=$value }
      elsif ($tag==255) { $bbi-&gt;{"Info.SubfileType"}=$value }
      elsif ($tag==262) { $bbi-&gt;{"Info.PhotometricInterpretation"}=$value }
      elsif ($tag==263) { $bbi-&gt;{"Info.Thresholding"}=$value }
      elsif ($tag==264) { $bbi-&gt;{"Info.CellWidth"}=$value }
      elsif ($tag==265) { $bbi-&gt;{"Info.CellLength"}=$value }
      elsif ($tag==266) { $bbi-&gt;{"Info.FillOrder"}=$value }
      elsif ($tag==274) { $bbi-&gt;{"Info.Orientation"}=$value }
      elsif ($tag==277) { $bbi-&gt;{SamplesPerPixel}=$value }
      elsif ($tag==278) { $bbi-&gt;{"Info.RowsPerStrip"}=$value }
      elsif ($tag==280) { $bbi-&gt;{"Info.MinSampleValue"}=$value }
      elsif ($tag==281) { $bbi-&gt;{"Info.MaxSampleValue"}=$value }
      elsif ($tag==284) { $bbi-&gt;{"Info.PlanarConfiguration"}=$value }
      elsif ($tag==290) { $bbi-&gt;{"Info.GrayResponseUnit"}=$value }
      elsif ($tag==296) { $bbi-&gt;{"Info.ResolutionUnit"}=$value }
      elsif ($tag==338 and $count&lt;=2) { $bbi-&gt;{"Info.ExtraSamples"}=$value }
    }
  } elsif ($head=~/\A\12[\0-\005]\001[\001-\10]/) {
    $bbi-&gt;{FileFormat}='PCX'; # PC Paintbrush image
    ($dummy,$bbi-&gt;{LLX},$bbi-&gt;{LLY},$bbi-&gt;{URX},$bbi-&gt;{URY})=unpack("A4vvvv",$head);
    $bbi-&gt;{URX}++; $bbi-&gt;{URY}++;
    # pinfo-&gt;w = 1+ (hdr[PCX_XMAXL] + ((int) hdr[PCX_XMAXH]&lt;&lt;8)) - (hdr[PCX_XMINL] + ((int) hdr[PCX_XMINH]&lt;&lt;8));
    # pinfo-&gt;h = 1+ (hdr[PCX_YMAXL] + ((int) hdr[PCX_YMAXH]&lt;&lt;8)) - (hdr[PCX_YMINL] + ((int) hdr[PCX_YMINH]&lt;&lt;8));
  } elsif ($head=~/\AGIF(8[79]a)/) {
    $bbi-&gt;{FileFormat}='GIF';
    $bbi-&gt;{SubFormat}=$1;
    ($dummy,$bbi-&gt;{URX},$bbi-&gt;{URY})=unpack("A6vv",$head);
  } elsif ($head=~/\A(\377+\330)\377/g) {
    $bbi-&gt;{FileFormat}='JPEG';
    die if !seek $F, length($1)-length($head), 1;
    my $id_rgb=0;
    my $had_jfif=0;
    my $cpp;
    my $colortransform=-1; # as defined by the Adobe APP14 marker
    my $tag;
    my $w;
    while (1) {
      goto IOerr if !defined($tag=getc($F)) or ord($tag)!=255;
      1 while defined($tag=getc($F)) and 255==($tag=ord($tag));
      goto IOerr if !defined($tag);
      if ($tag==0xC0) { # SOF0 marker: Baseline JPEG file
        $bbi-&gt;{SubFormat}='Baseline';
        goto IOerr if 2!=read $F, $w, 2;
        $dummy=unpack('n',$w)-2; # length includes itself
        goto IOerr if $dummy&lt;9 or $dummy!=read($F, $w, $dummy);
        $bbi-&gt;{BitsPerSample}=vec($w,0,8);
        $bbi-&gt;{URY}=(vec($w,1,8)&lt;&lt;8)|vec($w,2,8);
        $bbi-&gt;{URX}=(vec($w,3,8)&lt;&lt;8)|vec($w,4,8);
        $cpp=vec($w,5,8);
        goto SYerr if ($dummy-=6)!=3*$cpp or $cpp&gt;6 or $cpp&lt;1;
        $bbi-&gt;{'Info.hvs'}=vec($w,7,8); # HVSamples ?
        $id_rgb=1 if $cpp==3 and $w=~/\A......R..G..B/s;
      } elsif (0xC1&lt;=$tag and $tag&lt;=0xCF and $tag!=0xC4 and $tag!=0xC8) { # SOFn
        $bbi-&gt;{Subformat}="SOF".($tag-0xC0);
        last
      } elsif ($tag==0xD9 or $tag==0xDA) { # EOI or SOS marker; we're almost done
        if (!defined $cpp) {
        } elsif ($cpp==1) {
          $bbi-&gt;{'ColorSpace'}='Gray';
        } elsif ($cpp==3) {
          $bbi-&gt;{'ColorSpace'}='YCbCr';
          if ($had_jfif!=0 or $colortransform==1) {}
          elsif ($colortransform==0 or $id_rgb) { $bbi-&gt;{'ColorSpace'}='RGB' }
        } elsif ($cpp==4) {
          $bbi-&gt;{'ColorSpace'}='CMYK';
          if ($colortransform==2) { $bbi-&gt;{'ColorSpace'}='YCCK' }
        }
        last
      } else {
        # skip over a variable-length block; assumes proper length marker
        # ($tag==0xE0) # APP0: JFIF application-specific marker
        # ($tag==0xEE) # APP14: Adobe application-specific marker
        goto IOerr if 2!=read $F, $w, 2;
        $dummy=unpack('n',$w)-2; # length includes itself
        goto IOerr if $dummy!=read $F, $w, $dummy;
        $colortransform=ord($1) if
          $tag==0xEE and $dummy==12 and $w=~/\AAdobe[\001-\377].....(.)/s;
        $had_jfif=1 if
          $tag==0xE0 and $dummy==14 and $w=~/\AJFIF\0/;
      } ## IF
    } ## WHILE
    $bbi-&gt;{'Info.id_rgb'}=$id_rgb;
    $bbi-&gt;{'Info.had_jfif'}=$had_jfif;
    $bbi-&gt;{'Info.ColorTransform'}=$colortransform;
    $bbi-&gt;{SamplesPerPixel}=$cpp;
  } elsif (substr($head,0,8) eq "\211PNG\r\n\032\n") {
    $bbi-&gt;{FileFormat}='PNG';
    goto SYerr if $head!~/\A........\0\0\0[\15-\77]IHDR/s;
    ($dummy,$bbi-&gt;{URX},$bbi-&gt;{URY})=unpack("A16NN",$head);
  } elsif (substr($head,0,5) eq "%PDF-") {
    $bbi-&gt;{FileFormat}='PDF'; # Adobe Portable Document Format
    # Dat: this routine cannot read encrypted PDF files
    # Dat: example $bbi return: {
    #        'URY' =&gt; 792, 'LLX' =&gt; '0', 'LLY' =&gt; '0', 'URX' =&gt; 612
    #        'FileFormat' =&gt; 'PDF', 'SubFormat' =&gt; '1.2', 'Info.linearized' =&gt; 1, 'Info.binary' =&gt; 'Binary',
    #        'Info.MediaBox' =&gt; [ 0, 0, 612, 792 ],
    #        'Info.CropBox' =&gt; [ 41, 63, 572, 729 ],
    #      };
    # Dat: $bbi-&gt;{'Info.num_pages'} is not reported for Linearized PDF.
    # Imp: report much more specific error messages
    # Imp: better distinguish between IOerr and SYerr
    $bbi-&gt;{SubFormat}=$1 if $head=~/\A%PDF-([\d.]+)/;
    $bbi-&gt;{'Info.binary'}=($head=~/\A[^\r\n]+[\r\n]+[ -~]*[^\n\r -~]/) ? 'Binary' : 'Clean7Bit';
    # die $have_pdf;
    goto done if !$have_pdf;
    # if ($head=~m@\A(?:%[^\r\n]*[\r\n])*.{0,40}/Linearized@s and $head=~m@\A(?:%[^\r\n]*[\r\n])*.{0,200}/O\s+(\d+)@s) {
    my $had_pdfboxes=($head=~m@/Type\s*/pdfboxes%@); # `%' is important
    $head=pdf_rewrite($head,1);
    my $page1obj;
    $bbi-&gt;{'Info.linearized'}=0;
    $bbi-&gt;{'Info.pdfboxes'}=0;
    if (defined $head) {
      $head=~s@\bendobj.*@@s;
      if ($had_pdfboxes) {
        # a hint of very strict format, by 
        $head="";
        goto IOerr if !seek($F, 0, 0) or 20&gt;read($F, $head, 2048);
        goto SYerr unless $head=~/\d\s+\d+\s+obj\s*(.*?)\bendobj/s;
        $head=$1; goto SYerr unless $head=~m@/Type\s*/pdfboxes%@;
        while ($head=~m@^\s*/(\w+Box)\s*\[\s*(-?[\d.]+)\s+(-?[\d.]+)\s+(-?[\d.]+)\s+(-?[\d.]+)\s*\]@gm) {
          ## print "($1) ($2) ($3) ($4) ($5)\n";
          ($bbi-&gt;{LLX},$bbi-&gt;{LLY},$bbi-&gt;{URX},$bbi-&gt;{URY})=($2,$3,$4,$5) if $1 eq 'MediaBox';
          $bbi-&gt;{"Info.$1"}=[$2,$3,$4,$5];
        }
        $bbi-&gt;{'Info.pdfboxes'}=1;
        goto done;
      } elsif ($head=~m@/Linearized\s+@ and $head=~m@/O\s+(\d+)@) {
        $bbi-&gt;{'Info.linearized'}=1;
        $page1obj=$bbi-&gt;{'Info.page1obj'}=$1+0;
      }
    }
    goto IOerr if !seek $F, -1024, 2 and !seek $F, 0, 0;
    goto IOerr if 1&gt;read $F, $head, 1024;
    goto SYerr if $head!~/startxref\s+(\d+)\s*%%EOF\s*\Z(?!\n)/
              and $head!~/startxref\s+(\d+)\s*%%EOF/;
    # ^^^ Dat: some PDF files contain binary junk at the end
    my $xref_ofs=$1+0;
    goto IOerr if !seek $F, $xref_ofs, 0;
    # die pdf_read_obj($F);
    my $xref=[];
    my $trailer=pdf_read_xref($F,$xref);
    goto SYerr if !defined $trailer;
    
    my $pages;
    my $type;
    if (!defined $page1obj) { do_pdf_slow:
      ## die $trailer;
      ## die pdf_ref($F,$xref,37550,0);
      ## die pdf_get($F,$xref,$trailer,'/ID');
      ## die pdf_get($F,$xref,$trailer,'/Root');
      ## die pdf_get($F,$xref,$trailer,'/Size');
      ## die pdf_get($F,$xref,$trailer,'/Sizez');

      my $root=pdf_get($F,$xref,$trailer,'/Root');
      goto IOerr if !defined $root; goto SYerr if !length $root;
      $type=pdf_get($F,$xref,$root,'/Type');
      goto IOerr if !defined $type; goto SYerr if $type ne ' /Catalog';
      # die $root;
      # vvv Dat: reading xref for /Pages in a linearized PDF is quite slow
      $pages=pdf_get($F,$xref,$root,'/Pages');
      goto IOerr if !defined $pages; goto SYerr if !length $pages;
      ## die $pages;
      my $kids;
      
      while (1) {
        $type=pdf_get($F,$xref,$pages,'/Type');
        goto IOerr if !defined $type;
        last if $type ne ' /Pages';
        pdf_get_boxes($F, $xref, $pages, $bbi);
        $kids=pdf_get($F,$xref,$pages,'/Kids');
        goto IOerr if !defined $kids; goto SYerr if !length $kids;
        ## die $kids;
        $pages=pdf_get($F,$xref,$kids,0);
        ## die $pages;
        goto IOerr if !defined $pages; goto SYerr if !length $pages;
      }
      goto SYerr if $type ne ' /Page';
      # Dat: cannot set $page1obj properly here, because it might be a direct object
      $bbi-&gt;{'Info.page1obj'}=$Htex::PDFread::pdf_last_ref0;
    } else {
      # die $page1obj;
      $pages=pdf_ref($F, $xref, $page1obj, 0);
      goto IOerr if !defined $pages;
      $type=pdf_get($F,$xref,$pages,'/Type');
      goto IOerr if !defined $type;
      goto SYerr if $type ne ' /Page';
      my $mediabox=pdf_get($F,$xref,$pages,'/MediaBox');
      goto IOerr if !defined $mediabox;
      goto do_pdf_slow if !length $mediabox;
    }
    pdf_get_boxes($F, $xref, $pages, $bbi);
  } elsif (substr($head,0,4) eq "%!PS") {
    # Dat: the user should not trust Val.languagelevel blindly. There are far
    #      too many PS files hanging around that do not conform to any standard.
    $bbi-&gt;{FileFormat}=$bbi-&gt;{SubFormat}=
      ($head=~/\A[^\n\r]*?\bEPSF-/) ? "EPS" : "PS";
    goto SYerr if $head!~s@[^\n\r]*[\n\r]+@@;
    # vvv Dat `+' is `or' with full boolean eval
    until ($head=~s@[\n\r]%%EndComments.*@@s + $head=~s@[\n\r](?:[^%]|%[^%]).*@@s) {
      goto IOerr if 0&gt;read $F, $head, 1024, length($head);
    }
    my $headlen=length($head);
    $head=~s@(?:\r\n|\n\r|[\n\r])@\n@g; # uniformize newlines
    $head=~s@\s*\n%%[+]\s*@ @g; # unify line continuations
    my %H;
    my $had_hires=0; # HiresBoundingBox overrides normal
    my $val;
    while ($head=~/^%%([A-Za-z]+):?\s*((?:.*\S)?)/gm) {
      next if $2 ne '(atend)';
      # read additional ADSC comments from the last 1024 bytes of the file
      goto IOerr if !seek $F, -1024, 2 and !seek $F, 0, 0; # Dat: seek to EOF
      $dummy=tell $F;
      goto IOerr if $dummy&lt;$headlen and $headlen-$dummy!=read $F, $val, $headlen-$dummy;
      goto IOerr if 0&gt;read $F, $val, 1024;
      $val=~s@(?:\r\n|\n\r|[\n\r])@\n@g; # uniformize newlines
      $val=~s@\s*\n%%[+]\s*@ @g; # unify line continuations
      $val=~s@^(?:[^%]|%[^%]).*\n?@@mg; # remove non-DSC lines
      # vvv Dat: appending is schemantically correct here
      $head.="\n$val"; last
    }
    while ($head=~/^%%([A-Za-z]+):?[ \t]*((?:.*\S)?)/gm) { # iterate over Adobe DSC comments
      $dummy=lc($1); $val=$2;
      next if $dummy eq 'enddata' or $dummy eq 'trailer' or $dummy eq 'eof';
      $bbi-&gt;{"Val.$dummy"}=$2;
      if ($dummy eq 'documentdata') {
        $dummy=lc($2);
        $bbi-&gt;{'Info.binary'}='Clean7Bit' if $dummy eq 'clean7bit';
        $bbi-&gt;{'Info.binary'}='Clean8Bit' if $dummy eq 'clean8bit';
        $bbi-&gt;{'Info.binary'}='Binary' if $dummy eq 'binary';
      } elsif ($dummy eq 'creator' and $val=~/\bMetaPost\b/) {
        $bbi-&gt;{FileFormat}='EPS';
        $bbi-&gt;{SubFormat}='MPS'; # useful for graphicP.sty
      } elsif ($dummy eq 'boundingbox' and $val=~/\A([+-]?\d+)\s+([+-]?\d+)\s+([+-]?\d+)\s+([+-]?\d+)\Z(?!\n)/) {
        ($bbi-&gt;{LLX},$bbi-&gt;{LLY},$bbi-&gt;{URX},$bbi-&gt;{URY})=($1+0,$2+0,$3+0,$4+0) if !$had_hires;
      } elsif (($dummy eq 'hiresboundingbox' or $dummy eq 'exactboundingbox')
          and $val=~/\A([+-]?[0-9eE.-]+)\s+([+-]?[0-9eE.-]+)\s+([+-]?[0-9eE.-]+)\s+([+-]?[0-9eE.-]+)\Z(?!\n)/
          and  defined c_numval($1) and defined c_numval($2) and defined c_numval($3) and defined c_numval($4)
         ) {
        # Dat: capitalized names are: HiResBoundingBox, ExactBoundingBox
        no integer;
        ($bbi-&gt;{LLX},$bbi-&gt;{LLY},$bbi-&gt;{URX},$bbi-&gt;{URY})=($1+0,$2+0,$3+0,$4+0);
        $had_hires=1;
      }
    }
  } elsif ($head=~/\AFORM....ILBMBMHD/s) {
    $bbi-&gt;{FileFormat}='LBM';
    ($dummy,$bbi-&gt;{URX},$bbi-&gt;{URY})=unpack("A20nn",$head);
  } elsif ($head=~/\AFORM....(RGB[8N])/s) { # /etc/magic
    $bbi-&gt;{FileFormat}="IFF.$1";
    # dimension info not available
  } elsif ($head=~/\ABM....\0\0\0\0....[\014-\177]\0\0\0/s) { # PC bitmaps (OS/2, Windoze BMP files)  (Greg Roelofs, newt@uchicago.edu)
    $bbi-&gt;{FileFormat}='BMP';
    if (vec($head,14,8)==12) {
      $bbi-&gt;{SubFormat}='OS/2 1.x';
      ($dummy,$bbi-&gt;{URX},$bbi-&gt;{URY})=unpack("A18vv",$head);
    } elsif (vec($head,14,8)==64) {
      $bbi-&gt;{SubFormat}='OS/2 2.x';
      ($dummy,$bbi-&gt;{URX},$bbi-&gt;{URY})=unpack("A18vv",$head);
    } elsif (vec($head,14,8)==40) {
      $bbi-&gt;{SubFormat}='Windows';
      ($dummy,$bbi-&gt;{URX},$bbi-&gt;{URY},$dummy,$bbi-&gt;{"Info.depth"})=unpack("A18VVvv",$head);
    } else { goto SYerrr }
    #0	  string	BM		PC bitmap data
    #&gt;14  leshort	12		\b, OS/2 1.x format
    #&gt;&gt;18 leshort	x		\b, %d x
    #&gt;&gt;20 leshort	x		%d
    #&gt;14  leshort	64		\b, OS/2 2.x format
    #&gt;&gt;18 leshort	x		\b, %d x
    #&gt;&gt;20 leshort	x		%d
    #&gt;14  leshort	40		\b, Windows 3.x format
    #&gt;&gt;18 lelong	x		\b, %d x
    #&gt;&gt;22 lelong	x		%d x
    #&gt;&gt;28 leshort	x		%d
  } elsif (substr($head,0,10) eq "\367\002\001\203\222\300\34;\0\0") { FF__DVI:
    $bbi-&gt;{FileFormat}='DVI';
    # read 1st page of the DVI file, look for TeX \special{papersize=21cm,29.7cm},
    # as understood by dvips and xdvi
    ($dummy,$bbi-&gt;{'Info.version_id'},$bbi-&gt;{'Info.numerator'},
      $bbi-&gt;{'Info.denominator'},$bbi-&gt;{'Info.magnification'})=unpack('CCNNN',$head);
    goto IOerr if !seek $F, 15-length($head), 1;
    $dummy=vec($head,14,8);
    goto IOerr if $dummy!=read $F, $bbi-&gt;{'Info.jobname'}, $dummy;
    my($tag,$action);
    my @actions=(0)x256; # skip that char
    $actions[139]=15; # Bop
    @actions[248,249,140,223]=(16,16,16,16); # stop parsing file
    @actions[128,133,143,148,153,157,162,167,235]=(1,1,1,1,1,1,1,1,1); # read 1 extra bytes
    @actions[129,134,144,149,154,158,163,168,236]=(2,2,2,2,2,2,2,2,2); # read 2 extra bytes
    @actions[130,135,145,150,155,159,164,169,237]=(3,3,3,3,3,3,3,3,3); # read 2 extra bytes
    @actions[131,136,146,151,156,160,165,170,238]=(4,4,4,4,4,4,4,4,4); # read 2 extra bytes
    @actions[132,137]=(8,8); # read 8 extra bytes
    @actions[243,244,245,246]=(17,18,19,20); # Fnt_def
    @actions[239,240,241,242]=(33,34,35,26); # Special (XXX)
    while (1) {
      goto IOerr if !defined($tag=getc($F)); # Dat: EOF is error
      $tag=$actions[ord($tag)];
      if ($tag==0) {
      } elsif ($tag==16) {
        last
      } elsif ($tag==15) { # Bop
        last if exists $bbi-&gt;{'Info.page1_nr'};
        goto IOerr if 44!=read $F, $dummy, 44;
        $bbi-&gt;{'Info.page1_nr'}=unpack "N", $dummy;
      } else {
        # read number of ($tag&amp;15) bytes in MSBfirst byte order
        $dummy="\0\0\0\0";
        goto IOerr if ($tag&amp;15)!=read $F, $dummy, ($tag&amp;15), 4;
        $dummy=unpack("N",substr($dummy,-4));
        if ($tag&gt;=33) { # Special
          goto IOerr if $dummy!=read $F, $tag, $dummy;
          @L=split /\s*=\s*/, $tag, 2;
          if ($#L) {
            $bbi-&gt;{"Val.$L[0]"}=$L[1];
            if ($L[0] eq 'papersize') {
              @L=split /,/, $L[1], 2;
              $bbi-&gt;{URX}=Htex::dimen::dimen2bp($L[0]);
              $bbi-&gt;{URY}=Htex::dimen::dimen2bp($L[1]);
              if (!defined $bbi-&gt;{URX} or !defined $bbi-&gt;{URY}) {
                delete $bbi-&gt;{URX}; delete $bbi-&gt;{URY};
              }
            }
          } else { $bbi-&gt;{'Info.special'}=$tag; }
        } elsif ($tag&gt;=17) { # Fnt_def
          goto IOerr if 14!=read $F, $tag, 14;
          $dummy=vec($tag,12,8)+vec($tag,13,8);
          goto IOerr if $dummy!=read $F, $tag, $dummy;
        }
      } # IF 
    } # WHILE
  } elsif ($head=~/\Aid=ImageMagick\r?\n/) {
    $bbi-&gt;{FileFormat}='MIFF';
    # goto IOerr if 0&gt;read $F, $head, 128-length($head), length($head);
    goto SYerr if $head!~/\bcolumns=(\d+)\s+rows=(\d+)/;
    $bbi-&gt;{URX}=0+$1; $bbi-&gt;{URY}=0+$2;
  } elsif (substr($head,0,3) eq 'FWS') {
    $bbi-&gt;{FileFormat}='SWF'; # Macromedia ShockWave Flash
    my $nbits=get_bits_msb($head, 64, 5);
    no integer;
    $bbi-&gt;{URX}=get_bits_msb($head, 69+  $nbits, $nbits)/20.0;
    $bbi-&gt;{LLX}=get_bits_msb($head, 69,          $nbits)/20.0;
    $bbi-&gt;{URY}=get_bits_msb($head, 69+3*$nbits, $nbits)/20.0;
    $bbi-&gt;{LLY}=get_bits_msb($head, 69+2*$nbits, $nbits)/20.0;
  } elsif (substr($head,0,14) eq "gimp xcf file\0") { # GIMP XCF image data
    $bbi-&gt;{SubFormat}='version.000';
   do_XCF:
    $bbi-&gt;{FileFormat}='XCF';
    ($dummy,$bbi-&gt;{URX},$bbi-&gt;{URY},$dummy)=unpack("A14NNN", $head);
       if ($dummy==0) { $bbi-&gt;{ColorSpace}='RGB' }
    elsif ($dummy==1) { $bbi-&gt;{ColorSpace}='Gray' }
    elsif ($dummy==2) { $bbi-&gt;{ColorSpace}='Indexed' }
  } elsif ($head=~/\Agimp xcf v(\d\d\d)\0/) {
    $bbi-&gt;{SubFormat}="version.$1";
    goto do_XCF;
  } elsif ($head=~/\A\0\0\001\0[\001-\50]\0/) { # Windows ICO icon
    $bbi-&gt;{FileFormat}='ICO';
    # An .ico file may contain multiple icons (hence [\001-50]); we report the
    # properties of the very first one. Code based on ImageMagick.
    # Imp: WinXP True color icons
    ($dummy,$bbi-&gt;{URX},$bbi-&gt;{URY},$bbi-&gt;{'Info.colors'},$bbi-&gt;{'Info.reserved'},
     $bbi-&gt;{'Info.planes'},$bbi-&gt;{BitsPerSample})=unpack("A6CCCCvv", $head);
    # more precisely: BitsPerSample is bits per pixel;
    # Dat: Info.reserved, BitsPerSample and Info.planes are often 0
  } elsif (substr($head,0,4)eq"8BPS") { # PSD image data (Adobe Photoshop bitmap)
    # based on PHP 4.2 image.c; untested
    $bbi-&gt;{FileFormat}='PSD';
    ($dummy,$bbi-&gt;{URY},$bbi-&gt;{URX})=unpack("A14NN",$head);
  } elsif (substr($head,0,8) eq "\%bitmap\0") { # Fuzzy Bitmap (FBM) image; untested
    $bbi-&gt;{FileFormat}='FBM';
    @L=unpack("A8A8A8A8A8A8A12A12A12A12A80A80",$head); # &lt;=256 chars OK
    for (@L) { s@\0.*@@s } # make strings null-terminated
    $bbi-&gt;{"Info.credits"}=pop(@L); # string
    $bbi-&gt;{"Info.title"}=pop(@L); # string
    goto SYerr if !defined ($bbi-&gt;{aspect}=c_numval(pop(@L)));
    shift(@L); # magic
    for my $item (@L) { goto SYerr if !defined($item=c_intval($item)) }
    ( $bbi-&gt;{URX},$bbi-&gt;{URY},$bbi-&gt;{"Info.planes"},$bbi-&gt;{"Info.bits"},
      $bbi-&gt;{"Info.physbits"},$bbi-&gt;{"Info.rowlen"},$bbi-&gt;{"Info.plnlen"},
      $bbi-&gt;{"Info.clrlen"})=@L;
    #    char    cols[8];                /* Width in pixels */
    #    char    rows[8];                /* Height in pixels */
    #    char    planes[8];              /* Depth (1 for B+W, 3 for RGB) */
    #    char    bits[8];                /* Bits per pixel */
    #    char    physbits[8];            /* Bits to store each pixel */
    #    char    rowlen[12];             /* Length of a row in bytes */
    #    char    plnlen[12];             /* Length of a plane in bytes */
    #    char    clrlen[12];             /* Length of colormap in bytes */
    #    char    aspect[12];             /* ratio of Y to X of one pixel */
  } elsif (substr($head,0,4)eq"\x59\xa6\x6a\x95") { # Sun raster images; untested
    $bbi-&gt;{FileFormat}='SunRaster';
    ($dummy,$bbi-&gt;{URX},$bbi-&gt;{URY})=unpack("NNN",$head);
    #0		belong		0x59a66a95	Sun raster image data
    #&gt;4		belong		&gt;0		\b, %d x
    #&gt;8		belong		&gt;0		%d,
    #&gt;12	belong		&gt;0		%d-bit,
    ##&gt;16	belong		&gt;0		%d bytes long,
    #&gt;20	belong		0		old format,
    ##&gt;20	belong		1		standard,
    #&gt;20	belong		2		compressed,
    #&gt;20	belong		3		RGB,
    #&gt;20	belong		4		TIFF,
    #&gt;20	belong		5		IFF,
    #&gt;20	belong		0xffff		reserved for testing,
    #&gt;24	belong		0		no colormap
    #&gt;24	belong		1		RGB colormap
    #&gt;24	belong		2		raw colormap
    #&gt;28	belong		&gt;0		colormap is %d bytes long
  } elsif (substr($head,0,4)eq"\xf1\x00\40\xbb") {
    $bbi-&gt;{FileFormat}='CMUWM'; # from xloadimage; untested
    ($dummy,$bbi-&gt;{URX},$bbi-&gt;{URY},$bbi-&gt;{"Info.depth"})=unpack("NNNn",$head);
  } elsif (substr($head,0,4) eq "\361\0\100\273") { # CMU window manager raster image data
    # from xvl untested
    $bbi-&gt;{FileFormat}='CMUWM';
    ($dummy,$bbi-&gt;{URX},$bbi-&gt;{URY},$bbi-&gt;{'Info.num_bits'})=unpack("VVVV",$head);
  } elsif (substr($head,0,2)eq"\x52\xCC") { # Utah Raster Toolkit RLE images; untested
    $bbi-&gt;{FileFormat}='RLE'; # from xloadimage
    ($dummy,$bbi-&gt;{URX},$bbi-&gt;{URY},$bbi-&gt;{LLX},$bbi-&gt;{LLY})=unpack("A6vvvv",$head);
    $bbi-&gt;{BitsPerSample}=vec($head,12,8)/vec($head,11,8);
    $bbi-&gt;{SamplesPerPixel}=vec($head,11,8);
    #0		leshort		0xcc52		RLE image data,
    #&gt;6		leshort		x		%d x
    #&gt;8		leshort		x		%d
    #&gt;2		leshort		&gt;0		\b, lower left corner: %d
    #&gt;4		leshort		&gt;0		\b, lower right corner: %d
    #&gt;10	byte&amp;0x1	=0x1		\b, clear first
    #&gt;10	byte&amp;0x2	=0x2		\b, no background
    #&gt;10	byte&amp;0x4	=0x4		\b, alpha channel
    #&gt;10	byte&amp;0x8	=0x8		\b, comment
    #&gt;11	byte		&gt;0		\b, %d color channels
    #&gt;12	byte		&gt;0		\b, %d bits per pixel
    #&gt;13	byte		&gt;0		\b, %d color map channels
  } elsif (substr($head,0,32)eq"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377") { # Kodak Photograph on CD Image
    # derived from xloadimage; untested
    $dummy=3587-length($head);
    goto IOerr if $dummy=read $F, $head, $dummy, length($head);
    goto SYerr if substr($head,2048,7) ne "PCD_IPI";
    $bbi-&gt;{FileFormat}='PCD';
    # vvv funny: an image format with fixed (hard-wired) image size
    if ((vec($head,3586,8)&amp;1)!=0) { ($bbi-&gt;{URY},$bbi-&gt;{URX})=(768,512) }
                             else { ($bbi-&gt;{UXY},$bbi-&gt;{URY})=(768,512) }
  } elsif ($head=~/\A\0\0..\0\0\0[\001-\50]\0\0\0[\0-\002]\0\0\0([\001-\77])/s) {
    $bbi-&gt;{FileFormat}='XWD';
    $bbi-&gt;{SubFormat}='MSBfirst';
    $bbi-&gt;{'Info.depth'}=ord($1);
    ($dummy,$bbi-&gt;{URX},$bbi-&gt;{URY})=unpack("A16NN",$head);
  } elsif ($head=~/\A..\0\0[\001-\50]\0\0\0[\0-\002]\0\0\0([\001-\77])\0\0\0/s) {
    $bbi-&gt;{FileFormat}='XWD';
    $bbi-&gt;{SubFormat}='LSBfirst';
    $bbi-&gt;{'Info.depth'}=ord($1);
    ($dummy,$bbi-&gt;{URX},$bbi-&gt;{URY})=unpack("A16VV",$head);
  } elsif ($head=~/\A\0\001\0[\010-\377](?:\0.|\001\0)\0.....(?:[\001-\37].|\0[^\0]|\40\0){2}/s) { # GEM Bit image
    # from xloadimage; untested
    $bbi-&gt;{FileFormat}='GEM';
    ($dummy,$bbi-&gt;{'Info.hlen'},$bbi-&gt;{'Info.colors'},$bbi-&gt;{'Info.patlen'},
     $bbi-&gt;{URX},$bbi-&gt;{URY},$bbi-&gt;{'Info.llen'},$bbi-&gt;{'Info.lines'})=unpack("nnnnnnnn",$head);
  } elsif ($head=~/\A....\0\0\0\004....\0\0[\0-\001].\0\0[\0-\003]./s) { # McIDAS areafile
    # from xloadimage; untested
    $bbi-&gt;{FileFormat}='McIDAS';
    $bbi-&gt;{SubFormat}='MSBfirst';
    ($dummy,$bbi-&gt;{URY},$bbi-&gt;{URX})=unpack("A32NN",$head);
  } elsif ($head=~/\A....\004\0\0\0.....[\0-\001]\0\0.[\0-\003]\0\0/s) { # McIDAS areafile
    # from xloadimage; untested
    $bbi-&gt;{FileFormat}='McIDAS';
    $bbi-&gt;{SubFormat}='LSBfirst';
    ($dummy,$bbi-&gt;{URY},$bbi-&gt;{URX})=unpack("A32VV",$head);
  } elsif ($head=~/\AVIEW/) {
    # from xv; untested
    $dummy="NNNNNN"; $bbi-&gt;{SubFormat}='MSBfirst';
   do_PM:
    $bbi-&gt;{FileFormat}='PM';
    ($dummy,$bbi-&gt;{'Info.num_planes'},$bbi-&gt;{URX},$bbi-&gt;{URY},
     $bbi-&gt;{'Info.num_bands'}, $bbi-&gt;{'Info.pixel_format'})=unpack($dummy,$head);
  } elsif ($head=~/\AWEIV/) {
    $dummy="VVVVVV"; $bbi-&gt;{SubFormat}='LSBfirst';
    goto do_PM;
  } elsif ($head=~/\A\001\332/) { # SGI 'rgb' image data
    $bbi-&gt;{SubFormat}='MSBfirst'; $dummy="nCCnnnn";
   do_SGI:
    $bbi-&gt;{FileFormat}='SGI'; # from xv IRIS; untested
    ($dummy,$bbi-&gt;{'Info.compression'},$bbi-&gt;{'Info.precision'},$bbi-&gt;{'Info.dimension'},
     $bbi-&gt;{URX},$bbi-&gt;{URY},$bbi-&gt;{SamplesPerPixel})=unpack($dummy,$head);
       if ($bbi-&gt;{'Info.compression'}==0) { $bbi-&gt;{'Info.compression'}='None' }
    elsif ($bbi-&gt;{'Info.compression'}==1) { $bbi-&gt;{'Info.compression'}='RLE' }
    $dummy=substr($head,80);
    $bbi-&gt;{'Info.comment'}=$1 if $dummy=~m@\A([^\0])\0@s;
    # Dat: Info.dimension is 2 or 3
    ## See http://reality.sgi.com/grafica/sgiimage.html
  } elsif ($head=~/\A\332\001/) { # SGI 'rgb' image data
    $bbi-&gt;{SubFormat}='MSBfirst'; $dummy="vCCvvvvv";
    goto do_SGI;
  } elsif (substr($head,0,9) eq "SIMPLE  =") {
    $bbi-&gt;{FileFormat}='FITS';
    while ($head!~/\bEND/) {
      goto IOerr if 1&gt;read $F, $head, 1024, length($head);
    }
    $bbi-&gt;{'Info.bits_per_pixel'}=$1 if $head=~/\bBITPIX\s*=\s*(\d+)/;
    $bbi-&gt;{'Info.num_axis'}=$1 if $head=~/\bNAXIS\s*=\s*(\d+)/;
    $bbi-&gt;{URX}=$1 if $head=~/\bNAXIS1\s*=\s*(\d+)/;
    $bbi-&gt;{URY}=$1 if $head=~/\bNAXIS2\s*=\s*(\d+)/;
    $bbi-&gt;{'Info.depth'}=$1 if $head=~/\bNAXIS3\s*=\s*(\d+)/;
    $bbi-&gt;{'Info.data_max'}=$1 if $head=~/\bDATAMAX\s*=\s*(\d+)/;
    $bbi-&gt;{'Info.data_min'}=$1 if $head=~/\bDATAMIN\s*=\s*(\d+)/;
    # Dat: it would be quite hard to extract the dimensions...
    ## FITS is the Flexible Image Transport System, the de facto standard for
    ## data and image transfer, storage, etc., for the astronomical community.
    ## (FITS floating point formats are big-endian.)
    #0	string	SIMPLE\ \ =	FITS image data
    #&gt;109	string	8		\b, 8-bit, character or unsigned binary integer
    #&gt;108	string	16		\b, 16-bit, two's complement binary integer
    #&gt;107	string	\ 32		\b, 32-bit, two's complement binary integer
    #&gt;107	string	-32		\b, 32-bit, floating point, single precision
    #&gt;107	string	-64		\b, 64-bit, floating point, double precision
  } elsif ($head=~/\A(?:NJPL1I|CCSD3Z|LBLSIZE=)/) {
    # from xv, imagemagick; untested
    $bbi-&gt;{FileFormat}='VICAR';
    while ($head!~/\bEND/) {
      goto IOerr if 1&gt;read $F, $head, 1024, length($head);
    }
    $bbi-&gt;{URX}=$1 if $head=~/\b(?:IMAGE_LINES|LINES|NL)\s*=\s*(\d+)/;
    $bbi-&gt;{URY}=$1 if $head=~/\b(?:LINE_SAMPLES|NS)\s*=\s*(\d+)/;
    ##------------------------------------------------------------------------------
    ## vicar:  file(1) magic for VICAR files.
    ##
    ## From: Ossama Othman &lt;othman@astrosun.tn.cornell.edu
    ## VICAR is JPL's in-house spacecraft image processing program
    ## VICAR image
    #0	string	LBLSIZE=	VICAR image data
    #&gt;32	string	BYTE		\b, 8 bits  = VAX byte
    #&gt;32	string	HALF		\b, 16 bits = VAX word     = Fortran INTEGER*2
    #&gt;32	string	FULL		\b, 32 bits = VAX longword = Fortran INTEGER*4
    #&gt;32	string	REAL		\b, 32 bits = VAX longword = Fortran REAL*4
    #&gt;32	string	DOUB		\b, 64 bits = VAX quadword = Fortran REAL*8
    #&gt;32	string	COMPLEX		\b, 64 bits = VAX quadword = Fortran COMPLEX*8
    ## VICAR label file
    #43	string	SFDU_LABEL	VICAR label file
  } elsif (substr($head,0,4) eq "IT01" or substr($head,0,4) eq "IT02") { # untested
    $bbi-&gt;{FileFormat}='FIT'; # do not cunfuse FIT and FITS
    ($dummy,$bbi-&gt;{URX},$bbi-&gt;{URY},$bbi-&gt;{'Info.num_bits'})=unpack("NNNN",$head);
  } elsif (substr($head,0,4) eq "#FIG") {
    $bbi-&gt;{FileFormat}='FIG';
    $bbi-&gt;{SubFormat}=$1 if $head=~/\A....[ \t]+(\S+)/s;
    ## FIG (Facility for Interactive Generation of figures), an object-based format
    ## (as handled by xfig). There is no size information, fig2dev saves bounding
    ## box as EPS
    #0	string		#FIG		FIG image text
    #&gt;5	string		x		\b, version %.3s

## These file formats below are known to the Debian potato file(1) command,
## but the magic(5) file doesn't tell us how to extract size information
##
## NITF is defined by United States MIL-STD-2500A
#0	string	NITF	National Imagery Transmission Format
#&gt;25	string	&gt;\0	dated %.14s
#
## NIFF (Navy Interchange File Format, a modification of TIFF) images
#0	string		IIN1		NIFF image data
## ITC (CMU WM) raster files.  It is essentially a byte-reversed Sun raster,
## 1 plane, no encoding.
## Artisan
#0	long		1123028772	Artisan image data
#&gt;4	long		1		\b, rectangular 24-bit
#&gt;4	long		2		\b, rectangular 8-bit with colormap
#&gt;4	long		3		\b, rectangular 32-bit (24-bit with matte)
#
#
## PHIGS
#0	string		ARF_BEGARF		PHIGS clear text archive
#0	string		@(#)SunPHIGS		SunPHIGS
## version number follows, in the form m.n
##&gt;40	string		SunBin			binary
##&gt;32	string		archive			archive
##
## GKS (Graphics Kernel System)
#0	string		GKSM		GKS Metafile
#&gt;24	string		SunGKS		\b, SunGKS
#
## CGM image files
#0	string		BEGMF		clear text Computer Graphics Metafile
## XXX - questionable magic
#0	beshort&amp;0xffe0	0x0020		binary Computer Graphics Metafile
#0	beshort		0x3020		character Computer Graphics Metafile
#
## MGR bitmaps  (Michael Haardt, u31b3hs@pool.informatik.rwth-aachen.de)
#0	string	yz	MGR bitmap, modern format, 8-bit aligned
#0	string	zz	MGR bitmap, old format, 1-bit deep, 16-bit aligned
#0	string	xz	MGR bitmap, old format, 1-bit deep, 32-bit aligned
#0	string	yx	MGR bitmap, modern format, squeezed
#
## image file format (Robert Potter, potter@cs.rochester.edu)
#0	string		Imagefile\ version-	iff image data
## this adds the whole header (inc. version number), informative but longish
#&gt;10	string		&gt;\0		%s
#
## other images
#0	string	This\ is\ a\ BitMap\ file	Lisp Machine bit-array-file
#0	string		\!\!		Bennet Yee's "face" format
#
## From SunOS 5.5.1 "/etc/magic" - appeared right before Sun raster image
## stuff.
##
#0	beshort		0x1010		PEX Binary Archive
#
## Visio drawings
#03000	string	Visio\ (TM)\ Drawing			%s
#
#0	string		IC		PC icon data
#0	string		PI		PC pointer image data
#0	string		CI		PC color icon data
#0	string		CP		PC color pointer image data

  } elsif (substr($head,0,2) eq "\37\x9d") {
    # .Z compress(1)ed file; may be an image (i.e pbm.Z)
    $bbi-&gt;{FileFormat}='compress'; $bbi-&gt;{SubFormat}='compress';
  } elsif (substr($head,0,2) eq "\37\x8b") {
    $bbi-&gt;{FileFormat}='compress'; $bbi-&gt;{SubFormat}='gzip';
  } elsif (substr($head,0,2) eq "\37\x36") {
    $bbi-&gt;{FileFormat}='compress'; $bbi-&gt;{SubFormat}='pack';
  } elsif ($head=~/\A(?:\377\037|\037\377)/) {
    $bbi-&gt;{FileFormat}='compress'; $bbi-&gt;{SubFormat}='compact';
  } elsif (substr($head,0,3) eq "BZh") {
    $bbi-&gt;{FileFormat}='compress'; $bbi-&gt;{SubFormat}='bzip2';
  } elsif (substr($head,0,2) eq "BZ") { # check must be after bzip
    $bbi-&gt;{FileFormat}='compress'; $bbi-&gt;{SubFormat}='bzip1';
  } elsif (substr($head,0,2) eq "\x76\xff") {
    $bbi-&gt;{FileFormat}='compress'; $bbi-&gt;{SubFormat}='squeeze';
  } elsif (substr($head,0,2) eq "\x76\xfe") {
    $bbi-&gt;{FileFormat}='compress'; $bbi-&gt;{SubFormat}='crunch';
  } elsif (substr($head,0,2) eq "\x76\xfd") {
    $bbi-&gt;{FileFormat}='compress'; $bbi-&gt;{SubFormat}='LZH';
  } elsif (substr($head,0,2) eq "\037\237") {
    $bbi-&gt;{FileFormat}='compress'; $bbi-&gt;{SubFormat}='freeze2';
  } elsif (substr($head,0,2) eq "\037\236") {
    $bbi-&gt;{FileFormat}='compress'; $bbi-&gt;{SubFormat}='freeze1';
  } elsif (substr($head,0,2) eq "\037\240") {
    $bbi-&gt;{FileFormat}='compress'; $bbi-&gt;{SubFormat}='SCO.LZH';
  } elsif (substr($head,0,9) eq "\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a") {
    $bbi-&gt;{FileFormat}='compress'; $bbi-&gt;{SubFormat}='lzop';

  } elsif (substr($head,0,2) eq "\x60\xEA") {
    $bbi-&gt;{FileFormat}='archive'; $bbi-&gt;{SubFormat}='ARJ';
  } elsif ($head=~/\A..-l[hz]/s) {
    $bbi-&gt;{FileFormat}='archive'; $bbi-&gt;{SubFormat}='LHA';
  } elsif (substr($head,0,4) eq "Rar!") {
    $bbi-&gt;{FileFormat}='archive'; $bbi-&gt;{SubFormat}='RAR';
  } elsif (substr($head,0,4) eq "UC2\x1A") {
    $bbi-&gt;{FileFormat}='archive'; $bbi-&gt;{SubFormat}='UC2';
  } elsif (substr($head,0,4) eq "PK\003\004") {
    $bbi-&gt;{FileFormat}='archive'; $bbi-&gt;{SubFormat}='ZIP';
  } elsif (substr($head,0,4) eq "\xDC\xA7\xC4\xFD") {
    $bbi-&gt;{FileFormat}='archive'; $bbi-&gt;{SubFormat}='ZOO';

  } elsif ($head=~/\A.PC Research, Inc/s) {
    $bbi-&gt;{FileFormat}='G3';
    $bbi-&gt;{SubFormat}='Digifax';
    # Dat: determining $bbi-&gt;{URX} and $bbi-&gt;{URY} would require a complex
    #      and full parsing of the G3 facsimile data
  } elsif ($head=~/\A\367[\002-\005]/) {
    # Dat: \005 is rather arbitrary here
    goto FF__DVI;
  } elsif ($head=~/\A[\36-\77](?:\001[\001\11]|\0[\002\12\003\13])\0\0/ and
    vec($head, 1, 8)&lt;=11 and (vec($head, 16, 8)&lt;=8 or vec($head, 16, 8)==24)) { # potato magic
    my @types=(0,'Map','RGB','Gray',0,0,0,0,0,'Map.RLE','RGB.RLE','Gray.RLE');
    $bbi-&gt;{FileFormat}='TGA';
    $bbi-&gt;{SubFormat}=$types[vec($head,2,8)];
    ($dummy,$bbi-&gt;{LLX},$bbi-&gt;{LLY},$bbi-&gt;{URX},$bbi-&gt;{URY})=unpack("A8vvvv",$head);
    # Imp: verify LLX!=0 URX-LLX
  } elsif (30&lt;=vec($head, 0, 8) and vec($head, 0, 8)&lt;=63 and
    vec($head, 1, 8)&lt;=11 and (vec($head, 16, 8)&lt;=8 or vec($head, 16, 8)==24)) {
    # ^^^ Dat: TGA doesn't have a fixed-format header, so this detection is quite
    #     weak. That's why it is the last one we perform.
    $bbi-&gt;{FileFormat}='TGA';
    $bbi-&gt;{SubFormat}='fallback';
    ($dummy,$bbi-&gt;{LLX},$bbi-&gt;{LLY},$bbi-&gt;{URX},$bbi-&gt;{URY})=unpack("A8vvvv",$head);
    # Imp: verify LLX!=0 URX-LLX
  } elsif ($head=~/^PicData:\s*(\d+)\s*(\d+)\s*(\d+)/m) { # grayscale Faces Project imagegrayscale Faces Project image; untested
    # ^^^ Dat: regexp match is quite weak; perform check last
    $bbi-&gt;{FileFormat}='Faces'; # from xloadimage
    $bbi-&gt;{URX}=$1+0; $bbi-&gt;{URY}=$2+0; $bbi-&gt;{"Info.bitdepth"}=$3+0;
  } elsif ($head=~/\A\001\0/s) { # really weak
    $bbi-&gt;{FileFormat}='G3';
    $bbi-&gt;{SubFormat}='MSBfirst.bytepad';
  } elsif ($head=~/\A\0\001/s) { # really weak
    $bbi-&gt;{FileFormat}='G3';
    $bbi-&gt;{SubFormat}='LSBfirst.bytepad';
  } elsif ($head=~/\A\24\0/s) { # really weak
    $bbi-&gt;{FileFormat}='G3';
    $bbi-&gt;{SubFormat}='MSBfirst.raw';
  } elsif ($head=~/\A\0\24/s) { # really weak
    $bbi-&gt;{FileFormat}='G3';
    $bbi-&gt;{SubFormat}='LSBfirst.raw';
    # Dat: determining $bbi-&gt;{URX} and $bbi-&gt;{URY} would require a complex
    #      and full parsing of the G3 facsimile data
  } else {
    $bbi-&gt;{Error}='unrecognised FileFormat'
  }
 done:
  if ($have_paper and exists $bbi-&gt;{URX} and exists $bbi-&gt;{URY}) {
    ($bbi-&gt;{Paper},$bbi-&gt;{PaperWidth},$bbi-&gt;{PaperHeight})=@L[0,1,2] if
      @L=Htex::papers::valid_bp($bbi-&gt;{URX},$bbi-&gt;{URY},$bbi-&gt;{LLX},$bbi-&gt;{LLY});
  } else {
    delete $bbi-&gt;{LLX} if !exists $bbi-&gt;{URX};
    delete $bbi-&gt;{LLY} if !exists $bbi-&gt;{URY};
  }
  $bbi
}

sub import {
  no strict 'refs';
  my $package=(caller())[0];
  shift;
  ($have_paper,$have_pdf)=(1,1);
  for my $p (@_) {
    if ($p eq '-PDF') { $have_pdf=0 }
    elsif ($p eq '-paper') { $have_paper=0 }
    else { *{$package."::$p"}=\&amp;{$p} }
  }
  if ($have_pdf) { require Htex::PDFread; import Htex::PDFread }
  if ($have_paper) { require Htex::papers; import Htex::papers }
}

just::end}

BEGIN{$ INC{'vars.pm'}='vars.pm'} {
package vars;
use just;
# by pts@fazekas.hu at Wed Jan 10 12:42:08 CET 2001
require 5.002;
sub import {
  my $callpack = caller;
  my ($sym, $ch, $sym9);
  shift;
  for $sym0 (@_) {
    die("Can't declare another package's variables") if $sym0 =~ /::/;
    ($ch, $sym) = unpack('a1a*', $sym0);
    *{"${callpack}::$sym"} =
    (  $ch eq "\$" ? \$   {"${callpack}::$sym"}
     : $ch eq "\@" ? \@   {"${callpack}::$sym"}
     : $ch eq "\%" ? \%   {"${callpack}::$sym"}
     : $ch eq "\*" ? \*   {"${callpack}::$sym"}
     : $ch eq "\&amp;" ? \&amp;   {"${callpack}::$sym"}
     : die("'$ch$sym' is not a valid variable name\n")
    );
  }
}
just::end}

BEGIN{$ INC{'Htex/PDFread.pm'}='Htex/PDFread.pm'} {
package Htex::PDFread;
# by pts@fazekas.hu at Sat Dec 21 21:28:09 CET 2002
use just;
use integer;
use strict;
use Pts::string;
use vars qw($pdf_last_ref0);

my @pdf_classify;
#** @param $_[0] a string in PDF source format
#** @return a rewritten string, or "" if $_[0] is truncated, or undef if
#**   there is a parse error
sub pdf_rewrite($;$) {
  my $explicit_term_p=$_[1];
  my $L=length($_[0]);
  return "" if $L==0;
  my $S="$_[0]\n&gt;&gt;  "; # add sentinel
  my $I=0;
  my $O;
  my $RET="";
  if (!@pdf_classify) {
    # Dat: PDF whitespace(0) is  [\000\011\012\014\015\040]
    # Dat: PDF separators(10) are &lt; &gt; { } [ ] ( ) / %
    # Dat: PDF regular(40) character is any of [\000-\377] which is not whitespace or separator
    @pdf_classify=(40)x256;
    @pdf_classify[ord('&lt;'),ord('&gt;'),ord('{'),ord('}'),ord('['),ord(']'),
      ord('('),ord(')'),ord('/'),ord('%')]=(10,11,12,13,14,15,16,17,18,19);
    @pdf_classify[000,011,012,014,015,040]=(0,0,0,0,0,0);
  }
  while ($I&lt;$L) {
    $O=$pdf_classify[vec($S,$I,8)];
    if ($O==0) { # whitespace
    } elsif (12&lt;=$O and $O&lt;=15) { # one-char token
      $RET.=" ".substr($S,$I,1);
    } elsif ($O==18 or $O==40) { # name or /name
      my $P=0;
      if ($O==18) { $I++; $RET.=" /" } else { $RET.=" "; $P=1 }
      my $T="";
      $T.=chr($O) while $pdf_classify[$O=vec($S,$I++,8)]==40;
      $I--;
      ## die $I;
      $T=~s@([^A-Za-z0-9_.-])@sprintf"#%02x",ord$1@ge; # make name safe
      $RET.=$T;
      return $RET if $P and ($T eq "stream" or $T eq "endobj" or $T eq "startxref");
      next
    } elsif ($O==11) { # `&gt;'
      return "" if ++$I==$L; # only `&gt;' has arrived
      return undef if vec($S,$I,8)!=62; # err("&gt;&gt; expected");
      $RET.=" &gt;&gt;";
    } elsif ($O==16) { # string
      my $T="";
      my $depth=1; $I++;
      while ($I&lt;$L) {
        $O=vec($S,$I++,8); bcont:
        ## print chr($O),":$depth\n";
        if ($O==40) { $depth++ }
        elsif ($O==41) { last unless --$depth }
        elsif ($O==92) { # a backslash
          $O=vec($S,$I++,8);
          if (48&lt;=$O &amp;&amp; $O&lt;=55) {
            my $P=$O-48; $O=vec($S,$I++,8);
            if (48&lt;=$O &amp;&amp; $O&lt;=55) {
              my $Q=$O-48; $O=vec($S,$I++,8);
              if (48&lt;=$O &amp;&amp; $O&lt;=55) { $T.=chr(255&amp;($P&lt;&lt;6|$Q&lt;&lt;3|($O-48))) }
                               else { $T.=chr($P&lt;&lt;3|$Q); goto bcont }
            } else { $T.=chr($P); goto bcont }
          } elsif ($O==110) { $O=10 }
          elsif ($O==114) { $O=13 }
          elsif ($O==116) { $O=9 }
          elsif ($O== 98) { $O=8 }
          elsif ($O==102) { $O=12 }
        }
        $T.=chr($O)
      } # WHILE
      return "" if $depth; # err("unterminated string")
      $T=~s@([^A-Za-z0-9_.-])@sprintf"\\%03o",ord$1@ge; # make string safe
      $RET.=" ($T)"; next
    } elsif ($O==10) { # hex string
      $O=vec($S,++$I,8);
      if ($O==60) { $RET.=" &lt;&lt;"; $I++; next }
      # parse hexadecimal string
      my $half=0x100;
      my $T="";
      while (1) {
        1 until $pdf_classify[$O=vec($S,$I++,8)]; # skip whitespace
        if ($O==62) { $T.=chr($half&amp;0xFF) if $half&amp;0x1000; last } # '&gt;'
        return undef if $pdf_classify[$O]!=40; # err("unexpected token in hex")
        if (65&lt;=$O and $O&lt;=70) { $half+=$O-55 }
        elsif (97&lt;=$O and $O&lt;=102) { $half+=$O-87 }
        elsif (48&lt;=$O and $O&lt;=57) { $half+=$O-48 }
        else { return undef } # err("illegal hex digit")
        if ($half&amp;0x1000) { $T.=chr($half&amp;0xFF); $half=0x100 }
                     else { $half&lt;&lt;=4 }
      }
      $T=~s@([^A-Za-z0-9_.-])@sprintf"\\%03o",ord$1@ge; # make string safe
      $RET.=" ($T)"; next
    } elsif ($O==19) { # single-line comment
      $I++ while ($O=vec($S,$I,8))!=13 &amp;&amp; $O!=10;
      ## print STDERR "I=$I L=$L\n";
      next
    } else { return undef } # err("token expected") # $O==11, $O==17
    $I++
  } ## WHILE
  ## print STDERR "XI=$I L=$L\n";
  # die $explicit_term_p;
  return "" if $explicit_term_p;
  ($I&gt;$L) ? "" : $RET
}

# Unit test:
#die unless pdf_rewrite("hello \n\t world\n\t") eq " hello world";
#die unless pdf_rewrite('(hel\)lo\n\bw(or)ld)') eq ' (hel\051lo\012\010w\050or\051ld)';
#die unless pdf_rewrite('(hel\)lo\n\bw(orld)') eq '';
#die unless pdf_rewrite('[ (hel\)lo\n\bw(or)ld)&gt;&gt;') eq ' [ (hel\051lo\012\010w\050or\051ld) &gt;&gt;';
#die unless pdf_rewrite('&gt;') eq "";
#die unless pdf_rewrite('&lt;') eq "";
#die unless pdf_rewrite('&lt; ') eq "";
#die unless !defined pdf_rewrite('&lt; &lt;');
#die unless !defined pdf_rewrite('&gt; &gt;');
#die unless pdf_rewrite('[ (hel\)lo\n\bw(or)ld) &lt;') eq "";
#die unless pdf_rewrite("&lt;\n3\t1\r4f5C5 &gt;]") eq ' (1O\134P) ]';
#die unless pdf_rewrite("&lt;\n3\t1\r4f5C5") eq "";
#die unless !defined pdf_rewrite("&lt;\n3\t1\r4f5C5]&gt;");
#die unless pdf_rewrite("% he te\n&lt;\n3\t1\r4f5C5 &gt;]endobj&lt;&lt;") eq ' (1O\134P) ] endobj';
#die unless pdf_rewrite("") eq "";
#die unless pdf_rewrite("&lt;&lt;") eq " &lt;&lt;";
#die unless pdf_rewrite('%hello') eq '';
#die unless pdf_rewrite("alma\n%korte\n42") eq ' alma 42';
#die unless pdf_rewrite('/Size 42') eq ' /Size 42';
#die "OK";

#** Reads a single PDF indirect object (without its stream) from a PDF file.
#** Does some trivial transformations on it to make later regexp matching
#** easier. Stops at `stream', `endobj' and `startxref'.
#** @param $_[0] a filehandle (e.g \*STDIN), correctly positioned in the PDF
#**   file to the beginning of the object data (i.e just before `5 0 obj')
#** @return string containing PDF source code, or undef on error
sub pdf_read_obj($) {
  my $F=$_[0];  my $L=1024;  my $M;  my $S="";  my $RET;
  while (1) { # read as much data as necessary
    return undef if 0&gt;($M=read $F, $S, $L, length($S));
    $RET=pdf_rewrite($S,1);
    ## print "($S)\n";
    return undef if !defined $RET; # parse error
    return $RET if length $RET; # OK, found object
    return undef if $M==0; # cannot read more, reached EOF
    $L&lt;&lt;=1;
  }
  #$S=~m@[\000\011\012\014\015\040]*(
  #  %[^\r\n]*[\r\n]|
  #  /?[^\000\011\012\014\015\040&lt;&gt;{}\[\]()/%]*(?=[\000\011\012\014\015\040&lt;&gt;{}\[\]()/%])| # unterminated
  #  &lt;&lt;|&gt;&gt;|\{|}|\[|]|
  #  &lt;[a-fA-F0-9\000\011\012\014\015\040]*&gt;| # hex string
  #  \((?:[^\\()]+|\\[\000-\377])*\)| # literal string, the easy way
  #  \( # an unfinished string, needs special care
  #)@gx
}

#** @param $_[0] a filehandle (e.g \*STDIN), containing a PDF file, positioned
#**  just before an `xref' table
#** @param $_[1] an xref table: $_[1][4][56] is the file offset of object 56
#**   from generation 4; will be extended
#** @return the `trailer' section after the `xref'; or undef
sub pdf_read_xref($$) {
  # made much faster at Wed Dec 18 09:50:23 CET 2002
  my $T;
  my $E;
  my $F=$_[0];
  my $XREF=$_[1];
  return undef if 8&gt;read $F, $T, 1024;
  return undef unless $T=~s@\A\s*xref\s+(\d+)\s+(\d+)\s+(?=\S)@@;
  my ($first,$len,$flen);
  while (1) {
    ($first,$len)=($1+0,$2+0);
    ## print " $first + $len\n";
    $flen=($len*=20)-length($T)+20;
    return undef unless $flen&lt;1 or $flen==read $F, $T, $flen, length($T);
    for (my $I=0;$I&lt;$len;$I+=20, $first++) {
      $E=substr($T, $I, 20);
      return undef unless $E=~/\A(\d{10})\s(\d{5})\s([nf])\s\s/;
      ## print "($1 $2 $3)\n";
      $XREF-&gt;[$2+0][$first]=$1+0 if $3 eq 'n';
    }
    $E=substr($T, $len);
    last if $E!~s@\A\s*(\d+)\s*(\d+)\s+(?=\S)@@; # next section
    $T=$E;
  }
  
  # die(-length($T)+$len);
  ## die tell($F);
  return undef if length($T)!=$len and !seek $F, -length($T)+$len, 1;
  ## die tell($F);
  return undef unless defined($T=pdf_read_obj($F));
  $XREF-&gt;[0][0]=undef if defined $XREF-&gt;[0];
  $XREF-&gt;[0][0]=$1+0 if $T=~m@ /Prev (\d+)@; # remember /Prev xref table
  return undef unless $T=~m@\A trailer( .*) startxref\Z(?!\n)@s;
  $1
}

$pdf_last_ref0=0;
#** @param $_[0] a filehandle (e.g \*STDIN), containing a PDF file
#** @param $_[1] an xref table: $_[1][4][56] is the file offset of object 56
#**   from generation 4
#** @param $_[2] an object number
#** @param $_[3] a generation number
#** @return PDF source code of the reference, or undef
sub pdf_ref($$$$) {
  my $F=$_[0]; my $XREF=$_[1]; my $ON=$_[2]+0; my $GN=$_[3]+0;
  my $T;
  $pdf_last_ref0=$ON if $GN==0;
  ## print "REF $ON $GN;\n";
  until (ref $XREF-&gt;[$GN] and defined ($T=$XREF-&gt;[$GN][$ON])) {
    return undef if !ref $XREF-&gt;[0] or !defined $XREF-&gt;[0][0]; # no /Prev entry, `$ON $GN R' not found
    return undef unless seek $F, $XREF-&gt;[0][0], 0;
    return undef if !defined pdf_read_xref($F,$XREF);
  }
  ## print "REF at $T;\n";
  return undef unless seek $F, $T, 0;
  return undef unless defined($T=pdf_read_obj($F));
  ## print "REF=($T);\n";
  return undef unless $T=~s@\A (\d+) (\d+) obj\b(.*) (endobj|stream)\Z(?!\n)@$3@s;
  $T
}

#** Gets a key from a direct dict, and resolves it if it is an indirect object
#** @param $_[0] a filehandle (e.g \*STDIN), containing a PDF file
#** @param $_[1] an xref table: $_[1][4][56] is the file offset of object 56
#**   from generation 4
#** @param $_[2] a PDF source dict (`&lt;&lt; ... &gt;&gt;') or array
#** @param $_[3] a key (`/...')
sub pdf_get($$$$) {
  my $F=$_[0]; my $XREF=$_[1]; my $S=$_[2]; my $KEY=$_[3]; my $POS=0;
  my $DEPTH=0; my $IS_DICT; my $C=0; my $N=0;
  ## print "\n";
  while ($S=~/\G (\S+)/g) {
    $C=vec($1,0,8);  $POS=pos($S);
    ## print "($1) $DEPTH $N\n";
    if ($1 eq '&gt;&gt;' or $1 eq ']') {
      return undef if 0==$DEPTH--;
      last if !$DEPTH;
      $N++ if 1==$DEPTH;
    }
    elsif ($DEPTH==1 and !$IS_DICT and $KEY==$N) { $POS=pos($S)-=length($1)+1; goto do_ret }
    elsif ($1 eq '&lt;&lt;') { $IS_DICT=1 if 0==$DEPTH++ }
    elsif ($1 eq '[') {
      if (0==$DEPTH++) {
        $IS_DICT=0;
        return undef if $KEY!~/\A(\d+)\Z(?!\n)/; # err("non-numeric key in array")
      }
    }
    elsif (0==$DEPTH) { return undef } # not in a composite object
    elsif (1!=$DEPTH) { next }
    elsif (!$IS_DICT) { $N++ }
    elsif ($C==40) { $N++ } # `(': string or bare name
    elsif ($C&gt;=47 and $C&lt;=57) { # '/': /name 0..9: number
      ## print "TRY ($1) KEY=$KEY.\n";
      next if ($N++&amp;1)==1 or $1 ne $KEY;
     do_ret:
      ## print substr($S,pos($S)),";;\n";
      return pdf_ref $F, $XREF, $1, $2 if $S=~/\G (\d+) (\d+) R\b/gc;
      ## print substr($S,pos($S)),"::\n";
      $DEPTH=0;
      while ($S=~/\G( \S+)/g) {
        if ($1 eq ' &lt;&lt;' or $1 eq ' [') { $DEPTH++ }
        elsif ($1 eq ' &gt;&gt;' or $1 eq ' ]') {
          ## die "($1)\n";
          return undef if 0==$DEPTH--; # err("nesting")
          return substr($S,$POS,pos($S)-$POS) if 0==$DEPTH;
        } elsif ($DEPTH==0) { return $1 }
      }
    } else { $N++ } # bare name
  }
  return undef if $POS!=length($S); # err("invalid source dict");
  "" # not found
}

# Unit test:
#die unless pdf_get(\*STDIN, 0, ' [ al makorte 42 ]', 0) eq ' al';
#die unless pdf_get(\*STDIN, 0, ' [ al makorte 42 ]', 1) eq ' makorte';
#die unless pdf_get(\*STDIN, 0, ' [ al makorte 42 ]', 2) eq ' 42';
#die unless pdf_get(\*STDIN, 0, ' [ al makorte 42 ]', 3) eq '';
#die unless pdf_get(\*STDIN, 0, ' [ &lt;&lt; &gt;&gt; ]', 0) eq ' &lt;&lt; &gt;&gt;';
#die unless pdf_get(\*STDIN, 0, ' [ &lt;&lt; &gt;&gt; ]', 1) eq '';
#die unless pdf_get(\*STDIN, 0, ' [ &lt;&lt; &gt;&gt; [ al makorte 42 ] ]', 1) eq ' [ al makorte 42 ]';
#die unless pdf_get(\*STDIN, 0, ' &lt;&lt; /Alma [ 1 2 ] /Korte [ 3 4 ] &gt;&gt;', '/Korte') eq ' [ 3 4 ]';
#die unless !defined pdf_get(\*STDIN, 0, ' [ al makorte 42 ]', '/Name');
#die unless !defined pdf_get(\*STDIN, 0, ' &lt;&lt; al makorte 42 &gt;&gt;', 42);
#die unless pdf_get(\*STDIN, 0, ' &lt;&lt; al makorte 42 137 &gt;&gt;', 42) eq ' 137';
#die unless pdf_get(\*STDIN, 0, ' &lt;&lt; al makorte &gt;&gt;', 'al') eq "";
#die "OK";

#** Reported boxes: /MediaBox /CropBox /BleedBox /TrimBox /ArtBox
#** @param $_[0] a filehandle (e.g \*STDIN), containing a PDF file
#** @param $_[1] an xref table: $_[1][4][56] is the file offset of object 56
#**   from generation 4
#** @param $_[2] a PDF source dict (`&lt;&lt; ... &gt;&gt;') of /Type/Catalog
#**   /Type/Pages or /Type/Page
#** @param $_[3] hashref to update. $_[3]{BleedBox}[2] will be the URX corner
#**   of the BleedBox
sub pdf_get_boxes($$$$) {
  my $F=$_[0]; my $XREF=$_[1]; my $S=$_[2]; my $bbi=$_[3];
  return if !defined $S;
  for my $name (qw{MediaBox CropBox BleedBox TrimBox ArtBox}) {
    my $box=pdf_get($F, $XREF, $S, "/$name");
    next if !defined $box or !length $box
         or $box!~m@ \[ ([0-9eE.-]+) ([0-9eE.-]+) ([0-9eE.-]+) ([0-9eE.-]+) \]\Z(?!\n)@
         or !defined c_numval($1) or !defined c_numval($2) or !defined c_numval($3) or !defined c_numval($4);
    ($bbi-&gt;{LLX},$bbi-&gt;{LLY},$bbi-&gt;{URX},$bbi-&gt;{URY})=($1+0,$2+0,$3+0,$4+0) if $name eq 'MediaBox';
    my $name2="Info.$name";
    ($bbi-&gt;{$name2}[0],$bbi-&gt;{$name2}[1],$bbi-&gt;{$name2}[2],$bbi-&gt;{$name2}[3])=($1+0,$2+0,$3+0,$4+0);
  }
}

sub import {
  no strict 'refs';
  my $package=(caller())[0];
  shift;
  for my $p (@_ ? @_ : qw{pdf_get_boxes pdf_get pdf_read_xref pdf_read_obj
    pdf_rewrite pdf_ref}) { *{$package."::$p"}=\&amp;{$p} }
}

just::end}

BEGIN{$ INC{'Htex/papers.pm'}='Htex/papers.pm'} {
package Htex::papers;
# contains paper size information
# by pts@fazekas.hu at Sun Dec 22 00:30:58 CET 2002
use just;
use integer;
use strict;
use Htex::dimen;

my @papers=(
#
# paper.txt
# by pts@fazekas.hu at Tue Jan 16 18:21:59 CET 2001
# by pts@fazekas.hu at Tue Jan 16 19:13:16 CET 2001
#
# Examined: dvips, gs, libpaperg
#
# all units are measured in Big Points (bp)
# 72 bp == 1 in
# 2.54 cm == 1 in
#
# papername	width	height
qw{Comm10	297	684},
qw{Monarch	279	540},
qw{halfexecutive 378	522},

qw{Legal	612	1008},
qw{Statement	396	612},
qw{Tabloid	792	1224},
qw{Ledger	1224	792},
qw{Folio	612	936},
qw{Quarto	610	780},
qw{7x9		504	648},
qw{9x11		648	792},
qw{9x12		648	864},
qw{10x13	720	936},
qw{10x14	720	1008},
qw{Executive	540	720},
qw{ISOB0	2835	4008},
qw{ISOB1	2004	2835},
qw{ISOB2	1417	2004},
qw{ISOB3	1001	1417},
qw{ISOB4	709	1001},
qw{ISOB5	499	709},
qw{ISOB6	354	499},
qw{ISOB7	249	354},
qw{ISOB8	176	249},
qw{ISOB9	125	176},
qw{ISOB10	88	125},
qw{C7		230	323},
qw{DL		312	624},

qw{a3		842	1190},	# defined by Adobe
qw{a4		595	842},	# defined by Adobe; must precede a4small

# a4small should be a4 with an ImagingBBox of [25 25 570 817].},
qw{a4small	595	842},
qw{letter	612	792},	# must precede lettersmall
# lettersmall should be letter with an ImagingBBox of [25 25 587 767].
qw{lettersmall	612	792},
# note should be letter (or some other size) with the ImagingBBox
# shrunk by 25 units on all 4 sides.
qw{note		612	792},
qw{letterLand	792	612},
# End of Adobe-defined page sizes

qw{a0		2380	3368},
qw{a1		1684	2380},
qw{a2		1190	1684},
qw{a5		421	595},
qw{a6		297	421},
qw{a7		210	297},
qw{a8		148	210},
qw{a9		105	148},
qw{a10		74	105},
qw{b0		2836	4008},
qw{b1		2004	2836},
qw{b2		1418	2004},
qw{b3		1002	1418},
qw{b4		709	1002},
qw{b5		501	709}, # defined by Adobe

qw{a0Land	3368	2380},
qw{a1Land	2380	1684},
qw{a2Land	1684	1190},
qw{a3Land	1190	842},
qw{a4Land	842	595},
qw{a5Land	595	421},
qw{a6Land	421	297},
qw{a7Land	297	210},
qw{a8Land	210	148},
qw{a9Land	148	105},
qw{a10Land	105	74},
qw{b0Land	4008	2836},
qw{b1Land	2836	2004},
qw{b2Land	2004	1418},
qw{b3Land	1418	1002},
qw{b4Land	1002	709},
qw{b5Land	709	501},

qw{c0		2600	3677},
qw{c1		1837	2600},
qw{c2		1298	1837},
qw{c3		918	1298},
qw{c4		649	918},
qw{c5		459	649},
qw{c6		323	459},

# vvv U.S. CAD standard paper sizes
qw{archE	2592	3456},
qw{archD	1728	2592},
qw{archC	1296	1728},
qw{archB	864	1296},
qw{archA	648	864},

qw{flsa		612	936},	# U.S. foolscap
qw{flse		612	936},	# European foolscap
qw{halfletter	396	612},
qw{csheet	1224	1584},	# ANSI C 17x22
qw{dsheet	1584	2448},	# ANSI D 22x34
qw{esheet	2448	3168},	# ANSI E 34x44
qw{17x22	1224	1584},	# ANSI C 17x22
qw{22x34	1584	2448},	# ANSI D 22x34
qw{34x44	2448	3168},	# ANSI E 34x44
);

#** @param $_[0] width, in bp
#** @param $_[1] height, in bp
#** @return () or ("papername", width.bp, height.bp)
sub valid_bp($$;$$) {
  no integer;
  my ($W1,$H1)=(defined$_[2]?$_[2]:0,defined$_[3]?$_[3]:0);
  my ($WW,$HH)=(Htex::dimen::dimen2bp($_[0]-$W1), Htex::dimen::dimen2bp($_[1]-$H1));
  # Dat: 1mm == 720/254bp; 3mm =~ 8.5bp
  no integer;
  for (my $I=0; $I&lt;@papers; $I+=3) {
    return @papers[$I,$I+1,$I+2] if abs($papers[$I+1]-$WW)&lt;=8.5 and abs($papers[$I+2]-$HH)&lt;=8.5;
  }
  ()
}

#** @param $_[0] "width width_unit, height, height_unit"
#** @return () or ("papername", width.bp, height.bp)
sub valid($) { # valid_papersize
  my $S=lc shift;
  $S=~/^\s*(\d+(\.\d+)?)\s*([a-z][a-z0-9]+)\s*,\s*(\d+(\.\d+)?)\s*([a-z][a-z0-9]+)\s*\Z(?!\n)/ ?
    valid_bp("$1$3","$4$6") : ();
}

just::end}

BEGIN{$  INC{'Htex/img_bbox.pm'}='Htex/img_bbox.pm'}

package Htex::img_bbox;
# img_bbox.pa -- extract file format and size from image files
# This file contains embedded perldoc(1) POD documentation.
# by pts@fazekas.hu at Sat Dec  7 21:31:01 CET 2002
# JustLib2 at Sat Dec 21 21:29:21 CET 2002
#
# img_bbox.pl is a standalone Perl script that can extract file format,
# width, height, bounding box and
# other meta-information from image files. Supported vector formats are:
# PDF, Flash SWF, EPS, PS, DVI and FIG. Supported raster image formats are:
# GIF, JPEG, PNG, TIFF, XPM, XBM1, XBM, PNM, PBM, PGM, PPM, PCX, LBM, other
# IFF, Windows and OS/2 BMP, MIFF, Gimp XCF, Windows ICO, Adobe PSD, FBM,
# SunRaster, CMUWM, Utah RLE, Photo CD PCD, XWD, GEM, McIDAS, PM, SGI IRIS,
# FITS, VICAR, PDS, FIT, Fax G3, Targa TGA and Faces.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# Extracting the image size is not supported for: other IFF, FIG.
#
#
use just 1;
use integer; # important
use strict; # not so important
# use Htex::ImgBBox qw(calc -PDF -paper);
use Htex::ImgBBox qw(calc);

sub delete0($$) {
  delete $_[0]{$_[1]};
  ""
}

#** @param $_[0] $bbi hashref
#** @return a multiline dump of all key--value pairs, sorted by key
sub all($) {
  my $bbi=$_[0];
  my $RET="";
  for my $key (sort keys %$bbi) { if (1&lt;length $key) {
    my $val=$bbi-&gt;{$key};
    $RET.="  $key = ".(ref($val)eq'ARRAY' ? "[ @$val ]\n" : "$val\n");
  } }
  $RET
}

my %texq;
#** @param $_[0] arbitrary binary string
#** @return the string quoted, so it can be safely placed inside TeX
#**   \message{...} or \special{...}
sub texq($) {
  if (!keys %texq) {
    $texq{' '}='\iftrue\space\fi '; # won't collapse two spaces into one
   $texq{'\\'}='\expandafter\@secondoftwo\string\\\\';
    $texq{'{'}='\expandafter\@secondoftwo\string\{';
    $texq{'}'}='\expandafter\@secondoftwo\string\}';
    $texq{'%'}='\expandafter\@secondoftwo\string\%';
    $texq{'#'}='\expandafter\@secondoftwo\string\#';
    $texq{'^'}='\expandafter\@secondoftwo\string\^'; # no danger of ^^
    $texq{'~'}='\expandafter\@secondoftwo\string\~';
    $texq{'`'}='\expandafter\@secondoftwo\string\`';
    $texq{'"'}='\expandafter\@secondoftwo\string\"';
    # vvv will work only if the token is expanded only once
    #$texq{'~'}='\noexpand~';
    #$texq{'`'}='\noexpand`';
    #$texq{'"'}='\noexpand"';
  }
  my $S=$_[0];
  $S=~s@(\W)@exists$texq{$1}?$texq{$1}:$1@ge;
  $S=~s~([\000-\037\177-\377])~sprintf"\\expandafter\\\@secondoftwo\\string\\^^%02x",ord$1~ge;
  $S
}

sub aq($$) {
  $_[0] eq ":t" ? texq($_[1]) : $_[1]
}

my $t_short="%{FileName} %{FileFormat:-??} %{LLX:-??} %{LLY:-??} %{URX:-??} %{URY:-??}%{Paper?+ %{Paper}}%{Error?+ error:%{Error}}\n";
my $t_long="%{FileName}%{FileName?0}\n%{all}";
# my $t_tex='\graphicPmeta{%{FileName:t}%{c}{%{FileFormat:-?}%{c}{%{LLX:-?}%{c}{%{LLY:-?}%{c}{%{URX:-?}%{c}{%{URY:-?}%{c}%{n}';
my $t_tex='\graphicPmeta{%{FileName:t}%{c}{%{FileFormat:-?}%{SubFormat?+.%{SubFormat}}%{c}{%{LLX:-?}%{c}{%{LLY:-?}%{c}{%{URX:-?}%{c}{%{URY:-?}%{c}%{n}';

sub compile_template($) {
  my $template=$_[0];
  # convert $template to Perl code
  $template=~s@([\\'])@\\$1@g;
  $template=~s@([}])|[%][{]([\w.-]+)(:t)?(:-|[?][+0-]|)@
    defined($1) ? "').'" :
    $4 eq "" &amp;&amp; $2 eq "all" ? "'.(all(\$bbi).'" :
    $4 eq "" ? "'.(!defined\$bbi-&gt;{'$2'}?'':aq('".($3||"")."',\$bbi-&gt;{'$2'}).'" :
    $4 eq "?+" ? "'.(!defined\$bbi-&gt;{'$2'}?'':'" :
    $4 eq "?-" ? "'.(defined\$bbi-&gt;{'$2'}?'':'" :
    $4 eq ":-" ? "'.(defined\$bbi-&gt;{'$2'}?aq('".($3||"")."',\$bbi-&gt;{'$2'}):'" :
    $4 eq "?0" ? "'.(delete0(\$bbi,'$2').'" :
    "[$1]($2)($4)" # should never happen
  @ge;
  my $sub=eval "sub { my \$bbi=\$_[0]; '$template' }";
  die "$0: template syntax error: $@" if $@ or ref($sub) ne 'CODE';
  $sub
}

sub work($$) {
  my($sub,$filename)=@_;
  my $bbi;
  # die "$0: $filename: $!\n" unless open F, "&lt; $filename";
  if (open F, "&lt; $filename") {
    ## print STDERR "$filename\n";
    $bbi=calc(\*F);
  } else {
    $bbi-&gt;{Error}="open: $!"
  }
  $bbi-&gt;{FileName}=$filename;
  $bbi-&gt;{n}="\n";
  $bbi-&gt;{p}="%";
  $bbi-&gt;{c}="}";
  print $sub-&gt;($bbi);
}

sub usage() {
  die "This is img_bbox.pl by pts\@fazekas.hu, version 0.08
This program is free software, licensed under the GNU GPL.
This software comes with absolutely NO WARRANTY. Use at your own risk!

Usage: $0 [&lt;template&gt;] &lt;filename.image&gt; [...]
Template is one of: --  --short  --long  --tex  --template &lt;t&gt;

I can extract file format, width, height, bounding box and other
meta-information from image files. Run this to get more docs:
	perldoc '$0'\n"
}

just::main;

usage if !@ARGV;

my $template=$t_short;
if ($ARGV[0] eq '--' or $ARGV[0] eq '--short') { }
elsif ($ARGV[0] eq '--long') { $template=$t_long; shift @ARGV }
elsif ($ARGV[0] eq '--tex') { $template=$t_tex; shift @ARGV }
elsif ($ARGV[0] eq '--template') { usage if @ARGV&lt;2; $template=$ARGV[1]; splice @ARGV, 0, 2 }
elsif ($ARGV[0]=~/\A--/) { goto usage }

my $sub=compile_template($template);
for my $filename (@ARGV) { work $sub, $filename }

__END__

=begin man

.ds pts-dev \*[.T]
.do if '\*[.T]'ascii'  .ds pts-dev tty
.do if '\*[.T]'ascii8' .ds pts-dev tty
.do if '\*[.T]'latin1' .ds pts-dev tty
.do if '\*[.T]'nippon' .ds pts-dev tty
.do if '\*[.T]'utf8'   .ds pts-dev tty
.do if '\*[.T]'cp1047' .ds pts-dev tty
.do if '\*[pts-dev]'tty' \{\
.ll 79
.pl 33333v
.nr IN 2n
.\}
.ad n

=end

=head1 NAME

img_bbox.pl - Extract file format and size from image files

=head1 SYNOPSIS

C&lt;B&lt;img_bbox.pl&gt;&gt;
 S&lt;[ C&lt;--&gt; | C&lt;--short&gt;&gt;
 S&lt;| C&lt;--long&gt;&gt;
 S&lt;| C&lt;--tex&gt;&gt;
 S&lt;| C&lt;--template&gt; I&lt;template&gt; ]&gt;
 S&lt;I&lt;filename.image&gt;&gt; S&lt;[ ... ]&gt;

=head1 DESCRIPTION

img_bbox.pl is a standalone Perl script that can extract file format,
width, height, bounding box and
other meta-information from image files. Supported vector formats are:
PDF, Flash SWF, EPS, PS, DVI and FIG. Supported raster image formats are:
GIF, JPEG, PNG, TIFF, XPM, XBM1, XBM, PNM, PBM, PGM, PPM, PCX, LBM, other
IFF, Windows and OS/2 BMP, MIFF, Gimp XCF, Windows ICO, Adobe PSD, FBM,
SunRaster, CMUWM, Utah RLE, Photo CD PCD, XWD, GEM, McIDAS, PM, SGI IRIS,
FITS, VICAR, PDS, FIT, Fax G3, Targa TGA and Faces.

img_bbox.pl writes the extracted information to STDOUT, in a format
determined by the template specified on the command line. The default
template is C&lt;--short&gt;. Templates are:

=over 10

=item C&lt;--short&gt;

writes the file name, file format and the four
bounding box coordinates (lower left x, lower left y, upper right x, upper
right y), separated by spaces.

=item C&lt;--long&gt;

writes a multi-line entry for each file containing all key--value pairs
that img_bbox.pl was able to extract.

=item C&lt;--tex&gt;

writes output suitable for C&lt;\input&gt; in TeX. The file name, file format and
bounding box is dumped

=item C&lt;--pat&gt;

lets the user specify an individual pattern, see later.

=back

=head1 PATTERNS

Individual patterns can be specified after C&lt;--pat&gt;. Built-in patterns are:

 --short: %{FileName} %{FileFormat:-??} %{LLX:-??} %{LLY:-??} %{URX:-??} %{URY:-??}%{Paper?+ %{Paper}}%{Error?+ error:%{Error}}%{n}
 --long : %{FileName}%{FileName?0}%{n}%{all}
 --tex  : \graphicPmeta{%{FileName:t}%{c}{%{FileFormat:-?}%{c}{%{LLX:-?}%{c}{%{LLY:-?}%{c}{%{URX:-?}%{c}{%{URY:-?}%{c}%{n}

Expressions of the form
 C&lt;%{&gt; I&lt;key&gt; [ I&lt;quoting&gt; ] I&lt;method&gt; I&lt;body&gt; C&lt;}&gt;
 are substituted.

I&lt;key&gt;s of interest will be enumerated later in this subsection.

I&lt;quoting&gt; is one of

=over 7

=item (none)

The string is inserted as-is.

=item C&lt;:t&gt;

Quotes all TeX and LaTeX control characters.

=back

The interpretation of I&lt;body&gt; depends on I&lt;method&gt;. The default action is to
append the contents of I&lt;body&gt; verbatim after the substitution. I&lt;body&gt; is
an empty string most of the time.

I&lt;method&gt; is one of

=over 7

=item (none)

Expands to the value of I&lt;key&gt;, or an empty string. I&lt;body&gt; must be empty.

=item C&lt;:-&gt;

Expands to the value of I&lt;key&gt;, or I&lt;body&gt;.

=item C&lt;?0&gt;

Deletes I&lt;key&gt;, and expands to I&lt;body&gt;.

=item C&lt;?+&gt;

Expands to I&lt;body&gt; if I&lt;key&gt; exists, or an empty string.

=item C&lt;?-&gt;

Expands to I&lt;body&gt; if I&lt;key&gt; is missing, or an empty string.

=back

I&lt;key&gt;s of interest are:

=over 20

=item n

a newline

=item p

a percent sign

=item c

a close brace

=item all

A detailed, multi-line key--value listing of all information extracted, as
output by the C&lt;--long&gt; template.

=item FileName

=item FileFormat

=item SubFormat

=item LLX

Zero for most file formats.

=item LLY

Zero for most file formats.

=item URX

The width for most file formats.

=item URY

The height for most file formats.

=item SamplesPerPixel

=item BitsPerSample

=item ColorSpace

Gray, RGB, YCbCr, CMYK, YCCK, Indexed etc.

=item Error

the first I/O or other error

=item Info.

various file format specific keys begin with C&lt;Info.&gt;

=item Val.

various key--value pairs read from the file, beginning with C&lt;Val.&gt;

=item Info.MediaBox

PDF only

=item Info.CropBox

PDF only

=item Info.BleedBox

PDF only

=item Info.TrimBox

PDF only

=item Info.ArtBox

PDF only

=item Info.Compression

TIFF only

=item Info.NewSubfileType

TIFF only

=item Info.PhotometricInterpretation

TIFF only

=item Info.Thresholding

TIFF only

=item Info.CellWidth

TIFF only

=item Info.CellLength

TIFF only

=item Info.FillOrder

TIFF only

=item Info.Orientation

TIFF only

=item Info.RowsPerStrip

TIFF only

=item Info.MinSampleValue

TIFF only

=item Info.MaxSampleValue

TIFF only

=item Info.PlanarConfiguration

TIFF only

=item Info.GrayResponseUnit

TIFF only

=item Info.ResolutionUnit

TIFF only

=item Info.ExtraSamples

TIFF only

=item Info.hvs

JPEG only

=item Info.id_rgb

JPEG only

=item Info.had_jfif

JPEG only

=item Info.ColorTransform

JPEG only

=item Info.binary

Clean7Bit, Clean8Bit or Binary. PDF and PS only

=item Info.linearized

PDF only

=item Info.denominator

DVI only

=item Info.nominator

DVI only

=item Info.version_id

DVI only


=item Info.maginification

DVI only


=item Info.jobname

DVI only

=item Info.page1_nr

DVI only

=item Info.special

DVI only

=item Info.colors

ICO only

=item Info.reserved

ICO only


=item Info.planes

ICO only


=item Info.credits

FBM only

=item Info.title

FBM only

=item Info.planes

FBM only

=item Info.bits

FBM only

=item Info.rowlen

FBM only

=item Info.plnlen

FBM only

=item Info.clrlen

FBM only

=item Info.hlen

GEM only

=item Info.colors

GEM only

=item Info.patlen

GEM only

=item Info.llen

GEM only

=item Info.lines

GEM only

=item Info.num_planes

PM only

=item Info.num_bands

PM only

=item Info.pixel_format

PM only

=item Info.compression

SGI only

=item Info.comment

SGI only

=item Info.bits_per_pixel

FITS only

=item Info.num_axis

FITS only

=item Info.depth

FITS only

=item Info.data_max

FITS only

=item Info.data_min

FITS only

=back

=head1 LICENSE

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

=head1 AUTHOR

Szabó Péter &lt;F&lt;pts@fazekas.hu&gt;&gt;

=head1 SEE ALSO

file(1)
</pre></body></html>