symfony - Fix the number of pages of pdf report generated by snappy -
i using snappy generate pdf report,
pdf contain text , charts , should 4 pages every page contain data related specific theme.
so have done creating 4 div width: 100%and height: 100% instead of 4 pages have 9 pages
where problem ? tried use 'page-size' =>'a4' same 9 pages generated
public function pdfaction(survey $survey) { $chart=new chartcontroller(); $event = $survey->getevent(); $year = $survey->getyear(); $qb = $this->getdoctrine()->getmanager()->createquerybuilder(); $qb->select('e') ->from('appbundle:survey', 'e') ->where('e.year <= :year') ->andwhere('e.event = :event') ->setparameter('year', $year) ->setparameter('event', $event->getid()) ->orderby('e.year', 'desc') ->setmaxresults(4); $survey_year= = $qb->getquery()->getresult(); $date = array(); $data1 = array(); $data2 = array(); $data3 = array(); $data4 = array(); $survey_year= array_reverse($survey_year, true); foreach($survey_year $ea){ $date[] = $ea->getannee(); $data1[] = $ea->getform()->getbudget (); $data2[] = $ea->getform()->getressources(); $data3[] = $ea->getform()->gettauxglobal(); $data4[] = $ea->getform()->gettauxconsumption(); } $list1= array( 'name' => 'budget', 'type' => 'column', 'color' => '#4572a7', 'yaxis' => 1, 'datalabels' => array( 'enabled' => true ), 'data' => $data1 ); $list2 = array( 'name' => 'ressource', 'type' => 'column', 'color' => '#d49eda', 'yaxis' => 1, 'datalabels' => array( 'enabled' => true ), 'data' => $data2 ); $list3= array( 'name' => 'taux global', 'type' => 'spline', 'color' => '#0a0f19', 'datalabels' => array( 'enabled' => true ), 'data' => $data3 ); $list4 = array( 'name'=> 'taux consumption', 'type' => 'spline', 'color' => '#225824', 'datalabels' => array( 'enabled' => true ), 'data' => $data4 ); $containerpie1 = $chart->piechart1($survey); $containerpie2 = $chart->piechart2($survey); $containerpie3=$chart->piechart3($survey); $container4=$chart->multiaxechart($date, $list1, $list2,$list3,$list4); $html = $this->render('appbundle:event:pdf.html.twig',array( 'survey' =>$survey, 'containerpie1'=>$containerpie1, 'containerpie2'=>$containerpie2, 'containerpie3'=>$containerpie3, 'container4' => $container4, )); return new response( $this->get('knp_snappy.pdf')->getoutputfromhtml($html,array( 'default-header'=>false, 'encoding' => 'utf-8', 'images' => true, 'enable-javascript' => true, 'javascript-delay' => 5000 )), 200, array( 'content-type' => 'application/pdf', 'content-disposition' => 'attachment; filename="file1.pdf"' ) ); }
pdf.twig.html
<div style="width: 100%; height: 100% "> <header> <span>{{ survey.event.name </span> </header> <h2 style="width:100% ;background-color:darkseagreen">genaral</h2> <p> <span class="address" style="font-weight: bold">address:</span> <span >survey.event. address}}</span> </p> <p> <span class="email" style="font-weight: bold">email:</span> <span class=survey.event.email}}</span> </p> </div> <div style="width: 100%;height: 100% "> <h2 style="width:100%;background-color:darkseagreen"> resources </h2> <p></p> <p>budget p> <div style="display: inline;padding-top: 5em"> <div id="containerpie1" style="display:inline-block; width: 350px; height: 300px; margin: 0 auto; padding-left: 18em"> </div> </div> <div style="display: inline;padding-top: 5em"> <div id="containerpie2" style="display:inline-block; width: 350px; height: 300px; margin: 0 auto; padding-left: 18em"> </div> </div> </div> <div style="width: 100%;height: 100% "> <h2 style="width:100%;background-color:darkseagreen">activity</h2> <p></p> <div > <div id="container3" style="display:inline-block;width: 350px; height: 280px; margin: 0 auto"></div> </div> </div> <div style="width:100%;height:100% "> <h2 style="width:100%;background-color:darkseagreen">team</h2> <p></p> <p>performance</p> <div > <div id=" container4" style="display:inline-block; width: 800px; height: 400px; margin: 0 auto"> </div> </div> </div>
update
after more searching have found should fix height in mm
<div style="width: 100%; height: 340mm ">
is solution?
try adding onepage
class divs , add css :
.onepage { page-break-inside: avoid !important; page-break-after: !important; } @media print{ .onepage { page-break-inside: avoid !important; page-break-after: !important; } }
it works snappy , wkhtmltopdf v0.12.2
Comments
Post a Comment