Show a PDF file to the user with perl or php, not creating it nor download it. Just show it.

Posted by dimassony on Stack Overflow See other posts from Stack Overflow or by dimassony
Published on 2011-01-13T11:58:15Z Indexed on 2011/01/13 12:53 UTC
Read the original article Hit count: 187

Filed under:
|
|
|
|

Hello guys. I want to show my users PDF files. The reason why I use cgi to show the pdf is I want to track the clicks for the pdf, and cloak the real location of the saved pdf.

I've been searching on the Internet and only found how to show save dialog to the users and creating a pdf, not show the files to the users.

What I wanted for is show the users my pdf files, not creating or download the pdf. Here is what I got form the official php documentation:

<?php
header('Content-type: application/pdf');
readfile('the.pdf');
?>

Also my google-search-result perl code:

open(PDF, "the.pdf") or die "could not open PDF [$!]";
binmode PDF;
my $output = do { local $/; <PDF> };
close (PDF);

print "Content-Type: application/pdf\n";
print "Content-Length: " .length($output) . "\n\n";
print $output

if you do it on ruby, please say it to me. But I'm not sure if my server support rails.

Sorry if my code is too far away from the method to show the pdf, since I don't know anything about pdf processing and how to implement this problem.

Lets assume that the users have the Adobe Reader plug-in. So, how to fix my problem?

© Stack Overflow or respective owner

Related posts about php

Related posts about ruby