export to pdf using codeigniter & bootstrap - codeigniter

i have a web project. In my project, i would like to give button to export file to pdf. i'm using bootstrap & codeigniter.
can anyone give example for export file to pdf in codeigniter ?

Found this while trying to do the same. https://davidsimpson.me/2013/05/19/using-mpdf-with-codeigniter/
In place of redirect() function used on the page, you can use the code below to force download. Note that redirect() will only open the file in some browsers like chrome.
$this->load->helper('download');
$data = file_get_contents(base_url("downloads/reports/$filename.pdf")); // Read the file's contents
$name = 'mynewfile.pdf';
force_download($name, $data);
Don't forget to add the .pdf extension to $name

I am using TCPDF to generate pdf files in codeigniter. check this out.TCPDF examples

Related

Laravel 5.6: DOMPDF Doesn't Save PDF Files

I am using the DOMPDF Wrapper for Laravel 5 to create a PDF from a view.
<?php
$customer = Customer::findOrFail(Auth::user()->id);
return PDF::loadView('backend.profile.includes.pdf.pdf',
compact('customer'))->save(public_path('pdf/resume/test.pdf'));
When I access the related page, the file isn't saved in the public folder. Nothing happens.
You should use Laravel's filesystem to save the data from DOMPDF to a file. I'm not sure how your code looks that actually renders the PDF, but here is a general idea.
First, make sure to link the "public/storage" directory to "storage/app/public". Laravel can do this for you with the following command.
php artisan storage:link
Then you could do something like this to render the document with DOMPDF and save the file.
use Dompdf\Dompdf;
use Illuminate\Support\Facades\Storage;
$dompdf = new Dompdf();
$dompdf->loadHtml($view);
$dompdf->setPaper('letter', 'portrait');
$dompdf->render();
$file = $dompdf->output();
Storage::put('public/test.pdf', $file);
See this article for more details.

Is it possible to test file download in Laravel 5.4?

With Laravel 5.4, it's now easy to test file upload: https://laravel.com/docs/5.4/http-tests#testing-file-uploads
Is there a way to test file download too? Ex: I want to check if a CSV is generated on a click on a button.
I did not found anything about this. What are the best practices about file download testing in Laravel?
you can try with this solution to check if the file was generated while the clicked button
if($request->hasfile('nameOfInput'))
{
//your code
}

How can i download file in Codeingiter

I want to give download file option my webpage , but the file which i want to download is present on download link of another website , how can i directly download it from my webpage ,using CODEIGNITER
If you want download a file direct to your web site root folder use this code.
file_put_contents($_SERVER["DOCUMENT_ROOT"]."/your_folder_name/add_file_name.jpg..ect", "your_file_path_want_to_download");
hope it will help you.
You can download files using download helper in codeigniter. first you need to and $this->load->helper('download'); in your constructor or method. after that use following code for download.
force_download('/path/to/photo.jpg', NULL);
You can Use download helper in Codeigniter. simple load helper in your controller where you need like this
$this->load->helper('download');
here is ex
$data = 'Here is some text!';
$name = 'mytext.txt';
force_download($name, $data);

autoload twilio in codeigniter

I have just downloaded twilio-php-master.zip and extracted the file to the libraries folder in codeigniter. I would like to know what files to set on $autoload['libraries'] = array() to use the REST API.
Thank you.
First extract the Twilio folder inside the twilio-php-master.zip into the same level as your applications folder in codeigniter,
Next set $config['composer_autoload'] = 'Twilio/autoload.php'; in your config.php
lastly add use Twilio\Rest\Client; in the controller where you are going to use Twilio
Hope this helps you...

how and where can store images with laravel?

how and where I can store images using laravel?
context:
I want display some images in my main view (these are predefined by me).
I also want to store images uploaded by users, however, do not know where to store these images.
I'd like to call these from the view...
Thank you very much for the help. :)
Basically you can save your files wherever you want within your Laravel application provided that you have permissions to create directory and file.
But I prefer saving files in the storage/app folder. Laravel provides a simple API to manipulate files on disk. See the docs.
Update:
This answer was posted when Laravel was in version 5.2.
From version 5.3 on, you can easily create symbolic links by running the artisan command php artisan storage:link. See the docs.
Make directory for images in myapp/public/images and keep images on there.
<img src="{{URL('/images/logo.jpg')}}">
If you want to display them on your site store them in your public directory. Since they are uploaded by users you will need to pass them through a form. Here is an example of a controller.
$file = Input::file('picture');
$file->move(public_path().'/images/',$user->id.'.jpg');
The user will submit a form with a picture field. The two lines above will store it in the public directory in an images folder, with the relevant user's id as its name. Your probably best off making a model in your database for images and their paths. If you do, add these lines after the two above.
$image = new Image;
$image->path='/images/'.$user->id.'.jpg';
$image->user_id = $user->id;
$image->save();
To display it in the view simply set an $image variable to the correct image model in your controller and pass it to the view. Then pop its path in the src of the image.
<img src={{$image->path}} alt={{$image->path}}>

Resources