0

I want to download a PDF file from an associative array which looks like this:

$Array_data= Array(
[0] => Array
    (
        [Date] => 2017-01-02
        [Name] => Asia consumer MC Alpha bmk - risk
        [Level] => .333000
    )

[1] => Array
    (
        [Date] => 2017-01-03
        [Name] => Asia consumer MC Alpha bmk - risk
        [Level] => .333000
    ))

I have tried many libraries named snappypdf, Fpdf, codedge/laravel but nothing seems to work.

I've tried this:

$pdf = new PDF();
$pdf->SetFont('Arial','',48);
$pdf->AddPage();
$pdf->Cell(40,10,"Hello World!",15);
$pdf->Output();

And this

$string = json_encode($Array_data); 
$response = new Response($string);
$disposition = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
    'foo.pdf');

return $response->headers->set('Content-Disposition', $disposition);

After searching nothing seems to work. How can I get this done?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Rajat
  • 111
  • 4
  • 14

1 Answers1

0

Here is very good library to create an PDF in laravel:

To export files to pdf, you will have to include "dompdf/dompdf": "~0.6.1", "mpdf/mpdf": "~5.7.3" or "tecnick.com/tcpdf": "~6.0.0" in your composer.json and change the export.pdf.driver config setting accordingly.

Excel::create('Filename', function($excel) {

    $excel->sheet('Sheetname', function($sheet) {

        $sheet->fromArray(array(
            array('data1', 'data2'),
            array('data3', 'data4')
        ));

    });

})->export('pdf');

The below library is used for excel export but it provides the functionality to download PDF.

Check it here: http://www.maatwebsite.nl/laravel-excel/docs/export

Sagar Arora
  • 1,743
  • 1
  • 10
  • 19
  • Thank you so much @Sagar Arora it worked i was using the maatwebsite for excel export and now it worked for all thanks again Man :) – Rajat May 02 '17 at 06:45
  • hey Sagar i am getting new issue now if my table has more number of columns then some column gets hidden [see this](http://imgur.com/kRRJ7K9) – Rajat May 02 '17 at 09:46