CodeIgniter Forums
linking to .pdf - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: linking to .pdf (/thread-40357.html)



linking to .pdf - El Forum - 04-06-2011

[eluser]miramichi[/eluser]
I have inherited the job of maintaining a site built with code igniter. So far so good. But I can't figure out how to get a link to work to a .pdf (404 Page Not Found). The .pdf file is in the same directory as the index file. The controller and page works fine, but the link goes nowhere. At the moment I have an absolute path to the .pdf

Thanks for your help.


linking to .pdf - El Forum - 04-06-2011

[eluser]miramichi[/eluser]
I think I am getting a little closer.

Instead of doing this in my controller:
Code:
$this->load->view('contract')
I want to do something like this:
Code:
$this->load->view('contract.pdf')
and store the .pdf in the view folder.

Or am I barking up the wrong tree?


linking to .pdf - El Forum - 04-06-2011

[eluser]LuckyFella73[/eluser]
Code:
$this->load->view('your_file')

is used to load HTML/ PHP files. A PDF files is nothing
your browser can render like HTML - so that is not the
way to go.
You can set a link to your .pdf file in your html code
and when clicking the pdf should open in your browser displayed
by the acrobat plugin.

If you still get a 404 page you have to adjust your htaccess file
for you needs. I would prefer to place the pdf file in seperated
directory and not at the root level.


linking to .pdf - El Forum - 04-06-2011

[eluser]miramichi[/eluser]
I have placed my .pdfs in a folder at the root level, but still get a 404.

Should I out the htaccess in that folder? Can you give an example of an htaccess that will allow the pdfs to be viewed?


linking to .pdf - El Forum - 04-07-2011

[eluser]InsiteFX[/eluser]
This is the key:
Code:
header("Content-Type: application/octet-stream");
Content-type application/x-pdf-document or application/pdf is sent while sending PDF file. Adobe Reader usually sets the handler for this MIME type so browser will pass the document to Adobe Reader when any of PDF MIME types is received.

InsiteFX


linking to .pdf - El Forum - 04-07-2011

[eluser]LuckyFella73[/eluser]
Is it common praxis to load .pdf files like every other view (sending the
right header) instead of just linking to the file? Doesn't make much sense
to me unless you generate the pdf file dynamicly maybe. But maybe I'm
wrong.

@miramichi
Depending on what hosting environment you have the .htaccess file looks
different. A .htaccess file for a CI installation COULD look like this:
Code:
RewriteEngine On
RewriteCond $1 !^(index\.php|flash|images|stylesheets|javascript|pdf_files|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]



linking to .pdf - El Forum - 04-07-2011

[eluser]miramichi[/eluser]
Thank you, header and .htaccess were the keys.