any way to add malayalam font to PDF generation. any methods existing?
mPDF supports default malayalam font. after including mpdf folder to third party directory in codeIgniter insert code like
$html = $this->load->view('masterentries/pdfReport',$data,TRUE);
include_once APPPATH.'/third_party/mpdf/mpdf.php';
$pdf = new mPDF('ml', 'A4');
$pdf->SetFooter($_SERVER['HTTP_HOST'].'{PAGENO}|'.date(DATE_RFC822));
$pdf->WriteHTML($html); // write the HTML into the PDF
$pdf->Output();
will produce the pdf containing malayalam.
Related
I'm using mPDF to export a large table to a PDF. As I've read online, I need to break my HTML content into chunks and pass them to WriteHTML method one by one.
But looks like my bootstrap CSS is not getting exported when I do this. My table borders are not visible. No paddings...etc.
How can I achieve both these tasks?
This is my code:
$content_chunks = str_split($content, 1000);
$pdf = new Pdf();
$mpdf = $pdf->api; // fetches mpdf api
$mpdf->SetHTMLHeader(static::buildHeader());
$mpdf->SetHTMLFooter('Generated On: ' . date("r").'||{PAGENO}');
foreach($content_chunks as $html)
{
$mpdf->WriteHTML($html);
}
return $mpdf->Output($file_name,'D');
This is what the official docs say about breaking large HTML into chunks. But I can't find any information with related to exporting bootstrap css.
I've got this code to export some data into a pdf. And I would like to add css from an external css file (which is not mentionned in the html used)
/*********************************** Export PDF ****************************************************/
if($request->query->get('exportPDF')!= null){
// Configure Dompdf according to your needs
$pdfOptions = new Options();
$pdfOptions->set('defaultFont', 'Arial');
// Instantiate Dompdf with our options
$dompdf = new Dompdf($pdfOptions);
// Retrieve the HTML generated in our twig file
$html = $this->renderView('dashboard/user_table.html.twig', [
'users' => $users
]);
// Load HTML to Dompdf
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
$dompdf->setPaper('A3', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser (force download)
$dompdf->stream("exportUsers.pdf", [
"Attachment" => true
]);
}
The user_table.html is only a file with a <table>
who has some class from a css file loaded in an other template. That means for DomPDF the file who contains the css is unkown and, as a result I have a table with no css in my pdf.
I've tried to add the stylesheet in my html directly but the import isn't working like that neither. But I don't want to add it in the html anyway, the css is loaded is a more hight level template.
How to add external files (like bootstrap etc etc) from this structure ? I do not know if this is even possible. Thanks for the help ;)
the css file must be referenced in the HTML you give to DomPDF.
If you don't want to change your twig template, you can use a workaround like this :
$dompdf = new Dompdf();
$html = $this->renderView('dashboard/user_table.html.twig', [
'users' => $users
]);
$html .= '<link type="text/css" href="/absolute/path/to/pdf.css" rel="stylesheet" />';
$dompdf->loadHtml($html);
Note that adding a link tag to the body is not valid according to HTML specifications. With the current Dompdf version, it works but it may not work in future versions.
You can always use solutions like this Including a non-twig file from twig read external file contents right into templates attribute, so css will be rendered inline and will be compatible with mpdf.
i am using codeigniter i am working on invoice and i want to print a PDF file of my invoice page here is my controller.
$pdfFilePath ='invoice.pdf';
$data=$this->singleinvoice($invoiceId);
ini_set('memory_limit','32M');
$html = $this->load->view('invoice/invoicetopdf', $data, true);
$this->load->library('pdf');
$pdf = $this->pdf->load();
$pdf->SetFooter($_SERVER['HTTP_HOST'].'|{PAGENO}|'.date(DATE_RFC822));
$pdf->WriteHTML($html);
$pdf->Output($pdfFilePath, 'D');
redirect("invoice");
when i echo $html veriable is show fine but when it output the pdf .it has no css styling i mean it convert the HTML without any of my css Style.
i also tried the following but no luck.
$style=file_get_contents(base_url().'_assets/css/bootstrap.css');
$pdf->WriteHTML($style,1);
$pdf->Output($pdfFilePath, 'D');
Now i want to convert my HTML page to PDF as it is shown to the public with complete styling and markups.
does it possible any suggestion or solution ?
you have to convert your Page Structure from DIV to Traditional Table structure.
arrange your elements contents etc.into table or tables.
then try some basic CSS.
because most of CSS are not supported in mpdf or any other pdf converter.
Click here
to know what(CSS) is supported and what is not in mpdf.
This is the code for index which will export what ever is in page under HTML varialbe:
<?php
require('fpdf/fpdf.php');
$html = 'kkjkjkjkjjkj';
$pdf = new FPDF();
$pdf->AliasNbPages($html);
$pdf->AddPage($html);
$pdf->SetFont('Times','',12);
$pdf->Output();
?>
Here it's exporting it to PDF but here how I can let the $html to get export to PDF using FPDF
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
1) Have a look at the Manual and Tutorial sections of the FPDF website
There are a lot of simple examples to take a look at.
2) You can't send html code with the AddPage() function. It should be orientation ("P" or "L") and size (like "A4") (see their documentation here)
3) It is not possible to just insert html into FPDF. You have to cut it up into text, links, images, tables and build the PDF content up just as you build up the HTML. There are some script that do support html input, but even those make mistakes now and then. My advise: instead of creating/building/compiling HTML, generate FPDF elements.
This example clearly exports a (simple) $html variable to a PDF
http://fpdf.org/en/tutorial/tuto6.htm
It is not possible to directly write HTML to a PDF using FPDF - you would have to separate the data into strings, set formatting to them, etc - basically, you will not be dealing with HTML anymore.
However, if you are not limited to FPDF, I would suggest looking into wkhtmltopdf, which can take HTML as an input, and render it to PDF using Webkit rendering engine. It can even take a remote URL and convert it to a PDF on your server.
I am trying to create malayalam pdfs using FPDF.
Font using meera.ttf
It is working but is not working correctly.
Result is like this ഇഗലീഷ്
I want the result ഇംഗ്ലീഷ്
codes***
$pdf = new tFPDF();
$pdf->AddPage();
// Add a Unicode font (uses UTF-8)
$pdf->AddFont('meera','','meera.ttf',true);
$pdf->SetFont('meera','',14);
// Load a UTF-8 string from a file and print it
$txt = file_get_contents('HelloWorld.txt');
$pdf->Write(8,$txt);
// Select a standard font (uses windows-1252)
$pdf->SetFont('meera','',14);
$pdf->Ln(10);
$pdf->Write(5,'The file size of this PDF is only 12 KB.');
$pdf->Output();
?>
HelloWorld.txt
ഇംഗ്ലീഷ്
i got answer, use mpdf,
fpdf and tcpdf not support.
go to
https://mail.google.com/mail/u/0/?shva=1#sent/143096e2010c4a58
download ful version of mPDF v5.7 Full installation - Download (.ZIP file 12.8MB)
run example /example29_multilingual_autofont.php
eg. localhost/MPDF57/examples/example29_multilingual_autofont.php
I found the Solution.
Just Download mpdf 6.0 and use the following Query
<?php
include('mpdf.php');
$html = '
<html>
<head>
<style>
body {background-image:url(image.jpg); background-image-resize:6;}
footer {page-break-after: always;}
</style>
</head>
<body>
<p >ഇംഗ്ലീഷ്</p>
<p style="font-family:Courier New">Malayalam</p>
</body>
</html>';
$mpdf=new mPDF('ml');
$mpdf->WriteHTML($html);
$mpdf->Output();
?>