How to view a pdf file on your web page?
If the pdf file parked in a web folder like /cgi-bin/files/example.pdf, you can easily show it in a page using the following code
so the page will show the pdf file embedded on the web page like the following
but lets say that, the pdf file is not accessible on web page, that means its parked out of web directory for the sake of security. then how to get the file viewed on the web page?
I did the following thing to achieve showing the pdf file out of web directory for testing.
this method is not preferred to show secured documents.
cheers!
If the pdf file parked in a web folder like /cgi-bin/files/example.pdf, you can easily show it in a page using the following code
<embed src="/cgi-bin/files/example.pdf#toolbar=0&navpanes=1&scrollbar=0" width="100%" height="500">
so the page will show the pdf file embedded on the web page like the following
but lets say that, the pdf file is not accessible on web page, that means its parked out of web directory for the sake of security. then how to get the file viewed on the web page?
I did the following thing to achieve showing the pdf file out of web directory for testing.
- created a tempfile handler within web directory
use File::Temp qw/ tempfile /;
use File::Copy;
use File::Basename;
my($fh, $fname) = tempfile('TEMP_XXXX', SUFFIX => '.pdf', DIR =>'d:/Inetpub/cgi-bin/temp/'); - copied the file to the temp file
copy("d:/files/example.pdf","$fname") or die "Copy failed: $!";
$output_file = "temp/".basename($fname); - embedded the temp file on the web page
< embed src="$output_file#toolbar=0&navpanes=1&scrollbar=0" width="100%" height="500" >
this method is not preferred to show secured documents.
cheers!
Comments
Post a Comment