Zlib to uncompress pdf file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pankajit09
    Contributor
    • Dec 2006
    • 296

    Zlib to uncompress pdf file

    Code:
    use strict ;
        use warnings ;
        
        use Compress::Zlib ;
        
        my $x = inflateInit() or die "Cannot create a inflation stream\n" ;
          
        my $input = '' ;
        
        open(INPUTFILE,"E:\\test.pdf") or die "Can't create the output file : $!";
        open(OUTPUTFILE,'>',"E:\\test1.txt") or die "Can't create the output file : $!";
    	
        binmode INPUTFILE;
        binmode OUTPUTFILE;
        
        my ($output, $status) ;
        while (read(INPUTFILE, $input, 4096))
        {
            ($output, $status) = $x->inflate(\$input) ;
    
    
    	print OUTPUTFILE $output if $status == Z_OK or $status == Z_STREAM_END ;
        
            last if $status != Z_OK ;
        }
        
        close (INPUTFILE);
        close (OUTPUTFILE);
    
        die "inflation failed\n" unless $status == Z_STREAM_END;

    When I print $status "data error" is getting printed.

    How to uncompress the pdf file ?
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    if the pdf file were compressed I would think the extension would be .gz or other file extension that indicates it was compressed, like .zip.

    Comment

    • numberwhun
      Recognized Expert Moderator Specialist
      • May 2007
      • 3467

      #3
      If you are interested in playing around with PDF's, you may want to check out how some of the pdf modules on CPAN work.

      I agree with Kevin though, pdf is not an extension that denotes compression. Just like a .jpg/.jpeg, the file may have its own type of compression, but the extension is not condusive with it and thus uncompress utilities have not effect.


      Regards,

      Jeff

      Comment

      Working...