Welcome Guest, Not a member yet? Register   Sign In
[resolved] loading a PDF as a view
#1

[eluser]SaminOz[/eluser]
Is there any reason that codeigniter would have a problem loading a PDF as a view?

I have a pdf document (a receipt) that is written by a library script to sub-folder of the view folder.

I have received these two errors.

Code:
Warning: Unexpected character in input: '' (ASCII=29) state=1 in C:\svn_checkout\sports-courts\trunk\system\application\views\admin\dashboard_facility\pdf_receipts\receipt.pdf on line 241
Code:
Parse error: syntax error, unexpected T_STRING in C:\svn_checkout\sports-courts\trunk\system\application\views\admin\dashboard_facility\pdf_receipts\receipt.pdf on line 241

I have tested the controller/function/parameter by loading a standard .php page which works fine - does anyone know that these errors might be caused by?

thanks.
#2

[eluser]bretticus[/eluser]
[quote author="SaminOz" date="1283937082"]Is there any reason that codeigniter would have a problem loading a PDF as a view?

I have tested the controller/function/parameter by loading a standard .php page which works fine - does anyone know that these errors might be caused by?
[/quote]

Try calling include('pdffile.pdf'); in a standard php page. It's the same thing. The include function will load any file, but it's expected to have parseable PHP or not. You shouldn't load file contents when no PHP is to be parsed from include, nor from views.

You are approaching this problem wrong. Use php's file functions to load the contents of the file (or just set your headers to force download on the PDF.) Calling view is not necessary to set headers.
#3

[eluser]SaminOz[/eluser]
Thanks bretticus, I used the headers idea from ryboe.com.

Do you have any suggestions on how to set the path to the file relatively - I have this working fine but only with a path like this( C:\\svn_checkout\\sports-courts\\trunk\\system\\application\\views etc) and would like to set things for server deployment later.

Thanks again, your help was invaluable.
#4

[eluser]bretticus[/eluser]
Try...

Code:
realpath(APPPATH . 'views/admin/dashboard_facility/pdf_receipts/receipt.pdf');


[EDIT]
Although, I'd stick these outside of views as they are not really view files. Actual MVC files should never really be publicly accessible anyway. I'd put a pdf folder in the same folder as index.php (same level as system.)
#5

[eluser]pbreit[/eluser]
You can't display a PDF in a web page. You can inly link to it in which case it will be downloaded or browsers may be able to display it in a window (using Acrobat Reader or Apple Preview). To embed a PDF in a web page, have a look at Scribd.
#6

[eluser]SaminOz[/eluser]
btw - there are some code igniter plug-ins for PDF stuff:

see www.digitaljunkies.ca/dompdf/ if interested
#7

[eluser]SaminOz[/eluser]
I ended up using my own version, not dompdf.

What I did find odd is that the following code did not output an intelligible file. Is this to do with the .pdf extension (as mentioned earlier in the post)?

Code:
//$data = file_get_contents(PDFPATH. 'receipt.pdf');
  $data = read_file(PDFPATH. 'receipt.pdf'); // Read the file's contents
  $name = 'Receipt';
  force_download($name, $data);
#8

[eluser]SaminOz[/eluser]
answer was $name = 'receipt.pdf';

I misunderstood the purpose of this parameter.




Theme © iAndrew 2016 - Forum software by © MyBB