Example #1
0
 public function executeBatchPrintBadge(sfWebRequest $request)
 {
     $ids = $request->getParameter('ids');
     // initiate FPDI
     $pdf = new FPDI('P', 'pt');
     // set the sourcefile
     $pdf->setSourceFile(sfConfig::get('sf_upload_dir') . '/badges/ID_new.pdf');
     foreach ($ids as $id) {
         $this->employee = EmployeePeer::retrieveByPk($id);
         // import page 1
         $tplIdx = $pdf->importPage(1);
         // add a new page based on size of the badge
         $s = $pdf->getTemplatesize($tplIdx);
         $pdf->AddPage('P', array($s['w'], $s['h']));
         $pdf->useTemplate($tplIdx);
         $pdf->setMargins(0, 0, 0, 0);
         $pdf->SetAutoPageBreak(false);
         if ($this->employee->getPicture()) {
             $pdf->Image(sfConfig::get('sf_upload_dir') . '/' . sfConfig::get('app_employee_images_dir') . '/' . $this->employee->getPicture(), 29.5, 25.5, 60.3, 74.3);
         } else {
             $pdf->Image(sfConfig::get('sf_upload_dir') . '/badges/picture_missing.jpg', 29.5, 25.5, 60.3, 74.3);
         }
         // now write some text above the imported page
         $pdf->SetFont('freesans', 'B', 12);
         $pdf->SetTextColor(82, 78, 134);
         $pdf->SetXY(22, 110);
         $pdf->Cell(0, 12, $this->employee->getFullName());
         $pdf->Ln();
         $pdf->SetX(22);
         $pdf->SetFont('freesans', 'BI', 10);
         $pdf->Cell(0, 14, $this->employee->getJob());
         $pdf->SetDisplayMode('real');
     }
     return $pdf->Output('newpdf.pdf', 'D');
 }
		//$pdf->AddPage();
		//$title=$langs->trans("BillsCustomersUnpaid");
		//if ($option=='late') $title=$langs->trans("BillsCustomersUnpaid");
		//$pdf->MultiCell(100, 3, $title, 0, 'J');

		// Add all others
		foreach($files as $file)
		{
            print "Merge PDF file for invoice ".$file."\n";

			// Charge un document PDF depuis un fichier.
			$pagecount = $pdf->setSourceFile($file);
			for ($i = 1; $i <= $pagecount; $i++)
            {
                 $tplidx = $pdf->importPage($i);
                 $s = $pdf->getTemplatesize($tplidx);
                 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
                 $pdf->useTemplate($tplidx);
            }
		}

		// Create output dir if not exists
		create_exdir($diroutputpdf);

		// Save merged file
		$filename='mergedpdf';

		if (! empty($option)) $filename.='_'.$option;

		if ($pagecount)
		{
Example #3
0
 /**
  * Simple helper function which actually merges a given array of document-paths
  * @param $paths
  * @return string The created document's url
  */
 private function mergeDocuments($paths)
 {
     include_once 'engine/Library/Fpdf/fpdf.php';
     include_once 'engine/Library/Fpdf/fpdi.php';
     $pdf = new FPDI();
     foreach ($paths as $path) {
         $numPages = $pdf->setSourceFile($path);
         for ($i = 1; $i <= $numPages; $i++) {
             $template = $pdf->ImportPage($i);
             $size = $pdf->getTemplatesize($template);
             $pdf->AddPage('P', array($size['w'], $size['h']));
             $pdf->useTemplate($template);
         }
     }
     $hash = md5(uniqid(rand()));
     $pdf->Output($hash . '.pdf', "D");
 }