Ejemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $id = $input->getArgument('id');
     $pdffile = $input->getArgument('pdf');
     $em = $this->getContainer()->get('doctrine');
     $tab = $this->csv($pdffile);
     $template = $em->getRepository('PrintBundle:Template')->find($id);
     $path = $this->getContainer()->get('kernel')->getRootDir() . '/../web/uploads/pdf/' . $template->getPdffile();
     $width = $template->getWidth();
     $height = $template->getHeight();
     $orientation = $height > $width ? 'P' : 'L';
     $custom_layout = array($width, $height);
     $i = 1;
     foreach ($tab as $key => $value) {
         $pdf = new \FPDI($orientation, 'mm', $custom_layout, true, 'UTF-8', false);
         $pdf->setPageOrientation($orientation);
         $pdf->SetMargins(PDF_MARGIN_LEFT, 40, PDF_MARGIN_RIGHT);
         $pdf->SetAutoPageBreak(true, 40);
         $pdf->setFontSubsetting(false);
         // add a page
         $pdf->AddPage($orientation);
         $pdf->setSourceFile($path);
         $_tplIdx = $pdf->importPage(1);
         $size = $pdf->useTemplate($_tplIdx, 0, 0, $width, true);
         foreach ($template->getChildactivity() as $opt) {
             $pdf->SetXY($opt->getX(), $opt->getY());
             $pdf->SetFont($opt->getFont(), '', $opt->getFontsize() * 2);
             // echo $opt->getFontsize()."\n";
             $pdf->Cell($opt->getWidth(), $opt->getHeight(), $value[$opt->getName()]);
         }
         //$pdf->Cell(0, $size['h'], 'TCPDF and FPDI');
         // echo $template->getId();
         $pdf->Output($this->getContainer()->get('kernel')->getRootDir() . '/../web/folder/pdf' . $template->getId() . "-{$i}.pdf", 'F');
         $i++;
     }
 }
Ejemplo n.º 2
0
 public function generatepdfAction($id)
 {
     $width = 320;
     $height = 450;
     $pdfmerge = $this->getDoctrine()->getRepository('PrintBundle:Pdfmerge')->find($id);
     $elementwidth = $pdfmerge->getWidth();
     $elementheight = $pdfmerge->getHeight();
     $marge = $pdfmerge->getMarge();
     $singlewidth = $elementwidth + $marge;
     $singleheight = $elementheight + $marge;
     // test occupation
     $test1 = (int) ($height / $singleheight) * (int) ($width / $singlewidth);
     $test2 = (int) ($width / $singleheight) * (int) ($height / $singlewidth);
     if ($test1 >= $test2) {
         $width = 320;
         $height = 450;
         $orientation = "P";
     } else {
         $width = 450;
         $height = 320;
         $orientation = "L";
     }
     // calculate margin
     $nbrX = (int) ($width / $singlewidth);
     $nbrY = (int) ($height / $singleheight);
     $marginleft = ($width - $nbrX * $singlewidth) / 2;
     $margintop = ($height - $nbrY * $singleheight) / 2;
     //print_r(array($orientation, $marginleft, $margintop));
     $custom_layout = array($width, $height);
     $pdf = new \FPDI($orientation, 'mm', 'SRA3', true, 'UTF-8', false);
     $pdf->setPageOrientation($orientation);
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetMargins($marginleft, 40, $marginleft);
     $pdf->SetAutoPageBreak(true, 40);
     $pdf->setFontSubsetting(false);
     // add a page
     $pdf->AddPage($orientation);
     $i = 0;
     $path = $this->get('kernel')->getRootDir() . '/../web/';
     $toaddheight = $margintop;
     $face = array();
     $j = 0;
     foreach ($pdfmerge->getPdflist() as $list) {
         for ($k = 0; $k < $list->getRepeat(); $k++) {
             if ($i == $nbrX) {
                 $i = 0;
                 $j++;
                 $toaddheight += $singleheight;
             }
             $toaddwidth = $i * $singlewidth + $marginleft;
             $face[$toaddheight][$toaddwidth] = $list->getFile();
             $i++;
         }
     }
     $reverse = array();
     foreach ($face as $y => $value) {
         foreach ($value as $x => $fichier) {
             $file = $path . $fichier;
             $pdf->setSourceFile($file);
             $_tplIdx = $pdf->importPage(1);
             $size = $pdf->useTemplate($_tplIdx, $x, $y, 85);
             $reverse[$y][$x] = $fichier;
         }
     }
     //echo "<pre>";print_r($face);exit;
     $this->repert($pdf, $face, $marginleft, $margintop, $singlewidth, $singleheight, $height, $width);
     if ($pdfmerge->getNbpage() == 2) {
         $pdf->AddPage($orientation);
         foreach ($reverse as $y => $value) {
             foreach ($value as $x => $fichier) {
                 $file = $path . $fichier;
                 $pdf->setSourceFile($file);
                 $_tplIdx = $pdf->importPage(2);
                 $size = $pdf->useTemplate($_tplIdx, $x, $y, 85);
                 $reverse[$y][$x] = $fichier;
             }
         }
         $this->repert($pdf, $face, $marginleft, $margintop, $singlewidth, $singleheight, $height, $width);
     }
     $pdf->Output("aaa.pdf", 'I');
 }
