I'm using PDF::Create to make on-the-fly pdfs as part of a CGI application. It works fine, but only because I have bodged up a crude alteration to the add function in Create.pm. The original function is:
sub add { my $self = shift; my $data = join '', @_; $self->{'size'} += length $data; if (defined $self->{'fh'}) { my $fh = $self->{'fh'}; print $fh $data; } else { $self->{'data'} .= $data; } }
This does one of two things with any new bit of data: either it prints it to a previously opened file handle, or it stores it in the pdf object for, AFAIK ultimate dumping to... filehandle? (not sure - I'm afraid the close sub is a bit beyond me - it seems to call itself from within itself, though I'm sure there's more to it than that).

In any event, this creates PDF files ok, but I want it to send the PDF data to the web browser. The only way I could find to do that is to install a local copy of the module and alter it to
sub add { #I, George Sherston, edited this function 6/2002; my $self = shift; my $data = join '', @_; $self->{'size'} += length $data; # if (defined $self->{'fh'}) { # my $fh = $self->{'fh'}; # print $fh $data; print $data; # } # else { # $self->{'data'} .= $data; # } }
Now it works (I include a pdf header in my script) - the pdf appears straight on the browser screen as desired, with no intermediate saving and retrieving.

BUT this is obviously a BAD THING (tm) from the point of view of portability and future generations. So my question is whether any monk knows how I can achieve my aim without editing the module. I'd have thought it wd be a thing people wanted to do, so wd probably be possible. But I've tried: I think the first of these fails because the filehandle has to be "an already opened filehandle". So maybe the solution lies in making the module think that STDOUT is "already open". But I thought it was the 7/11 of filehandles, and never closed...

I'd be most grateful for any light sibling monks can shed on this.

§ George Sherston

In reply to PDF::Create - send output to STDOUT? by George_Sherston

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.