Generate PDF using DomPDF - php

hello i'm newbie and need your help buddy... please kindly help for a minute
So, i want to generate PDF but i dont know what should i do, please look at this
public function pdfview($id){
$halaman="tindaklayanan";
$keluhan = keluhan::findOrFail($id);
$tindak = DB::table('tindakans')
->join('keluhans','keluhans.id','=','tindakans.id_keluhan')
->select(DB::raw('keluhans.id, perbaikan_sementara, ttd_tanggung1, ttd_tanggung2, revisi_dokumen,
target_verifikasi'))->get();
//dd($tindak);
$analisa = DB::table('analisas')
->join('tindakans','tindakans.id','=','analisas.id_tindakan')
->join('keluhans','keluhans.id','=','tindakans.id_keluhan')
->select(DB::raw('id_tindakan, analisa, tindakan, pic, tanggal_pelaksanaan'))->get();
return view('Laporan.pdfview',compact('keluhan','tindak','analisa','halaman'));
//$pdf = PDF::loadHTML('<h1>Test</h1>');
//return $pdf->stream();
}
I've an HTML view and it's finished but how to generate as PDF ? see the command line its work, but i want to load my view that compact('keluhan','tindak','analisa','halaman')

$pdf = \PDF::loadView('Laporan.pdfview',compact('keluhan','tindak','analisa','halaman'));
return $pdf->stream();
Its work now thank you.

Related

fpdf Output(name) not working if adding Image()

I here trying to create a pdf with fpdf and want to display and rename the web title with Output(name) it worked fine before, but after I added Image() it didn't work, did I do something wrong?
require('../libs/fpdf/fpdf.php');
$no_ref = 'TJ100001';
$dir = 'https://www.vuien.my.id/assets/img/logo.png';
$pdf = new FPDF('l','mm','A5');
$pdf->AddPage();
$pdf->Image($dir,10,7,10);
$filename = 'Invoice '.$no_ref.'.pdf';
$pdf->Output($filename,'I', true);
with add Image() :
screenshot
With no add Image() :
screenshot

How to convert view to pdf in php codeigniter using mpdf?

As I am new to CodeIgniter, I am trying to convert a view to PDF using mpdf, but I am getting following error :
Call to undefined function mb_internal_encoding()
And the code in my controller file is:
public function DownloadPDF()
{
$this->load->library('M_pdf');
$data =array('id'=>'1',
'name'=>'test'
);
$html=$this->load->view('user/Invoice', $data, true);
$pdfFilePath ="mypdfName-".time()."-download.pdf";
$pdf = $this->M_pdf->load();
$pdf->WriteHTML($html,2);
$pdf->Output($pdfFilePath, "D");
}
Please, can anyone help me to solve this error?
Thanks in advance!

PDF data displayed but file not downloaded

I want to preview and download an order invoice pdf using this code :
public function generatePDFByIdOrder()
{
$order = new Order(1); //I want to download the invoice PDF of $order_id '1'
if (!Validate::isLoadedObject($order)) {
throw new PrestaShopException('Can\'t load Order object');
}
$order_invoice_collection = $order->getInvoicesCollection();
$this->generatePDF($order_invoice_collection, PDF::TEMPLATE_DELIVERY_SLIP);
}
public function generatePDF($object, $template)
{
$pdf = new PDF($object, $template, Context::getContext()->smarty);
$pdf->render();
}
And calling it with the following code :
$order = new order();
echo $order->generatePDFByIdOrder();
I have the pdf's data printed on the browser console but not downloaded .
How can I manipulate that data to download a pdf file ?
PrestaShop use TCPDF.
Edit generatePDF in this way:
public function generatePDF($object, $template)
{
$pdf = new PDF($object, $template, Context::getContext()->smarty);
$pdf->Output('name.pdf', 'I');
}
I guess you only have to set the proper headers before rendering the PDF with TCPDF like so :
header("Content-type:application/pdf");
But "downloading" a PDF will depend on what the user's browser settings. It might download them (in which case you'd have to set another header called Content-Disposition:attachment) or display it inside the browser.
We recommend you, to create a separate controller to render the PDF file and to always open that controller in a new tab. It will help you to have separate logic using DOMPDF library.
Invoice controller will be as follows (invoice.php)
include_once(_PS_MODULE_DIR_.'supercehckout/libraries/dompdf/dompdf_config.inc.php');
class SuperCheckoutInvoiceModuleFrontController extends ModuleFrontController
{
public function initContent()
{
parent::initContent();
$this->generateInvoice(ORDER_ID);
}
}
Note: SuperCheckout is the example module name.
generateInvoice() function will be as follows:
function generateInvoice($order_id)
{
$dompdf = new DOMPDF();
$html = utf8_decode(INVOICE_HTML);
$dompdf->load_html(INVOICE_HTML);
$dompdf->render();
}

Rendering html to pdf

I am new to Laravel. I want to convert my HTML page into PDF therefore I am using:
https://github.com/barryvdh/laravel-snappy
Now from my controller I am using the following code:
$data = $this->getdata();
$html = view('myview', [ 'data' => $data] )->render();
$pdf = \App::make('snappy.pdf.wrapper');
$pdf->loadHtml($html);
return $pdf->inline();
When I dump or return the $html variable, it's giving the desire view on the browser but when I convert it its not giving that output. My HTML page is also using Bootstrap but I think after rendering its just a normal HTML string.
Can anyone tell what I am missing here?
I have also tried $pdf->loadView() but it's not working.
Take a look at the loadView function.
Try this:
$data = $this->getdata();
$pdf = \App::make('snappy.pdf.wrapper');
$pdf->loadView('my.view', $data);
return $pdf->inline();
And print what's returned by the laodView to see if it get your view correctly.

codeigniter convert excel file to pdf

I want to ask how can I convert excel to pdf?
I want to put 5 excel files and after I click upload in convert to 1 pdf?
for now I use in this code:
/**
* Example: DOMPDF
*
* Documentation:
* http://code.google.com/p/dompdf/wiki/Usage
*
*/
public function index() {
// Load all views as normal
$this->load->view('test');
// Get output html
$html = $this->output->get_output();
// Load library
$this->load->library('dompdf_gen');
// Convert to PDF
$this->dompdf->load_html($html);
$this->dompdf->render();
$this->dompdf->stream("welcome.pdf");
}
the library:
class Dompdf_gen {
public function __construct() {
require_once APPPATH.'third_party/dompdf/dompdf_config.inc.php';
$pdf = new DOMPDF();
$CI =& get_instance();
$CI->dompdf = $pdf;
}
}
first of things , you have to dump all excel to php array or var , after that you can create pdf as you want , this is simple php script for convert excel to pdf , you can use it and convert it to subclass of codeigniter as well
please check this url
PHP read excel file
when you use that class your excel data will be with you so you can use another class for pdf and this class will help you
codeigniter create PDF file
hopeful this is helpful for you .
I do not understand the problem.
like in this code:
$this->load->helper(array('dompdf', 'file'));
// page info here, db calls, etc.
$html = $this->load->view('home', $data, true);
pdf_create($html, 'filename')
or
$data = pdf_create($html, '', false);
write_file('name', $data);
how i put after i upload excel file and cover it to pdf?
this function is only for HTML

Categories