[ic] generate pdf of current viewed page

Mike Heins mike at perusion.com
Fri Jul 23 12:30:22 EDT 2004

Quoting Carsten Jahnke (carstenjahnke at web.de):
> Hi list,
> I want my shop visitors to have the availability to generate a pdf of 
> their current cart items or checkout receipt.
> Therefor it is of course neccessary to be logged in so I have my 
> problems to use htmldoc.
> How do I pass the current page to htmldoc with its session context?
> I could send the current url with session id and stuff to a cgi-script 
> or a usertag calling htmldoc but first I tried to "hijack" the session 
> with a second browser window (to test the scenario *g*) but nifty little 
> interchange didn't let me outflank it.
> Am I able to get the current generated html page from an internal 
> interchange cache or something?

You can get it from @Vend::Output. If you add this UserTag (global):

UserTag create-pdf Routine <<EOR
sub {
    my $infile = catfile($Vend::Cfg->{ScratchDir}, "$Vend::Session->{id}.html");
    my $outfile = catfile($Vend::Cfg->{ScratchDir}, "$Vend::Session->{id}.pdf");
    open PAGE, "> $infile"
        or die "Cannot create pagefile $infile: $!";
    for(@Vend::Output) {
        print PAGE $$_;
    close PAGE;
    my $cmd = "htmldoc --continuous -f $outfile  $infile";
#::logDebug("ready to run htmldoc command=$cmd");
    system $cmd;
    if(-f $outfile) {
        $Tag->deliver( { type => 'application/pdf', file => $outfile });
        unlink $outfile;
    else {
        my $msg = errmsg("htmldoc failed to produce output with command: %s", $cmd);
    unlink $infile;

Then at the bottom of your page (if in foundation) or at the bottom of
your @_PAGE_BOTTOM_@ region (if standard/mike):

	[if cgi pdf][create-pdf][/if]

Then any time you pass a pdf=1 as part of the parameters passed to
the page, it will deliver a PDF instead.

I am not responsible for what htmldoc does with all the JavaScript,
though. 8-)

Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.765.647.1295  tollfree 800-949-1889 <mike at perusion.com>

Unix version of an Outlook-style virus:
It works on the honor system. Please forward this message to everyone
you know, and delete a bunch of your files at random.

More information about the interchange-users mailing list