-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Howdy,
We just started doing something similar to what you're looking to do.
We're using PDF::Reuse to generate our PDF files, are using
CGI::Application, and it's running under mod_perl.
On Wed, 10 Sep 2003, Steve Hay wrote:
> Hmm. So I use CGI-Application to generate the file and then send a
> redirect header. The page that the user is redirected to is then
> handled by a non-CGI-Application CGI script that downloads that file, yes?
>
> I would rather do it in one step rather than two, and all inside
> CGI-Application, if possible.
We considered this too. Like you said, it seems a like a few too many
steps, though it would work in a pinch.
> It seems a shame to have to step outside of CGI-Application to achieve
> something so simple.
Right. I don't think you have to, you can get CGI::App to do what you
need here.
> So I prefer not to use the -attachment argument in those headers. The
> browser will still pop up a "Save As..." dialogue box anyway if it
> doesn't recognise the MIME type or has no action configured for it.
I think you're looking for the 'Content-disposition' header here. By
setting it to inline, it suggests to the browser to view it inline,
instead of prompting to save it.
> >Then print the data to the browser.
> >
> >For PDFs and ZIPs, I'm not sure if you can simply print, but let us know if
> >you succeed.
> >
> Yes, you can print anything you like to the browser as long as (1)
> you've set the correct Content-Type in the headers (using the -type
> argument) and (2) you've set both the filehandle that you're reading the
> file in from and STDOUT that you're writing the file out to to "binary
> mode" if you're on a platform like Windoze that does nasty CRLF
> translations otherwise.
Agreed, printing does work, which is how we're doing it. There was
recently some discussion on Perlmonks about this exact topic (PDF's and
CGI::Application):
http://perlmonks.org/index.pl?node_id=288443
Now, what's not discussed it what you mentioned about not wanting to read
the entire file in. That's an honorable goal :-) We actually aren't
doing that... it was just simpler to read the whole file in, send it to
the browser, and just use 'exit' afterwards to kill off that Apache child.
Our files also aren't particularly big (1MB max, usually much less).
This isn't particularly well documented because it's not recommended for
typical use -- however, there is a way to tell CGI::Application that
you've already sent data to the browser.
CGI::Application uses the following code to send data to the browser:
# Send output to browser (unless we're in serious debug mode!)
unless ($ENV{CGI_APP_RETURN_ONLY}) {
print $output;
}
Which means that if you set the $ENV{CGI_APP_RETURN_ONLY} variable, you
can send headers and data to the browser within your run_mode, and
cgi::app won't send data to the browser.
That would allow you to send your PDF any way you like, including reading
it in line by line instead of slurping the whole file in.
The problem with the above CGI::App behaviour not being documented is that
it can dissapear. I really feel that there are cases where it's necessary
to send stuff to the browser from within the run_mode, and I feel yours is
a valid one. I hope Jesse will leave the functionality in there, or
perhaps even make it easier by making an accessor method for it :-)
-Eric
- --
Eric Andreychek | Lucy: "What happens if you practice the
Eric Conspiracy Secret Labs | piano for 20 years and then end up not
suppressed | being rich and famous?"
http://openthought.net | Schroeder: "The joy is in the playing."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE/Xy4IR5UKaDAjAG4RArq2AJ9F4XQFNuPSdwwHvKNt6tmTKdstnACaAzAZ
R5CzZ4Un7SV+PZg2sCY0UlQ=
=Fn5S
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.