Professional Web Applications Themes

Serving up a pdf file - PERL Beginners

All, I have a page with a link "Quiz1". When the user clicks on the the link, a perl script will be summoned that will populate forms of a pdf doent. Now, I could create a new page at this point with a link to the newly created pdf, but could someone suggest a technique where I simply send the pdf to the user after the pdf forms have been populated? Does that sound like a redirect or does someone have a better suggestion? Thanks....

  1. #1

    Default Serving up a pdf file

    All,

    I have a page with a link "Quiz1".

    When the user clicks on the the link, a perl script will be summoned that
    will populate forms of a pdf doent.

    Now, I could create a new page at this point with a link to the newly
    created pdf, but could someone suggest a technique where I simply send the
    pdf to the user after the pdf forms have been populated?

    Does that sound like a redirect or does someone have a better suggestion?

    Thanks.
    David Guest

  2. #2

    Default Re: Serving up a pdf file

    Phillip,

    Thanks, but this is not quite what I was looking for.

    When the user clicks on "Quiz1" a perl script will be called to generate
    and compile a tex file using pdflatex. Once that is complete, I will have a
    file Quiz1.pdf which I want to send back to the user.

    Thanks.

    At 10:09 PM 7/21/04 +0000, Philipp Traeder wrote: 
    >
    >Hi David, 
    >
    >if I understand your problem correctly, you want to generate a pdf file when
    >the user clicks a link, and when the pdf is generated completely, you want[/ref]
    to 
    David Guest

  3. #3

    Default Re: Serving up a pdf file

    On Wednesday 21 July 2004 HH:53:19, David Arnold wrote: 

    Hi David, 

    if I understand your problem correctly, you want to generate a pdf file when
    the user clicks a link, and when the pdf is generated completely, you want to
    send it back to him?

    If yes, just create the pdf file on the fly and send it back - I don't know
    how to generate pdf files in perl, therefore I'll just give you an example
    that creates a text file (untested, for demonstration only):

    #!/usr/bin/perl -w

    use strict;
    use CGI;

    my $query = new CGI();

    # print the header (you need to modify this to the correct content-type for
    pdfs)
    print $query -> header(-type => 'text/plain');

    for (my $loop = 1; $loop <= 10; $loop++) {
    print "line $loop\n";
    }

    If you execute this as CGI script, the user will receive a text file that he
    can save. I think you should be able to do the same for PDFs.

    HTH,

    Philipp
    Philipp Guest

  4. #4

    Default Re: Serving up a pdf file

    On Wednesday 21 July 2004 HH:44:20, David Arnold wrote: 

    Hi David,

    please bottom post. 

    maybe I don't get it, but I think the base principle stays the same - as long
    as you specify the correct http content-type, you can to what you want before
    sending it back to the user, and the user will receive your script's output
    as a file (i.e. the browser should ask the user if it wants to open or save
    the file etc.). It should be transparent to the user whether a file is
    returned by the web server directly or if you create it on the fly.

    Let me re-write the example (untested, again):

    #!/usr/bin/perl -w

    use strict;
    use CGI;
    use CGI::Carp qw(fatalsToBrowser);
    use FileHandle;

    my $query = new CGI();

    print $query -> header(-type => 'text/plain');

    # call an external program to generate a file
    system('netstat > netstat.file')
    or die "could not call netstat : $!";

    # open the file and sent it back to the user
    my $fh = new FileHandle();
    open($fh, 'netstat.file')
    or die "could not open netstat file : $!";
    while (<$fh>) {
    print;
    }
    close($fh)
    or die "could not close handle to netstat file : $!";

    If I'm on the wrong track, let me know - otherwise this should do the trick.

    HTH,

    Philipp
    Philipp Guest

Similar Threads

  1. [PHP] help with ad serving
    By Curt Zirzow in forum PHP Development
    Replies: 2
    Last Post: July 22nd, 03:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139