Michael Lake wrote:
> I wish to create some PDF docs using pdflib on the server and send them
> to a users browser.
> I have a perl prog that creates my forms and its working OK but I dont
> know how to deliver the output from the perl cgi script to the users
> browser.
> --- PERL PROGRAM ---
> #!/usr/bin/perl -w
> use pdflib_pl 3.03;
>
> my $p = PDF_new();
> PDF_open_file($p, ""); # Generate PDF entirely in memory. See the PDFlib
> manual.
> # Here we write the pdf stuff...
> PDF_close($p);
>
> my $buf = PDF_get_buffer($p);
> # Use the PDF data contained in the buffer buf
> PDF_delete($p);
> ----------------------------
>
> --- Simple CGI SCRIPT ---
> #!/usr/bin/perl
> use strict;
> use CGI;
>
> my $q = new CGI; # create new CGI object
> print $q->header,
> $q->start_html('hello world'),
> $q->h1('hello world'),
>
> print $q->a({href=>"out.pdf"}, "Your PDF File"); # this if its reading
> from disk
> print $q->a({href=>"???????"}, "Your PDF File"); # this if its reading
> from memory
>
> $q->end_html;
> ----------------------------------
Suggestion 1: make the script output the PDF as the content, no HTML:
print "Content-type: application/x-pdf\r\n"; # or whatever the content type
should be
print "Content-length: $pdflen\r\n"
print "\r\n"
print $pdfbuf;
Suggestion 2: write some HTML, but if the CGI parameter 'pdf' is found, write the PDF
my $q = new CGI; # create new CGI object
if ($q->param('pdf'))
{
print "Content-type: application/x-pdf\r\n"; # or whatever the content type
should be
print "Content-length: $pdflen\r\n"
print "\r\n"
print $pdfbuf;
}
else
{
print $q->header,
$q->start_html('Get a PDF'),
$q->h1('PDF Download'),
print $q->a({href=>"$ENV{SCRIPT_NAME}?pdf=1"}, "Click for your PDF File");
$q->end_html;
}
HTH
cheers
rickw
>
> Mike
> --
> --------------------------------------------------------------------
> Michael Lake
> Active caver, Linux enthusiast and interested in anything technical.
> --------------------------------------------------------------------
> --
> SLUG - Sydney Linux User's Group - http://slug.org.au/
> More Info: http://lists.slug.org.au/listinfo/slug
--
_________________________________
Rick Welykochy || Praxis Services
That that is is that that is not is not.
--
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug