Пример #1
0
 public static function merge($mpdfs, $filename, $outputmode = 'I')
 {
     $p = new \fpdi\FPDI();
     $n = 0;
     foreach ($mpdfs as $mpdf) {
         if ($mpdf instanceof MPdf) {
             $mpdf->write(TMP_PATH . '/temmpdf' . $n . '.pdf');
             $file = TMP_PATH . '/temmpdf' . $n . '.pdf';
         } else {
             $file = $mpdf;
         }
         $n++;
         $files[] = $file;
         $pagecount = $p->setSourceFile($file);
         for ($i = 1; $i <= $pagecount; $i++) {
             $tplidx = $p->ImportPage($i);
             $p->AddPage();
             $p->useTemplate($tplidx);
         }
     }
     foreach ($files as $v) {
         //  			@unlink($v);
     }
     $p->output($filename, $outputmode);
 }
Пример #2
0
 public function generate()
 {
     $container = $this->view->getViewHelperVariableContainer();
     if ($container->exists('Famelo\\Pdf\\ViewHelpers\\Fpdi\\DefaultsViewHelper', 'defaults')) {
         $defaults = $container->get('Famelo\\Pdf\\ViewHelpers\\Fpdi\\DefaultsViewHelper', 'defaults');
     }
     if ($container->exists('Famelo\\Pdf\\ViewHelpers\\Fpdi\\TemplateViewHelper', 'template')) {
         $template = $container->get('Famelo\\Pdf\\ViewHelpers\\Fpdi\\TemplateViewHelper', 'template');
     }
     if ($container->exists('Famelo\\Pdf\\ViewHelpers\\Fpdi\\TextViewHelper', 'texts')) {
         $texts = $container->get('Famelo\\Pdf\\ViewHelpers\\Fpdi\\TextViewHelper', 'texts');
     }
     $fpdi = new \fpdi\FPDI();
     $fpdi->AddPage();
     $fpdi->setSourceFile($template);
     $fpdi->useTemplate($fpdi->importPage(1), 0, 0, 0);
     foreach ($texts as $text) {
         foreach ($defaults as $key => $value) {
             if (isset($text[$key]) && !empty($text[$key])) {
                 continue;
             }
             $text[$key] = $value;
         }
         $text['font-weight'] = $text['font-weight'] == 'bold' ? 'B' : '';
         $fpdi->SetFont($text['font'], $text['font-weight'], $text['font-size']);
         #$fpdi->SetTextColor($page[$i][$x]['color_r'], $page[$i][$x]['color_b'], $page[$i][$x]['color_g']);
         $fpdi->SetXY($text['x'], $text['y']);
         $fpdi->Write(0, $text['content']);
     }
     return $fpdi;
 }
Пример #3
0
require 'vendor/itbz/fpdf/src/fpdf/FPDF.php';
require 'vendor/itbz/fpdi/src/fpdi/FPDI.php';
Connection::conecting();
$file_id = $_GET['file'];
$file_id = strip_tags(htmlspecialchars($file_id));
$file_id = filter_var($file_id, FILTER_SANITIZE_NUMBER_INT);
$file_id = filter_var($file_id, FILTER_VALIDATE_INT);
if (!$file_id) {
    echo 'no es un id valido';
} else {
    $archivo = Archivo::find($file_id);
    if (count($archivo) > 0) {
        $pdf = new \fpdi\FPDI();
        $pageCount = $pdf->setSourceFile('uploads/lecciones/' . $archivo->nombre);
        for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
            $templateId = $pdf->importPage($pageNo);
            $size = $pdf->getTemplateSize($templateId);
            if ($size['w'] > $size['h']) {
                $pdf->AddPage('L', array($size['w'], $size['h']));
            } else {
                $pdf->AddPage('P', array($size['w'], $size['h']));
            }
            $pdf->useTemplate($templateId);
            $pdf->SetFont('Helvetica');
            $pdf->SetXY(5, 5);
        }
        $pdf->Output('file.pdf', 'I');
    } else {
        echo 'no existe el archivo';
    }
}