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
Related
I'm using niklasravnsborg/laravel-pdf package in laravel to generate a pdf. In this code i added watermark but that watermark is coming only on the last page though i wanted that to be in every page.
$pdf = PDFm::loadHtml($result->document);
$pdf->mpdf->SetWatermarkText('DRAFT');
$pdf->mpdf->showWatermarkText = true;
return $pdf->download('hdtuto.pdf');
From the documentation, it should work. Could you however, give the following a try?
$config = ['instanceConfigurator' => function($mpdf) {
$mpdf->SetWatermarkText('DRAFT');
$mpdf->showWatermarkText = true;
}]
PDF::loadHtml($result->document, $config)->download('hdtuto.pdf');
In this case, we are initialising the PDF instance with the right configuration instance, instead of doing it after loading the HTML.
mPDF doc states that
The watermark will be added to each page when the Footer is printed if the variable $showWatermark is set to 1 or true.
Try to add header/footer to your PDF and set corresponding flags
If any one trying to use blade file instead of direct html document, you can use view function which will return html content to the loadHtml method.
$config = ['instanceConfigurator' => function($mpdf) {
$mpdf->SetWatermarkText('DRAFT');
$mpdf->showWatermarkText = true;
}]
$pdf = PDF::loadHtml(view('path.to.blade_file', $blade_data), $config);
return $pdf->stream('DocumentName.pdf');
if you want to use an image as watermark
$config = ['instanceConfigurator' => function ($mpdf) {
$mpdf->SetWatermarkImage(asset('path/to/image_file'));
$mpdf->showWatermarkImage = true;
// $mpdf->watermarkImageAlpha = 0.2; // image opacity
// dd($mpdf) // show all attributes
}];
$pdf = PDF::loadHtml(view('path.to.blade_file', $blade_data), $config);
return $pdf->stream('DocumentName.pdf');
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.
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();
}
I'm using Code Igniter framework, and tcpdf third-parties
I have a global variable in controller :
public $pdf_content = '';
here is some of my function to book :
$data['success'] = $this->hotel_model->set_hotel(); //get the data from database
//view reservation detail
$this->load->view('hotel/header');
$this->load->view('hotel/success', $data );
$this->load->view('hotel/footer');
//assign the HTML page into global variable
$this->pdf_content = $this->load->view('hotel/success', $data , TRUE);
In my view file I'm using a button to download the HTML as pdf file, here is the download function :
public function download(){
$this->load->library("Pdf");
$this->load->helper('pdf_helper');
$pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
// Add a page
$pdf->AddPage();
$pdf->writeHTMLCell(0, 0, '', '', $this->pdf_content , 0, 1, 0, true, '', true);
$pdf->Output('invoice.pdf', 'I');
}
Both function located inside the same controller.
I think there is nothing wrong in my code based on any tutorial I ever read.
But it downloaded some blank page instead, and when I try to assign string value into $pdf_content, it works fine, The string value is written into the downloaded PDF file.
Anybody know what I missed there?
Or there is something wrong in my code?
Any help is appreciated.
There are multiple ways. The easiest would be to save the page as pdf manually (ctrl+p) and then make it available as download. OR, you can show the page and run the following script in the bottom of the body.
<script>
var yourName = "someName';
document.title = yourName;
window.print();
</script>
This fires the ctrl+p command and allows users to either print or save the page.
I'm trying to create a pdf using laravel 5 and https://github.com/elibyy/laravel-tcpdf
i have a form of 20 pages writing in laravel blade when my client fill the form and click submit i want to generate pdf for him and save it
i try to do it like this in my controller
public function createPDF()
{
$pdf = Input::get('pdf',null);
$company = Input::get('company',null);
$branch = Input::get('branch',null);
$sub_branch = Input::get('sub_branch',null);
$form_type = Input::get('form_type',null);
$form_name = Input::get('form_name',null);
$form_heb_name = Input::get('form_heb_name',null);
$sig_path=FormsController::getSignature_file();
$data=compact('company','branch','sub_branch','form_type','form_name','form_heb_name','sig_path');
Input::flash();
if ($pdf)
{
$pdf = new TCPDF();
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
$pdf->writeHTML(view('forms.'.$company.'.'.$branch.'.'.$sub_branch.'.'.$form_type.'.'.$form_name, $data)->render());
$filename = storage_path().'/forms_pdf/10006/26/4718326/'.$form_name.'.pdf';
$pdf->output($filename, 'I');
return redirect('forms');
}
return view('forms.'.$company.'.'.$branch.'.'.$sub_branch.'.'.$form_type.'.'.$form_name , $data);
}
bat its not working it's create 2 pdf page with All fields on top of each other
how to fix it?
In addition, I want to save the pdf in a way it can not be edited file how can i do it?
thanks.
I will try to give you a step by step answer (tested for laravel 5.1):
Before using it, be sure that you installed the TCPDF service provider correctly:
Installing TCPDF service provider
In composer.json, add this package:
"require": {
"elibyy/laravel-tcpdf": "0.*"
}
Run composer update
in config/app.php add this service provider
'providers' => [
//..
Elibyy\TCPDF\ServiceProvider::class,
]
Run php artisan vendor:publish , that will generate config/laravel-tcpdf.php in your files
Generate the pdf in your controller
public function createPDF()
{
[...]
//get default settings from config/laravel-tcpdf.php
$pdf_settings = \Config::get('laravel-tcpdf');
$pdf = new \Elibyy\TCPDF\TCPdf($pdf_settings['page_orientation'], $pdf_settings['page_units'], $pdf_settings['page_format'], true, 'UTF-8', false);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
$pdf->writeHTML(view('forms.'.$company.'.'.$branch.'.'.$sub_branch.'.'.$form_type.'.'.$form_name, $data)->render());
$filename = storage_path().'/forms_pdf/10006/26/4718326/'.$form_name.'.pdf';
$pdf->output($filename, 'I');
return redirect('forms');
}