how to include graphs into html2pdf? - php

I am using maxChart.class.php to create Graphs and its working properly.
I am also using html2pdf.class.php to create Online pdf report. I tried to include chart in pdf file but its not working.
My code is
$rowval=$sqcat1->qcategory;
$data3["$rowval"]=$per;
$content = "
<page>
$content.=$mc3 = new maxChart($data3);
$mc3->displayChart('',1,450,400,true);
"
</page>";
require_once("/pdf1/html2pdf.class.php");
$html2pdf = new HTML2PDF('P','A4','en');
$html2pdf->WriteHTML($content);
$html2pdf->Output('demo.pdf');
How can i add graphs in file ?
Anybody please help me.

I used MPDF and SVGGraphs to do this
Code to add graphs value in php variable
$html.='<br>'.$graph->Fetch("CylinderGraph",true).'<br>';
Code for MPDF
include("/mpdf.php");
$mpdf=new mPDF('c');
$mpdf->SetHTMLHeader($header);
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;

You can do the following:
make the chart an image and embed that image in the document, using <img src=...
display the chart image using binary data <img src="data:image/png;base64,binarycontentherebase64encoded...">

Related

Unable to export CSS when exporting large HTML to PDF using mPDF

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.

mpdf Skips CSS when i render the view into HTML?

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.

Print webpage as PDF in PHP

I am newbie to php.
I have developed small application in PHP. Now I have few label controls in one webpage inside form. that i want to save in pdf. Is there any tool like itextsharp (In ASp.net), where I can export one panel or form to pdf. (By rendering)
I checked fpdf and other. In that we can print text. My label data is coming from MYSQL.
Any suggestion.
I suggest mpdf. I'ts very simple, you can create your html as string and render it as pdf.
require_once("mpdf/mpdf.php");
$html = "<p>Hello World</p>";
$mpdf = new mPDF('c', 'A4');
$mpdf->WriteHTML($html);
print $mpdf->Output();

Adjust Image if page break occurs in mpdf library

I am generating pdf from html source using mpdf library in php and everything seems working perfect.
Now I have an issue with the images. Suppose before page end I'm inserting an image but image is big so that it doesn't fit at the bottom of first page and goes to second page. Now I have a long white space at the end of first page because image moved to second page.
Now I want is "if next item to insert in pdf is an image then calculate the remaining size of pdf page if it is less than Image size then adjust the image size so that image can be fit in the pdf page instead of moving to next page" how can i do this here?
Please check the issue image :
If any one has other solution please help me to sort out.
Here's My sample code
include_once 'simple_html_dom.php'; //import html dom and mpdf library
include 'PDFScript/MPDF/mpdf.php';
$mpdf = new mPDF('','','','',15,15,30,15,8,8); //create mpdf object
$html = new simple_html_dom(); //create html dom object
$html = file_get_html("htmlsource.html"); //htmlsource.html is a webpage can contain any html data
$mpdf->WriteHTML($html); //write html source to pdf
$mpdf->Output(); //generate pdf
I got a solution from mpdf forum itself. If Anyone also has the same problem enclose every image in your html inside table as table has a autosize feature in mpdf library.
For more information please check here

Include stylesheet file into MPDF conversion in PHP

I have made HTML to convert it into PDF using MPDF,
but issue is that I can't include a stylesheet file.
Example:
include("../mpdf.php");
$mpdf=new mPDF('c');
$mpdf->SetDisplayMode('fullpage');
// LOAD a stylesheet
$stylesheet = file_get_contents('mpdfstyleA4.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html);
$mpdf->Output();
I used the code above but I can't see the effect of the styles.
Does anyone know a better way to include styles?
You need to load the stylesheet in the html - it's not clear in your snippet where the content for $html comes from but that's the place to load styles. Using your code you'll be writing the CSS you've loaded as if it were document content for the PDF, which I assume isn't your intent.
mPdf works best with inline style sheets which cause no bugs while pdf opens in different browsers.
It looks to me you are setting the new PDF function into "Code" mode.
$mpdf=new mPDF('c');
Have you tried it without the "C"?
$mpdf=new mPDF();
Also, is your stylesheet, "mpdfstyleA4.css", located in the same path as mpdf.php?

Categories