Ejemplo n.º 3
0
 public function generatepdfAction(command $commande)
 {
     $request = $this->get('request');
     $tools = $this->get('tools.utils');
     $session = $request->getSession();
     if ($session->has('tpl')) {
         $tpl = $commande->getToprint();
         $pdffile = "";
         foreach ($tpl as $key => $elemnt) {
             foreach ($elemnt as $val) {
                 $prod = $this->getDoctrine()->getRepository('MainFrontBundle:paramtpl')->find($val['id']);
                 $template = $prod->getTpl();
                 $tplpdf = str_replace("../", "", $template->getPdf());
                 $pdffile = $this->get('kernel')->getRootDir() . '/../web/' . $tplpdf;
             }
         }
         $custom_layout = array(85, 55);
         $orientation = 'L';
         $pdf = new \FPDI($orientation, 'mm', $custom_layout, true, 'UTF-8', false);
         $pdf->setPageOrientation($orientation);
         $pdf->SetMargins(0, 0, 0);
         $pdf->SetAutoPageBreak(true, 0);
         $pdf->setFontSubsetting(false);
         $pdf->AddPage($orientation);
         //   echo "<pre>";print_r($pdf->getMargins());exit;
         $pdf->setSourceFile($pdffile);
         $_tplIdx = $pdf->importPage(1);
         $size = $pdf->useTemplate($_tplIdx, 0, 0, 85, 55, true);
         $idd = "";
         $i = 0;
         $oldx = 0;
         $oldy = 0;
         foreach ($elemnt as $value) {
             //if($i==0)
             if ($idd != $value['id'] && $value['value'] != "") {
                 $pdf->SetPageMark();
                 if (substr($value['value'], 0, 4) != "/tmp") {
                     //$tools->dump($value);
                     $align = strtoupper(substr($value['align'], 0, 1));
                     $color = $this->hex2rgb($value['color']);
                     $pdf->SetTextColor($color[0], $color[1], $color[2]);
                     $param = $this->getDoctrine()->getRepository('MainFrontBundle:paramtpl')->find($value['id']);
                     $y2 = $param->getX1() / 5;
                     $x1 = $param->getY1() / 5;
                     //$x1 = 10;$y2 = 8;
                     $w = $param->getX2() / 5;
                     $h = $param->getY2() / 5;
                     $oldx = $x1;
                     $oldy = $y2;
                     $pdf->SetX($x1, false);
                     $pdf->SetY($y2, false);
                     //$pdf->SetXY($x1, $y2,true);
                     $pdf->SetFont(null, '', $param->getSize() * 0.6);
                     //$param->getPolice()
                     // echo $opt->getFontsize()."\n";
                     $pdf->Cell($w, $h, $value["value"], 0, 0, $align);
                 } else {
                     $param = $this->getDoctrine()->getRepository('MainFrontBundle:paramtpl')->find($value['id']);
                     $img = $this->getParameter('base_url') . $value['value'];
                     $pdf->Image($img, $param->getX1() / 4.5, $param->getY1() / 4.55, $param->getX2() / 4.55, $param->getY2() / 4.5, '', '', '', true);
                 }
             }
             $idd = $value['id'];
             $i++;
         }
         //$pdf->Cell(0, $size['h'], 'TCPDF and FPDI');
         // echo $template->getId();
         $pdf->Output($this->get('kernel')->getRootDir() . '/../web/pdf.pdf');
     }
     return new Response("");
 }