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?


In reply to Problem converting HTML to PDF by ehdonhon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.