How to add page number in footer using mpdf in laravel - php

I'm using niklasravnsborg/laravel-pdf package in Laravel to generate a pdf. Now I want to add page number dynamically in footer part. Here is my code which I'm using correctly:
$config = ['instanceConfigurator' => function($mpdf) {
$mpdf->SetWatermarkText('DRAFT');
$mpdf->showWatermarkText = true;
}];
return PDFm::loadHtml($space.$result->document, $config)->download('draftAgreement.pdf');

You could configure your mpdf instance to include page numbers.
$config = ['instanceConfigurator' => function($mpdf) {
$mpdf->SetWatermarkText('DRAFT');
$mpdf->showWatermarkText = true;
$mpdf->setFooter('{PAGENO}');
}];
return PDFm::loadHtml($space.$result->document, $config)->download('draftAgreement.pdf');

Related

How to add watermark to every page using mpdf in laravel

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');

Dhtmlx load data into dropdown

I'm using Dhtmlx scheduler and it works really fine, but I have some issue with customization of the LightBox. I have added a dropdown list and I would like to load data from my MySqli db using json.
Here is my code
require_once('codebase/connector/scheduler_connector.php');
require("codebase/connector/db_mysqli.php");
$mysqli = new mysqli("$db", "$dbn", "$pw", "$tb");
$listcollab = new OptionsConnector($mysqli, "MySQLi");
$listcollab->render_table("Operator","ID","ID(value),Name(label)");
$scheduler = new JSONSchedulerConnector($mysqli, "MySQLi");
$scheduler->set_options("coll", $listcollab); //without this scheduler charge data
$scheduler->render_table("Agenda","ID","AppStart,AppEnd,Cliente,Servizio");
This is Client side
var list = scheduler.serverList("coll");
function init() {
scheduler.config.xml_date = "%Y-%m-%d %H:%i";
scheduler.config.prevent_cache = true;
scheduler.config.first_hour = 8;
scheduler.config.last_hour = 21;
scheduler.config.limit_time_select = true;
scheduler.locale.labels.section_location = "Servizio";
scheduler.locale.labels.section_select = 'Seleziona';
scheduler.config.details_on_create = true;
scheduler.config.details_on_dblclick = true;
scheduler.config.prevent_cache = true;
scheduler.config.lightbox.sections = [
{name:"CLIENTE", height:90, map_to:"Cliente", type:"textarea" , focus:true},
{name:"Servizio", height:43, type:"textarea", map_to:"Servizio" },
{name:"select", height:40, map_to:"ID", type:"select", options:scheduler.serverList(list)},
{name:"Collaboratore", height:43, type:"textarea", map_to:"auto" },
{name:"Orario", height:72, type:"time", map_to:"auto"}
];
scheduler.init('scheduler_here', new Date(2015, 9, 23), "week");
scheduler.load("connessione.php", 'json');
var dp = new dataProcessor("connessione.php");
dp.init(scheduler);
Can someone helps me to get data from db using php?
Thanks in advance
What you use on server side? If you have PHP and dhtmlxConnector on a backend, this article should help.
If you've implemented data loading manually then you'll need these two methods:
http://docs.dhtmlx.com/scheduler/api__scheduler_serverlist.html
http://docs.dhtmlx.com/scheduler/api__scheduler_updatecollection.html
The common way to go is following - you declare options as named collection using scheduler.serverList method, and then update using scheduler.updateCollection when data is loaded from the server

how to generate pdf using blade view with tcpdf laravel 5?

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');
}

Paste a PDF-file into another PDF with ZendPDF

Is it possible to "merge" or "paste" a PDF-file into antother PDF? Or must it be a image instead?
The PDF i want to to paste or merge, is a simple picture that is going to appear at the bottom of the finished PDF:
//Generate the "Original" PDF here..
function addReklam($reklamblad) //The PDF that should be merged into the PDF that is created above
{
//Count how many pages that has been created, and add it at the bottom of the PDF:
if($this->drawed_lines<52)
{
$this->active_page = $this->pdf->pages[2];
}
elseif($this->drawed_lines<92)
{
$this->active_page = $this->pdf->pages[3];
}
elseif($this->drawed_lines<132)
{
$this->active_page = $this->pdf->pages[4];
}
else
{
$this->active_page = $this->pdf->pages[5];
}
//$this->active_page = $this->pdf->pages[5]; // page 5 is the last
//Add it here???
}
My recommendation would be to use the Zend_Pdf::load() method to load the "Original" PDF file into a local instance of Zend_Pdf and then you can access the pages using the pages[] array as in your sample code and use the all the standard functions like drawImage() etc to make the needed modifications prior to saving the updated version.

How to capture view content in symfony for pdf output

I'm using Symfony and mPDF.
I'm trying to integrate both but am running into some problems.
I need to capture the content of a view but can't see how to do it.
public function executePDF(sfWebRequest $request)
{
$this->object = $this->getRoute()->getObject();
require_once 'mpdf.php';
/* Example code from mPDF site */
$mpdf=new mPDF('win-1252','A4','','',20,15,48,25,10,10);
$mpdf->useOnlyCoreFonts = true; // false is default
$mpdf->SetProtection(array('print'));
$mpdf->SetTitle("Acme Trading Co. - Invoice");
$mpdf->SetAuthor("Acme Trading Co.");
$mpdf->SetWatermarkText("Paid");
$mpdf->showWatermarkText = true;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->SetDisplayMode('fullpage');
$this->setLayout(false);
$html = $this->getResponse()->getContent();
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
}
With the above example, $html is returned as an empty string. I have a view template relating to this action (PDFSuccess.php) which accesses the $object and has the HTML that mPDF will use.
Thanks for any help.
As it is just now, when accessing this action it does open a PDF correctly, but there is no content in it.
Thanks
Haven't done this in this specific context but you could try:
$html = $this->getPartial('moduleName/partialName');
... where the template is a partial (_partialName) inside a given module. As it's a partial, there's no need to switch off the layout.
You can also pass variables to it:
$html = $this->getPartial('moduleName/partialName', array('var' => 'something'));
...
If that doesn't work, here's a question relating to email templates that contains an alternative way of doing this (see the accepted answer):
Email body in Symfony 1.4 mailer?

Categories