Take the 2-minute tour ×

I have to write taking a code from the .pdf file, and copy it to anyother pdf file. The code i have written to open the file is given as under :


use IO::File;

$r->header_out( 'Content-disposition' => "attachment; filename=$filename" );

my $tmpfile = $filename;
my $forread = new IO::File "< $fullname";

my @lines = <$forread>;

foreach my $key (@lines){ 
      print $key;

return $fullname;


where filename is the name for the file to save the pdf content to and "fullname" is the pdf getting the content from

share|improve this question
What's the question? –  ikegami Nov 12 '12 at 20:04
Look at File::Copy. –  squiguy Nov 12 '12 at 21:15

1 Answer 1

You're currently reading in a text file. You should binmode first for non-text (like PDF). And, never use indirect object syntax.

my $fh = IO::File->new($fullname, 'r');


So try something like this, adapted from the Mason Book.

use Apache::Constants qw(OK);



$m->clear_buffer; # avoid extra output (but it only works when autoflush is off)


while ( my $data = $fh->getline ) {

share|improve this answer

Your Answer


