ehdonhon has asked for the wisdom of the Perl Monks concerning the following question:
Hello fellow monks,
I'm having some difficulty with the following chunk of code, from a cgi which is intended to take whatever my web page looks like at the moment, convert it to a pdf and serve that pdf to the client:
use Image::Magick; my $html2ps = '/usr/local/bin/html2ps'; print "Content-type: application/pdf\n\n"; open ( FIN, "$html2ps http://mypage.com/index?param=x&foo=y' |" ); my $image = Image::Magick->new; # I don't think binmode is necessary in ps or pdf, but # I'm adding it just in case it makes a difference. binmode FIN; my $status = $image->Read(file=>\*FIN); warn( "Read status = $status" ); $image->set(format=>'pdf'); binmode STDOUT; $image->set(file=>\*STDOUT); $status = $image->Write(); warn( "Write status = $status" ); $image->set(file=>\*STDERR); $status = $image->Write();
From my debugging, I know that Image::Magick does actually read in the postscript file correctly. I also know that the $status value returned by both Read() and Write() is empty (I think that means success). Also I know that the second Write() call which outputs to STDERR does output a valid pdf file.
My problem, is that the first Write() call which should be sending output to STDOUT isn't doing anything at all! In fact, here is all the output that the web server returns from this cgi:
HTTP/1.1 200 OK Connection: close Date: Wed, 29 Jan 2003 20:50:01 GMT Server: Apache/1.3.26 (Unix) mod_perl/1.27 mod_ssl/2.8.9 OpenSSL/0.9.6e Content-Type: application/pdf Client-Date: Wed, 29 Jan 2003 20:50:48 GMT Client-Peer: 1.2.3.4:80
All its returning back are the headers. No output from the Write(). Can anybody tell me what I'm doing wrong?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Problem converting HTML to PDF
by stephen (Priest) on Jan 29, 2003 at 21:56 UTC | |
by ehdonhon (Curate) on Jan 29, 2003 at 22:43 UTC | |
by Cody Pendant (Prior) on Jan 29, 2003 at 22:59 UTC | |
by ehdonhon (Curate) on Jan 29, 2003 at 23:10 UTC | |
Re: Problem converting HTML to PDF
by Dr. Mu (Hermit) on Jan 30, 2003 at 03:54 UTC | |
Re: Problem converting HTML to PDF
by Cody Pendant (Prior) on Jan 29, 2003 at 21:33 UTC | |
by ehdonhon (Curate) on Jan 29, 2003 at 21:43 UTC |