public function runProcessStep($dokument)
 {
     $file = $dokument->getLatestRevision()->getFile();
     $extension = array_pop(explode(".", $file->getExportFilename()));
     #$this->ziphandler->addFile($file->getAbsoluteFilename(), $file->getExportFilename());
     // Print Metainfo for PDFs
     if (strtolower($extension) == "pdf") {
         try {
             $fpdf = new FPDI();
             $pagecount = $fpdf->setSourceFile($file->getAbsoluteFilename());
             $fpdf->SetMargins(0, 0, 0);
             $fpdf->SetFont('Courier', '', 8);
             $fpdf->SetTextColor(0, 0, 0);
             $documentSize = null;
             for ($i = 0; $i < $pagecount; $i++) {
                 $string = $dokument->getLatestRevision()->getIdentifier() . " (Seite " . ($i + 1) . " von " . $pagecount . ", Revision " . $dokument->getLatestRevision()->getRevisionID() . ")";
                 $fpdf->AddPage();
                 $tpl = $fpdf->importPage($i + 1);
                 $size = $fpdf->getTemplateSize($tpl);
                 // First Page defines documentSize
                 if ($documentSize === null) {
                     $documentSize = $size;
                 }
                 // Center Template on Document
                 $fpdf->useTemplate($tpl, intval(($documentSize["w"] - $size["w"]) / 2), intval(($documentSize["h"] - $size["h"]) / 2), 0, 0, true);
                 $fpdf->Text(intval($documentSize["w"]) - 10 - $fpdf->GetStringWidth($string), 5, $string);
             }
             $this->ziphandler->addFromString($dokument->getLatestRevision()->getIdentifier() . "." . $extension, $fpdf->Output("", "S"));
         } catch (Exception $e) {
             $this->ziphandler->addFile($file->getAbsoluteFilename(), $dokument->getLatestRevision()->getIdentifier() . "." . $extension);
         }
     } else {
         $this->ziphandler->addFile($file->getAbsoluteFilename(), $dokument->getLatestRevision()->getIdentifier() . "." . $extension);
     }
 }
Example #2
0
 public function listAction()
 {
     $receipt = new \FPDI();
     // PDFの余白(上左右)を設定
     $receipt->SetMargins(0, 0, 0);
     // ヘッダーの出力を無効化
     $receipt->setPrintHeader(false);
     // フッターの出力を無効化
     $receipt->setPrintFooter(false);
     // フォントを登録
     $fontPathRegular = $this->getLibPath() . '/tcpdf/fonts/migmix-2p-regular.ttf';
     //         $regularFont = $receipt->addTTFfont($fontPathRegular, '', '', 32);
     $font = new TCPDF_FONTS();
     $regularFont = $font->addTTFfont($fontPathRegular);
     $fontPathBold = $this->getLibPath() . '/tcpdf/fonts/migmix-2p-bold.ttf';
     //         $boldFont = $receipt->addTTFfont($fontPathBold, '', '', 32);
     $font = new TCPDF_FONTS();
     $boldFont = $font->addTTFfont($fontPathBold);
     // ページを追加
     $receipt->AddPage();
     // テンプレートを読み込み
     //         $receipt->setSourceFile($this->getLibPath() . '/tcpdf/tpl/receipt.pdf');
     //         $receipt->setSourceFile($this->getLibPath() . '/tcpdf/tpl/template.pdf');
     //         $receipt->setSourceFile($this->getLibPath() . '/tcpdf/tpl/w01_1.pdf');
     $receipt->setSourceFile($this->getLibPath() . '/tcpdf/tpl/senijiten.pdf');
     // 読み込んだPDFの1ページ目のインデックスを取得
     $tplIdx = $receipt->importPage(1);
     // 読み込んだPDFの1ページ目をテンプレートとして使用
     $receipt->useTemplate($tplIdx, null, null, null, null, true);
     // 書き込む文字列のフォントを指定
     $receipt->SetFont($regularFont, '', 11);
     // 書き込む文字列の文字色を指定
     $receipt->SetTextColor(0, 0, 255);
     // X : 42mm / Y : 108mm の位置に
     $receipt->SetXY(59, 248);
     // 文字列を書き込む
     $receipt->Write(0, isset($_POST['name']) ? $_POST['name'] . 'さん' : '名無しさん');
     /*         $response = new Response(
                 // Output関数の第一引数にはファイル名、第二引数には出力タイプを指定する
                 // 今回は文字列で返してほしいので、ファイル名はnull、出力タイプは S = String を選択する
                 $receipt->Output(null, 'S'),
                 200,
                 array('content-type' => 'application/pdf')
             );
     
             // レスポンスヘッダーにContent-Dispositionをセットし、ファイル名をreceipt.pdfに指定
             $response->headers->set('Content-Disposition', 'attachment; filename="receipt.pdf"');
     
             return $response;
      */
     //         $receipt->
     $receipt->output('newpdf.pdf', 'I');
 }
Example #3
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++;
     }
 }
Example #4
0
     //if
 }
 //foreach
 // unique id for this fax
 $fax_instance_uuid = uuid();
 //generate cover page, merge with pdf
 if ($fax_subject != '' || $fax_message != '') {
     //load pdf libraries
     require_once "resources/tcpdf/tcpdf.php";
     require_once "resources/fpdi/fpdi.php";
     // initialize pdf
     $pdf = new FPDI('P', 'in');
     $pdf->SetAutoPageBreak(false);
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetMargins(0, 0, 0, true);
     if (strlen($fax_cover_font) > 0) {
         if (substr($fax_cover_font, -4) == '.ttf') {
             $pdf_font = TCPDF_FONTS::addTTFfont($fax_cover_font);
         } else {
             $pdf_font = $fax_cover_font;
         }
     }
     if (!$pdf_font) {
         $pdf_font = 'times';
     }
     //add blank page
     $pdf->AddPage('P', array($page_width, $page_height));
     // content offset, if necessary
     $x = 0;
     $y = 0;
Example #5
0
         $page_height = 8.5;
         //in
         break;
     case 'letter':
     default:
         $page_width = 11;
         //in
         $page_height = 8.5;
         //in
 }
 // initialize pdf
 $pdf = new FPDI('L', 'in');
 $pdf->SetAutoPageBreak(false);
 $pdf->setPrintHeader(false);
 $pdf->setPrintFooter(false);
 $pdf->SetMargins(0.5, 0.5, 0.5, true);
 //set default font
 $pdf->SetFont('helvetica', '', 7);
 //add new page
 $pdf->AddPage('L', array($page_width, $page_height));
 $chunk = 0;
 //write the table column headers
 $data_start = '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
 $data_end = '</table>';
 $data_head = '<tr>';
 $data_head .= '<td width="7.5%"><b>' . $text['label-direction'] . '</b></td>';
 $data_head .= '<td width="15%"><b>' . $text['label-cid-name'] . '</b></td>';
 $data_head .= '<td width="8.5%"><b>' . $text['label-cid-number'] . '</b></td>';
 $data_head .= '<td width="11%"><b>' . $text['label-destination'] . '</b></td>';
 $data_head .= '<td width="11%"><b>' . $text['label-start'] . '</b></td>';
 $data_head .= '<td width="4%" align="right"><b>' . $text['label-tta'] . '</b></td>';
Example #6
0
 public function save_design()
 {
     if ($this->input->post('mode') == 'edit') {
         $this->db->delete('designs', array('id' => $this->input->post('design_id')));
     }
     $faceMacket = str_replace('http://klever.media/', '', $this->input->post('faceMacket'));
     $backMacket = str_replace('http://klever.media/', '', $this->input->post('backMacket'));
     $face = $this->input->post('face');
     $back = $this->input->post('back');
     // get all fonts
     $query = $this->db->get('fonts');
     $fonts = array();
     foreach ($query->result() as $font) {
         $fonts[$font->family] = $font->source;
     }
     // generate pdf face template name and preview name
     $face_pdf = 'uploads/redactor/face_' . md5(microtime(true)) . '.pdf';
     $face_preview = 'uploads/redactor/face_' . md5(microtime(true)) . '.jpg';
     // convert face image to pdf
     $img = new Imagick($faceMacket);
     $img->setresolution(300, 300);
     $img->setcolorspace(Imagick::COLORSPACE_CMYK);
     $img->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1);
     $img->setimageformat('pdf');
     $img->writeimage($face_pdf);
     // include TCPDF ana FPDI
     include_once APPPATH . 'libraries/tcpdf/tcpdf.php';
     include_once APPPATH . 'libraries/tcpdf/fpdi.php';
     include_once APPPATH . 'libraries/tcpdf/include/tcpdf_fonts.php';
     $fontMaker = new TCPDF_FONTS();
     // создаём лист
     $pdf = new FPDI('L', 'mm', array(91, 61), true, 'UTF-8', false);
     $pdf->SetMargins(0, 0, 0, true);
     $pdf->AddPage('L');
     // загрузим ранее сохранённый шаблон
     $pdf->setSourceFile($face_pdf);
     $pdf->SetMargins(0, 0, 0, true);
     $tplIdx = $pdf->importPage(1);
     $pdf->useTemplate($tplIdx, null, null, 0, 0, true);
     // установим опции для pdf
     $pdf->setCellHeightRatio(1);
     $pdf->setCellPaddings(0, 0, 0, 0);
     $pdf->setCellMargins(0, 0, 0, 0);
     $pdf->SetAutoPageBreak(false, 0);
     $pdf->SetPrintHeader(false);
     $pdf->SetPrintFooter(false);
     if (!empty($face)) {
         // отрисуем сначала изображения лица
         foreach ($face as $item) {
             if ($item['type'] == 'image') {
                 $pdf->Image($_SERVER['DOCUMENT_ROOT'] . '/' . str_replace('http://klever.media/', '', $item['content']), $this->px_to_mm($item['left']), $this->px_to_mm($item['top']), $this->px_to_mm($item['width']), '', '', '', '', false, 300);
             }
         }
         // потом текст на лице
         foreach ($face as $item) {
             if ($item['type'] == 'text') {
                 $cmyk = $this->rgbToCmyk($item['color']);
                 $pdf->SetTextColor($cmyk['c'] * 100, $cmyk['m'] * 100, $cmyk['y'] * 100, $cmyk['k'] * 100);
                 // set font
                 $tcpdfFont = $fontMaker->addTTFfont(realpath('fonts/redactor/' . $fonts[$item['font']]));
                 $pdf->SetFont($tcpdfFont, '', $item['size'] / 2, '', 'false');
                 $pdf->Text($this->px_to_mm($item['left']), $this->px_to_mm($item['top']), $item['content'], false, false, true, 0, 0, 'L', false, '', 0, false, 'T', 'L', false);
             }
         }
     }
     // сохраним пдф лица
     $pdf->Output($_SERVER['DOCUMENT_ROOT'] . '/' . $face_pdf, 'F');
     // сделаем превью для пользователя
     $im = new Imagick();
     $im->setResolution(300, 300);
     $im->readimage($face_pdf . '[0]');
     $im->flattenimages();
     $im->setImageFormat('jpg');
     $im->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1);
     $im->writeImage($face_preview);
     $im->clear();
     $im->destroy();
     //exec('$ convert ' . $_SERVER['DOCUMENT_ROOT'] . '/' . $face_pdf . ' ' . $_SERVER['DOCUMENT_ROOT'] . '/' . $face_preview);
     // есть ли оборот
     if (!empty($backMacket)) {
         // generate pdf back template name and preview name
         $back_pdf = 'uploads/redactor/back_' . md5(microtime(true)) . '.pdf';
         $back_preview = 'uploads/redactor/back_' . md5(microtime(true)) . '.jpg';
         // convert back image to pdf
         $img = new Imagick($backMacket);
         $img->setresolution(300, 300);
         $img->setcolorspace(Imagick::COLORSPACE_CMYK);
         $img->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1);
         $img->setimageformat('pdf');
         $img->writeimage($back_pdf);
         // создаём лист
         $pdf = new FPDI('L', 'mm', array(91, 61), true, 'UTF-8', false);
         $pdf->AddPage('L');
         // загрузим ранее сохранённый шаблон
         $pdf->setSourceFile($_SERVER['DOCUMENT_ROOT'] . '/' . $back_pdf);
         $pdf->SetMargins(0, 0, 0, true);
         $tplIdx = $pdf->importPage(1);
         $pdf->useTemplate($tplIdx, null, null, 0, 0, true);
         // установим опции для pdf
         $pdf->SetMargins(0, 0, 0, true);
         $pdf->setCellHeightRatio(1);
         $pdf->setCellPaddings(0, 0, 0, 0);
         $pdf->setCellMargins(1, 1, 1, 1);
         $pdf->SetAutoPageBreak(false);
         $pdf->SetPrintHeader(false);
         $pdf->SetPrintFooter(false);
         if (!empty($back)) {
             // отрисуем сначала изображения оборота
             foreach ($back as $item) {
                 if ($item['type'] == 'image') {
                     $pdf->Image($_SERVER['DOCUMENT_ROOT'] . '/' . str_replace('http://klever.media/', '', $item['content']), $this->px_to_mm($item['left']), $this->px_to_mm($item['top']), $this->px_to_mm($item['width']), '', '', '', '', false, 300);
                 }
             }
             // потом текст на обороте
             foreach ($back as $item) {
                 if ($item['type'] == 'text') {
                     $cmyk = $this->rgbToCmyk($item['color']);
                     $pdf->SetTextColor($cmyk['c'] * 100, $cmyk['m'] * 100, $cmyk['y'] * 100, $cmyk['k'] * 100);
                     // set font
                     $tcpdfFont = $fontMaker->addTTFfont($_SERVER['DOCUMENT_ROOT'] . '/fonts/redactor/' . $fonts[$item['font']]);
                     $pdf->SetFont($tcpdfFont, '', $item['size'] / 2, '', 'false');
                     $pdf->Text($this->px_to_mm($item['left']), $this->px_to_mm($item['top']), $item['content'], false, false, true, 0, 0, 'L', false, '', 0, false, 'T', 'L', false);
                 }
             }
         }
         // сохраним пдф оборота
         $pdf->Output($_SERVER['DOCUMENT_ROOT'] . '/' . $back_pdf, 'F');
         // сделаем превью для пользователя
         $im = new Imagick();
         $im->setResolution(300, 300);
         $im->readimage($back_pdf . '[0]');
         $im->setImageFormat('jpg');
         $im->flattenimages();
         $im->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1);
         $im->writeImage($back_preview);
         $im->clear();
         $im->destroy();
     }
     $this->db->insert('products', array('name' => 'cards_pvc', 'tiraj' => 100, 'weight' => 0.5, 'price' => 0.49, 'cost' => 49, 'macket' => 'my_macket'));
     $product_id = $this->db->insert_id();
     $this->db->insert('designs', array('product_id' => $product_id, 'theme_id' => $this->input->post('theme'), 'face_background' => $faceMacket, 'back_background' => empty($backMacket) ? NULL : $backMacket, 'face' => $face_preview, 'back' => empty($back_preview) ? '' : $back_preview, 'type' => 'system'));
     $design_id = $this->db->insert_id();
     $options = array();
     if (!empty($face)) {
         foreach ($face as $item) {
             if ($item['type'] == 'text') {
                 $options[] = array('design_id' => $design_id, 'type' => 'text', 'front' => 'face', 'top' => $item['top'], 'left' => $item['left'], 'width' => NULL, 'height' => NULL, 'content' => $item['content'], 'font' => $item['font'], 'color' => $item['color'], 'size' => $item['size']);
             } else {
                 $options[] = array('design_id' => $design_id, 'type' => 'image', 'front' => 'face', 'top' => $item['top'], 'left' => $item['left'], 'width' => $item['width'], 'height' => $item['height'], 'content' => $item['content'], 'font' => NULL, 'color' => NULL, 'size' => NULL);
             }
         }
     }
     if (!empty($back)) {
         foreach ($back as $item) {
             if ($item['type'] == 'text') {
                 $options[] = array('design_id' => $design_id, 'type' => 'text', 'front' => 'back', 'top' => $item['top'], 'left' => $item['left'], 'width' => NULL, 'height' => NULL, 'content' => $item['content'], 'font' => $item['font'], 'color' => $item['color'], 'size' => $item['size']);
             } else {
                 $options[] = array('design_id' => $design_id, 'type' => 'image', 'front' => 'back', 'top' => $item['top'], 'left' => $item['left'], 'width' => $item['width'], 'height' => $item['height'], 'content' => $item['content'], 'font' => NULL, 'color' => NULL, 'size' => NULL);
             }
         }
     }
     if (count($options) > 0) {
         $this->db->insert_batch('design_options', $options);
     }
     echo 'OK';
 }
Example #7
0
 function SetMargins()
 {
     parent::SetMargins($this->leftmargin, $this->topmargin, $this->rightmargin);
 }
Example #8
0
/**
 * Crea un archivo PDF a partir de un quiz, agregando una hoja de respuestas de opción múltiple
 * 
 * @param unknown $cm
 * @param string $debug
 * @param string $context
 * @param string $course
 * @param string $logofilepath
 * @param boolean $answersheetsonly
 * @return void|NULL
 */
function emarking_create_quiz_pdf($cm, $debug = false, $context = null, $course = null, $answersheetsonly = false, $pbar = false)
{
    global $DB, $CFG, $OUTPUT;
    // Inclusión de librerías
    require_once $CFG->dirroot . '/mod/assign/feedback/editpdf/fpdi/fpdi2tcpdf_bridge.php';
    require_once $CFG->dirroot . '/mod/assign/feedback/editpdf/fpdi/fpdi.php';
    require_once $CFG->libdir . '/pdflib.php';
    require_once $CFG->dirroot . '/mod/quiz/locallib.php';
    require_once $CFG->dirroot . '/mod/emarking/print/locallib.php';
    $filedir = $CFG->dataroot . "/temp/emarking/{$context->id}";
    emarking_initialize_directory($filedir, true);
    $fileimg = $CFG->dataroot . "/temp/emarking/{$context->id}/qr";
    emarking_initialize_directory($fileimg, true);
    $userimgdir = $CFG->dataroot . "/temp/emarking/{$context->id}/u";
    emarking_initialize_directory($userimgdir, true);
    $logofile = emarking_get_logo_file();
    $logofilepath = $logofile ? emarking_get_path_from_hash($filedir, $logofile->get_pathnamehash()) : null;
    $fullhtml = array();
    $numanswers = array();
    $attemptids = array();
    $images = array();
    $imageshtml = array();
    $users = emarking_get_enroled_students($course->id);
    if ($pbar) {
        echo $OUTPUT->heading(get_string('loadingquestions', 'mod_emarking'), 3);
        $progressbar = new progress_bar();
        $progressbar->create();
        $progressbar->update(0, count($users), get_string('processing', 'mod_emarking'));
    }
    $current = 0;
    foreach ($users as $user) {
        $current++;
        if ($pbar) {
            $progressbar->update($current, count($users), "{$user->firstname}, {$user->lastname}");
        }
        // Get the quiz object
        $quizobj = quiz::create($cm->instance, $user->id);
        // Create the new attempt and initialize the question sessions
        $attemptnumber = 1;
        $lastattempt = null;
        $timenow = time();
        // Update time now, in case the server is running really slowly.
        $attempts = quiz_get_user_attempts($quizobj->get_quizid(), $user->id, 'all');
        $numattempts = count($attempts);
        foreach ($attempts as $attempt) {
            $attemptobj = quiz_attempt::create($attempt->id);
            $slots = $attemptobj->get_slots();
            foreach ($slots as $slot) {
                $qattempt = $attemptobj->get_question_attempt($slot);
                $question = $qattempt->get_question();
                if ($question->get_type_name() === 'multianswer') {
                    $q = $question->subquestions[1];
                    $numanswers[$user->id][] = count($q->answers);
                } else {
                    if ($question->get_type_name() === 'multichoice') {
                        $numanswers[$user->id][] = count($question->answers);
                    }
                }
                $attemptids[$user->id] = $attempt->id;
                $qhtml = $attemptobj->render_question($slot, false);
                $qhtml = emarking_clean_question_html($qhtml);
                $currentimages = emarking_extract_images_url($qhtml);
                $idx = 0;
                foreach ($currentimages[1] as $imageurl) {
                    if (!array_search($imageurl, $images)) {
                        $images[] = $imageurl;
                        $imageshtml[] = $currentimages[0][$idx];
                    }
                    $idx++;
                }
                $fullhtml[$user->id][] = $qhtml;
            }
            // One attempt per user
            break;
        }
    }
    $save_to = $CFG->tempdir . '/emarking/printquiz/' . $cm->id . '/';
    emarking_initialize_directory($save_to, true);
    // Bajar las imágenes del HTML a dibujar
    $search = array();
    $replace = array();
    $replaceweb = array();
    $imagesize = array();
    $idx = 0;
    if ($pbar) {
        $progressbar->update_full(100, get_string('finished', 'mod_emarking'));
        echo $OUTPUT->heading(get_string('downloadingimages', 'mod_emarking'), 3);
        $progressbar = new progress_bar();
        $progressbar->create();
        $progressbar->update(0, count($images), get_string('processing', 'mod_emarking'));
    }
    foreach ($images as $image) {
        if ($pbar) {
            $imagefilename = explode("/", $image);
            $progressbar->update($idx + 1, count($images), $imagefilename[count($imagefilename) - 1]);
        }
        // Si solamente incluiremos hojas de respuesta terminamos el ciclo
        if ($answersheetsonly) {
            break;
        }
        if (!(list($filename, $imageinfo) = emarking_get_file_from_url($image, $save_to))) {
            echo "Problem downloading file {$image} <hr>";
        } else {
            // Buscamos el src de la imagen
            $search[] = 'src="' . $image . '"';
            $replacehtml = ' src="' . $filename . '"';
            $replacehtmlxweb = ' src="' . $image . '"';
            // Si el html de la misma contiene ancho o alto, se deja tal cual
            $imghtml = $imageshtml[$idx];
            if (substr_count($imghtml, "width") + substr_count($imghtml, "height") == 0) {
                $width = $imageinfo[0];
                $height = $imageinfo[1];
                $ratio = floatval(10) / floatval($height);
                $height = 10;
                $width = (int) ($ratio * floatval($width));
                $sizehtml = 'width="' . $width . '" height="' . $height . '"';
                $replacehtml = $sizehtml . ' ' . $replacehtml;
                $replacehtmlxweb = $sizehtml . ' ' . $replacehtmlxweb;
            }
            $replace[] = $replacehtml;
            $replaceweb[] = $replacehtmlxweb;
            $imagesize[] = $imageinfo;
        }
        $idx++;
    }
    if ($debug) {
        foreach ($fullhtml as $uid => $questions) {
            $index = 0;
            foreach ($questions as $question) {
                echo str_replace($search, $replaceweb, $fullhtml[$uid][$index]);
                $index++;
            }
        }
        return;
    }
    // Now we create the pdf file with the modified html
    $doc = new FPDI();
    $doc->setPrintHeader(false);
    $doc->setPrintFooter(false);
    $doc->SetFont('times', '', 12);
    // set margins
    $doc->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $doc->SetHeaderMargin(250);
    $doc->SetFooterMargin(PDF_MARGIN_FOOTER);
    if ($pbar) {
        $progressbar->update_full(100, get_string('finished', 'mod_emarking'));
        echo $OUTPUT->heading(get_string('creatingpdffile', 'mod_emarking'), 3);
        $progressbar = new progress_bar();
        $progressbar->create();
    }
    $current = 0;
    foreach ($fullhtml as $uid => $questions) {
        $current++;
        $stinfo = $DB->get_record('user', array('id' => $uid));
        $stinfo->name = $stinfo->firstname . ' ' . $stinfo->lastname;
        $stinfo->picture = emarking_get_student_picture($stinfo, $userimgdir);
        $stinfo->idnumber = $uid . '-' . $attemptids[$uid];
        if ($pbar) {
            $progressbar->update($current, count($fullhtml), $stinfo->name);
        }
        $groups = groups_get_user_groups($course->id, $uid);
        if ($groups && isset($groups[0][0]) && ($group = $DB->get_record('groups', array('id' => $groups[0][0])))) {
            $stinfo->group = $group->name;
        } else {
            $stinfo->group = '';
        }
        emarking_add_answer_sheet($doc, $filedir, $stinfo, $logofilepath, null, $fileimg, $course, $quizobj->get_quiz_name(), $numanswers[$uid], $attemptids[$uid]);
        // Una vez agregada la página de respuestas, si es todo lo que hay que hacer saltar al siguiente
        if ($answersheetsonly) {
            continue;
        }
        $doc->AddPage();
        emarking_draw_header($doc, $stinfo, $quizobj->get_quiz_name(), 2, $fileimg, $logofilepath, $course, null, false, 0);
        $doc->SetFont('times', '', 12);
        $doc->SetAutoPageBreak(true);
        $doc->SetXY(PDF_MARGIN_LEFT, 40);
        $index = 0;
        foreach ($questions as $question) {
            $prevy = $doc->getY();
            $fullhtml[$uid][$index] = str_replace($search, $replace, $fullhtml[$uid][$index]);
            $doc->writeHTML($fullhtml[$uid][$index]);
            $y = $doc->getY();
            $fmargin = $doc->getFooterMargin();
            $height = $doc->getPageHeight();
            $spaceleft = $height - $fmargin - $y;
            $questionsize = $y - $prevy;
            if ($spaceleft < 70) {
                $doc->AddPage();
            }
            $index++;
        }
    }
    if ($pbar) {
        $progressbar->update_full(100, get_string('finished', 'mod_emarking'));
    }
    $qid = $quizobj->get_quizid();
    $pdfquizfilename = 'quiz-' . $qid . '-' . random_string() . '.pdf';
    $fs = get_file_storage();
    $filerecord = array('component' => 'mod_emarking', 'filearea' => 'pdfquiz', 'contextid' => $context->id, 'itemid' => $quizobj->get_quizid(), 'filepath' => '/', 'filename' => $pdfquizfilename);
    $doc->Output($filedir . '/' . $pdfquizfilename, 'F');
    $file = $fs->create_file_from_pathname($filerecord, $filedir . '/' . $pdfquizfilename);
    $downloadurl = moodle_url::make_file_url("{$CFG->wwwroot}/pluginfile.php", "/{$context->id}/mod_emarking/pdfquiz/{$qid}/{$pdfquizfilename}", null, true);
    return $downloadurl;
}
Example #9
0
$calc_result = unserialize($contract_data['calc_result']);
require_once 'fpdf17/fpdf.php';
require_once 'fpdi/fpdi.php';
//Вносим необходимые данные в полис и отдаём в формате pdf
$pdf = new FPDI();
$pdf->AddFont('ArialMT', '', 'arial_cyr.php');
$pdf->AddFont('Arial-BoldMT', '', 'arialbold.php');
$pdf->AddPage();
// $pdf->setSourceFile('blank/bso3.pdf');
// // Указываем номер импортируемой страницы
// $tplIdx = $pdf->importPage(1);
// //указываем размер страницы
// //$pdf->useTemplate($tplIdx, 0, 0, 210, 297, true);
// $pdf->useTemplate($tplIdx, 0, 0, 210, 297, true);
//Ставим поля по нулям
$pdf->SetMargins(0, 0, 0, 0);
$pdf->SetAutoPageBreak(false);
//указываем шрифт и размер
$pdf->SetFont('Arial-BoldMT', '', '13');
//указываем цвет текста
$pdf->SetTextColor(0, 0, 0);
////////////////////////////////////////////////////////Добавляем данные в полис//////////////////////////////
//Время начала действия договора
$pdf->SetXY(120.8, 42.5);
$pdf->Write(0, $contract_data['start_time'][0]);
$pdf->SetXY(125.8, 42.5);
$pdf->Write(0, $contract_data['start_time'][1]);
$pdf->SetXY(137.3, 42.5);
$pdf->Write(0, $contract_data['start_time'][3]);
$pdf->SetXY(142.3, 42.5);
$pdf->Write(0, $contract_data['start_time'][4]);
Example #10
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');
 }
function FlyerRendering($inputFile, $outputPostfix, $anschnitt)
{
    /*------------------------------------------------------------------------------------
     * Bitte tragt hier eure lokalen Freifunk Daten ein.
     *------------------------------------------------------------------------------------
     *
     * Hinweiss Community-Logo: 
     * Moegliche Format sind GIF, JPG und PNG.
     *
     * Laenge des Community Namen:
     * Falls der Community-Name zu lang ist und es zu einem Zeilenumbruch kommt,
     * dann sollte $communityNameFontSize verkleiner werden
     *
    -------------------------------------------------------------------------------------*/
    // Community Name fuer Hauptseite
    $communityNameText = "Freifunk Duckburg";
    $communityNameFontSize = 48.0;
    //in pt
    $communityNamePositionOffsetX = 0.0;
    // +/- in mm
    $communityNamePositionOffsetY = 0.0;
    // +/- in mm
    // Logo auf Kontaktseite
    $kontaktLogoDateiName = "logo-template.png";
    $kontaktLogoWidth = 66.25;
    //in mm  // Muss kleiner 98.0 mm sein! Hier bitte die gewuenschte Breite des Logos auf dem Flyer eintragen.
    $kontaktLogoPositionY = 47.0;
    //in mm  // Die Hoeheneinstellung ist etwas frickelig. Es klappt aber :-)
    // Texte fuer Seite mit Kontaktdaten
    $kontaktTitelText = "Kontakt";
    $kontaktInfoTexte = [["Webseite", "http://ffdb.freifunk.net"], ["Mail", "*****@*****.**"], ["Mailingliste", "*****@*****.**"], ["Twitter", "@FreiFunkDB"], ["Treffen", "Jeden zweiten Montag"], ["", "Und wo? Siehe unsere Webseite"], ["", ""], ["", ""]];
    // Text Fusszeile
    $kontaktFusszeileText = "Freifunk Duckburg e.V.";
    /*-----------------------------------------------------------------------------------
     *
     * Ab hier sollte nichts mehr geander werden!
     *
     ------------------------------------------------------------------------------------*/
    // Breite der einzelnen Seiten
    $wRechts = 99.0;
    //mm
    $wMitte = 98.0;
    //mm
    $wLinks = 97.0;
    //mm
    // Community Name
    $communityNamePositionX = $wLinks + $wMitte + $communityNamePositionOffsetX;
    //mm
    $communityNamePositionY = 12.2 + $communityNamePositionOffsetY;
    //mm
    // Kontakt Titel
    $kontaktTitelPositionX = $wLinks + 3.975;
    //mm
    $kontaktTitelPositionY = 10.425;
    //mm
    $kontaktTitelFontSize = 15.0;
    //pt
    // Kontakt Info
    $kontaktInfoTextPositionX = $kontaktTitelPositionX + 25.0;
    //mm
    $kontaktInfoPositionY = $kontaktTitelPositionY + 7.0;
    //mm
    $kontaktInfoZeilenOffsetY = 4.7;
    //mm
    $kontaktInfoFontSize = 10.9;
    //pt
    // Kontakt Logo
    $kontaktLogoPositionX = $wLinks + $wMitte / 2 - $kontaktLogoWidth / 2;
    // Kontakt Footer
    $kontaktFooterPositionX = $wLinks;
    //mm
    $kontaktFooterPositionY = 95.40000000000001;
    //mm
    $kontaktFooterWidth = $wMitte;
    //mm
    $kontaktFooterFontSize = 10.9;
    //pt
    echo "\n";
    // Output-Dasteiname zusammenbauen
    $outputFile = $outputPostfix . "-" . $inputFile;
    // initiate FPDI
    $pdf = new FPDI();
    echo "Input: {$inputFile}\n";
    $pageCount = $pdf->setSourceFile($inputFile);
    // Importiere Vorder- und Rueckseite
    $Vorderseite = $pdf->ImportPage(1);
    $Rueckseite = $pdf->ImportPage(2);
    // Seitenabmessungen holen
    $size = $pdf->getTemplateSize($Vorderseite);
    $dokumentBreite = round($size['w'], 2);
    $dokumentHoehe = round($size['h'], 2);
    echo "Dokumenten Breite: {$dokumentBreite} mm\n";
    echo "Dokumenten Hoehe: {$dokumentHoehe} mm\n";
    echo "Anschnitt: {$anschnitt} mm\n";
    // Vorderseite uebernehmen
    // Anfang eines bloeden Hacks wegen des FooterZeilen-Textes.
    // Der Footertext laesst sich nur einfügen, wenn die Seite eine A4 Seite ist.
    // Keine Ahnung warum!
    $pdf->AddPage('L');
    $tplVorderseite = $pdf->importPage(1);
    $pdf->useTemplate($tplVorderseite);
    //Margin ist wegen der Rand-Platzierung des Community Names wichtig.
    $pdf->SetMargins(0, 0, 0);
    // erstmal alle Fonts laden
    echo "Lade Fonts...\n";
    $pdf->AddFont('lato-bold');
    $pdf->AddFont('lato-regular');
    $pdf->AddFont('alternategothic');
    // Rendern Titel Text
    echo "Verarbeite Titel Text...\n";
    $pdf->SetFont('lato-bold');
    $pdf->SetFontSize($kontaktTitelFontSize);
    $pdf->SetTextColor(0, 0, 0);
    //schwarz
    $pdf->SetXY($kontaktTitelPositionX + $anschnitt, $kontaktTitelPositionY + $anschnitt);
    $pdf->Write(0, iconv('UTF-8', 'windows-1252', $kontaktTitelText));
    // Rendern Info Text
    echo "Verarbeite Info Text...\n";
    $pdf->SetTextColor(0, 0, 0);
    //schwarz
    $pdf->SetFontSize($kontaktInfoFontSize);
    foreach ($kontaktInfoTexte as $a) {
        $pdf->SetFont('lato-bold');
        $pdf->SetXY($kontaktTitelPositionX + $anschnitt, $kontaktInfoPositionY + $anschnitt);
        $pdf->Write(0, iconv('UTF-8', 'windows-1252', $a[0]));
        $pdf->SetFont('lato-regular');
        $pdf->SetXY($kontaktInfoTextPositionX + $anschnitt, $kontaktInfoPositionY + $anschnitt);
        $pdf->Write(0, iconv('UTF-8', 'windows-1252', $a[1]));
        $kontaktInfoPositionY = $kontaktInfoPositionY + $kontaktInfoZeilenOffsetY;
    }
    // Rendern Community Logo
    echo "Verarbeite Logo...\n";
    $pdf->Image($kontaktLogoDateiName, $kontaktLogoPositionX + $anschnitt, $kontaktLogoPositionY + $anschnitt, $kontaktLogoWidth, 0);
    // Rendern Fusszeilen Text
    echo "Verarbeite Fusszeile...\n";
    $pdf->SetFont('lato-regular');
    $pdf->SetFontSize($kontaktFooterFontSize);
    $pdf->SetTextColor(255, 255, 255);
    //weiss
    $pdf->SetXY($kontaktFooterPositionX + $anschnitt, $kontaktFooterPositionY + $anschnitt);
    $pdf->Cell($kontaktFooterWidth, 0, iconv('UTF-8', 'windows-1252', $kontaktFusszeileText), 0, 0, 'C');
    // Rendern Community Name
    echo "Verarbeite Community Name...\n";
    $pdf->SetFont('alternategothic');
    $pdf->SetFontSize($communityNameFontSize);
    $pdf->SetTextColor(0, 0, 0);
    //schwarz
    $pdf->SetXY($communityNamePositionX + $anschnitt, $communityNamePositionY + $anschnitt);
    $pdf->MultiCell($wRechts, 10, iconv('UTF-8', 'windows-1252', $communityNameText), 0, 'C');
    // Das war's mit dem Editieren
    // Original PDF Rueckseit uebernehmen
    $pdf->AddPage('L', array($dokumentBreite, $dokumentHoehe));
    $tplRueckseite = $pdf->importPage(2);
    $pdf->useTemplate($tplRueckseite);
    // und erstmal abspeichern
    echo "Zwischenspeichern...\n";
    $pdf->Output($outputFile);
    // Hier geht jetzt der Hack wegen der Footerzeile weiter
    // Die gerade abgespeicherte Datei wird erneut eingelesen
    // um dann im Seiten-Format der Ursprungsdatei erneut abgespeichert zu werden.
    // Is' doof, muss aber sein
    $pdf_2 = new FPDI();
    echo "Erneut laden...\n";
    $pageCount = $pdf_2->setSourceFile($outputFile);
    echo "Feinschliff...\n";
    $Vorderseite_2 = $pdf_2->ImportPage(1);
    $Rueckseite_2 = $pdf_2->ImportPage(2);
    $pdf_2->AddPage('L', array($dokumentBreite, $dokumentHoehe));
    $tplForderseite = $pdf_2->importPage(1);
    $pdf_2->useTemplate($tplForderseite);
    $pdf_2->AddPage('L', array($dokumentBreite, $dokumentHoehe));
    $tplRueckseite = $pdf_2->importPage(2);
    $pdf_2->useTemplate($tplRueckseite);
    echo "Output: {$outputFile}\n";
    $pdf_2->Output($outputFile);
    unset($pdf);
    unset($pdf_2);
}
Example #12
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("");
 }
Example #13
0
 function generatePDF($id_invoice, $introduction_letter = false, $target = 'file', $docs = false)
 {
     if (!is_numeric($id_invoice)) {
         error_log('$id_invoice not defined');
         exit(1);
     }
     if (!defined('EURO')) {
         define('EURO', chr(128));
     }
     $facture = Facture::getInfos($id_invoice);
     foreach (array(LC_MESSAGES, LC_TIME, LC_MONETARY, LC_CTYPE) as $locale) {
         setlocale($locale, $facture->language . ".UTF-8") or die("locale {$locale} language failed {$facture->language}");
     }
     bindtextdomain('webfinance', dirname(__FILE__) . '/../../lang') or die("Set gettext bindtextdomain language failed\n");
     textdomain('webfinance') or die("Set gettext textdomain language failed\n");
     $type_doc = $facture->type_doc;
     if ($facture->language == 'en_US' and $facture->type_doc == 'facture') {
         $type_doc = 'invoice';
     }
     if ($facture->language == 'en_US' and $facture->type_doc == 'devis') {
         $type_doc = 'quote';
     }
     // Generate PDF filename
     $filename = sys_get_temp_dir() . '/' . ucfirst($type_doc) . ' ' . preg_replace('/[^a-z0-9éàçùî\\._-]/i', ' ', $facture->num_facture . ' ' . $facture->nom_client) . '.pdf';
     foreach ($facture as $n => $v) {
         if (!is_array($v)) {
             $facture->{$n} = preg_replace("/€/", "EUROSYMBOL", $facture->{$n});
             // FPDF ne support pas l'UTF-8
             $facture->{$n} = utf8_decode($facture->{$n});
             $facture->{$n} = preg_replace("/EUROSYMBOL/", chr(128), $facture->{$n});
             $facture->{$n} = preg_replace("/\\\\EUR\\{([0-9.,]+)\\}/", "\\1 " . chr(128), $facture->{$n});
         }
     }
     $pdf = new FPDI('P', 'mm', 'A4');
     // Address
     $address = "{$facture->nom_client}\n";
     for ($i = 0; $i < 3; $i++) {
         $n = sprintf("addr%d", $i + 1);
         if ($facture->{$n} != "") {
             $address .= $facture->{$n} . "\n";
         }
     }
     $address .= "{$facture->cp} {$facture->ville}\n{$facture->pays}";
     //Get docs, if needed
     if ($docs !== false) {
         $pagecount = $pdf->SetSourceFile(dirname(__FILE__) . '/../admin/invoice_docs/docs_' . $facture->language . '.pdf');
         for ($n = 1; $n <= $pagecount; $n++) {
             $tplidx = $pdf->ImportPage($n, '/MediaBox');
             $pdf->AddPage();
             $pdf->UseTemplate($tplidx);
         }
     }
     $pdf->SetMargins(10, 10, 10);
     $pdf->SetDisplayMode('fullwidth');
     $pdf->AddPage();
     $prefs = new WebfinancePreferences();
     // UTF8 to ISO
     $prefs->prefs['societe']->invoice_top_line1 = preg_replace("/€/", "EUROSYMBOL", $prefs->prefs['societe']->invoice_top_line1);
     // FPDF ne support pas l'UTF-8
     $prefs->prefs['societe']->invoice_top_line1 = utf8_decode($prefs->prefs['societe']->invoice_top_line1);
     $prefs->prefs['societe']->invoice_top_line1 = preg_replace("/EUROSYMBOL/", chr(128), $prefs->prefs['societe']->invoice_top_line1);
     // Save the logo to a temp file since fpdf cannot read from a var
     $tempfile_logo = tempnam(sys_get_temp_dir(), 'logo') . '.png';
     $logo_tmp = fopen($tempfile_logo, "w");
     fwrite($logo_tmp, $prefs->prefs['logo']);
     fclose($logo_tmp);
     // Logo
     $pdf->Image($tempfile_logo, 90, 5, 25, 0, 'PNG');
     // Display text headers
     $pdf->SetFont('Arial', '', 5);
     $logo_size = getimagesize($tempfile_logo);
     $logo_height = $logo_size[1] * 25 / $logo_size[0];
     $pdf->SetXY(10, $logo_height + 5);
     $pdf->Cell(190, 5, $prefs->prefs['societe']->invoice_top_line1, 0, 0, "C");
     $pdf->SetLineWidth(0.3);
     $pdf->SetXY(10, $logo_height + 8);
     $pdf->Cell(190, 5, utf8_decode($prefs->prefs['societe']->invoice_top_line2), "B", 0, "C");
     // Address
     $pdf->SetFont('Arial', 'B', 11);
     $pdf->SetXY(115, 50);
     $pdf->Cell(80, 5, $facture->nom_client, 0, 0);
     $pdf->SetFont('Arial', '', 11);
     $y = 54;
     for ($i = 0; $i < 3; $i++) {
         $n = sprintf("addr%d", $i + 1);
         if ($facture->{$n} != "") {
             $pdf->SetXY(115, $y);
             $pdf->Cell(80, 5, $facture->{$n}, 0, 0);
             $y += 5;
         }
     }
     $pdf->SetXY(115, $y);
     $pdf->Cell(80, 4, $facture->cp . " " . $facture->ville, 0, 0);
     $pdf->SetXY(115, $y + 5);
     $pdf->Cell(80, 4, $facture->pays, 0, 0);
     // Donnees factures
     $pdf->SetXY(10, 19 + $logo_height);
     $pdf->SetFont('Arial', 'B', 14);
     $pdf->Cell(60, 4, ucfirst($type_doc) . utf8_decode(_(' #')) . $facture->num_facture);
     $pdf->SetFont('Arial', '', 9);
     $pdf->SetXY(10, 27 + $logo_height);
     $pdf->Cell(60, 4, $societe->ville . " " . utf8_decode(_("on")) . " " . strftime("%d/%m/%Y", $facture->timestamp_date_facture));
     $pdf->SetXY(10, 32 + $logo_height);
     if (!empty($societe->tva_intracommunautaire)) {
         $pdf->Cell(60, 4, utf8_decode(_("VAT code")) . " " . $societe->raison_sociale . " : {$societe->tva_intracommunautaire}\n");
     }
     if (!empty($facture->vat_number)) {
         $pdf->Write(5, utf8_decode(_("Your VAT code")) . " : {$facture->vat_number}\n");
     }
     $pdf->Write(5, $facture->ref_contrat . "\n");
     $pdf->Write(5, wordwrap($facture->extra_top, 70));
     // Lignes de facturation
     $pdf->SetLineWidth(0.1);
     $pdf->SetXY(10, 80);
     $pdf->SetFont('Arial', 'B', '10');
     $pdf->Cell(110, 6, utf8_decode(_("Designation")), 1);
     $pdf->Cell(20, 6, utf8_decode(_("Quantity")), 1, 0, "C");
     $pdf->Cell(30, 6, utf8_decode(_("VAT excl.")), 1, 0, "C");
     $pdf->Cell(30, 6, utf8_decode(_("Total")), 1, 0, "C");
     $pdf->Ln();
     $total_ht = 0;
     foreach ($facture->lignes as $ligne) {
         foreach ($ligne as $n => $v) {
             $ligne->{$n} = preg_replace("/€/", "EUROSYMBOL", $ligne->{$n});
             $ligne->{$n} = utf8_decode($ligne->{$n});
             $ligne->{$n} = preg_replace("/EUROSYMBOL/", chr(128), $ligne->{$n});
         }
         setlocale(LC_TIME, "fr_FR.UTF8");
         // Replace dates like YYYY-MM-DD with nice expanded date
         $ligne->description = preg_replace_callback('/\\d{4}-\\d{2}-\\d{2}/', create_function('$matches', 'return utf8_decode(strftime("%e %B %Y", strtotime($matches[0])));'), $ligne->description);
         $y_start = $pdf->getY();
         $pdf->SetFont('Arial', '', '10');
         $pdf->MultiCell(110, 6, $ligne->description, "LR", 'L');
         $x = $pdf->getX();
         $y = $pdf->getY();
         $pdf->setXY(120, $y_start);
         $pdf->Cell(20, 6, $ligne->qtt, "LR", 0, "C");
         $pdf->Cell(30, 6, preg_replace("/\\./", ",", sprintf("%.2f" . EURO, $ligne->prix_ht)), "LR", 0, "R");
         $pdf->Cell(30, 6, preg_replace("/\\./", ",", sprintf("%.2f" . EURO, $ligne->prix_ht * $ligne->qtt)), "LR", 0, "R");
         $pdf->setXY(120, $y_start);
         $pdf->Cell(20, $y - $y_start, '', "LR", 0, "C");
         $pdf->Cell(30, $y - $y_start, '', "LR", 0, "R");
         $pdf->Cell(30, $y - $y_start, '', "LR", 0, "R");
         $total_ht += $ligne->prix_ht * $ligne->qtt;
         $pdf->Ln();
         $pdf->Cell(110, 2, "", "LR");
         $pdf->Cell(20, 2, "", "LR");
         $pdf->Cell(30, 2, "", "LR");
         $pdf->Cell(30, 2, "", "LR");
         $pdf->Ln();
     }
     $y_fin = $pdf->getY();
     if ($y < 190) {
         $pdf->Cell(110, 190 - $y, "", "LRB", 0, "C");
         $pdf->Cell(20, 190 - $y, "", "LRB", 0, "C");
         $pdf->Cell(30, 190 - $y, "", "LRB", 0, "C");
         $pdf->Cell(30, 190 - $y, "", "LRB", 0, "C");
         $pdf->Ln();
     }
     // Total HT
     $txt_type_paiement = $facture->type_paiement;
     if (preg_match('/eption de cette facture/', $txt_type_paiement) and $facture->language != 'fr_FR') {
         $txt_type_paiement = _('upon receipt of invoice');
     }
     $pdf->SetFont('Arial', '', '11');
     $pdf->Cell(130, 6, utf8_decode(_("Payment")) . " : " . $txt_type_paiement);
     $pdf->Cell(30, 6, utf8_decode(_("Subtotal")), "", 0, "R");
     $pdf->Cell(30, 6, preg_replace("/\\./", ",", sprintf("%.2f" . EURO, $total_ht)), "", 0, "R");
     $pdf->Ln();
     // TVA
     $pdf->Cell(130, 6, "");
     $pdf->Cell(30, 6, utf8_decode(_("VAT")) . " " . str_replace('.', ',', $facture->taxe) . "%", "", 0, "R");
     $pdf->Cell(30, 6, preg_replace("/\\./", ",", sprintf("%.2f" . EURO, $facture->taxe / 100 * $total_ht)), "", 0, "R");
     $pdf->Ln();
     // Solde à régler
     $pdf->SetFont('Arial', 'B', '11');
     $pdf->Cell(130, 6, "");
     $pdf->Cell(30, 6, utf8_decode(_('Total')), "", 0, "R");
     $pdf->Cell(30, 6, preg_replace("/\\./", ",", sprintf("%.2f" . EURO, (1 + $facture->taxe / 100) * $total_ht - $facture->accompte)), "", 0, "R");
     $pdf->Ln();
     $pdf->Ln();
     $pdf->SetFont('Arial', '', '8');
     $pdf->MultiCell(190, 4, utf8_decode(_('Discount not practiced by the company. In case of default in the invoice due date, the client agrees to pay a penalty pursuant to the provisions of Article 1226 of the Civil Code, an increase of 15% in addition to the main total without any notice of default being required.')));
     // Extra data
     $pdf->SetFont('Arial', '', '10');
     if (!empty($facture->extra_bottom)) {
         $pdf->Ln(10);
         $pdf->MultiCell(120, 6, $facture->extra_bottom, 0);
     }
     // RIB
     $result = mysql_query('SELECT value ' . 'FROM webfinance_pref ' . 'WHERE id_pref=' . $facture->id_compte) or die(mysql_error());
     list($cpt) = mysql_fetch_array($result);
     mysql_free_result($result);
     $cpt = unserialize(base64_decode($cpt));
     if (!is_object($cpt)) {
         echo "compte Impossible de generer la facture. <a " . "href='../admin/societe'>Vous devez saisir au moins un compte " . "bancaire dans les options pour emettre des factures</a>";
         exit(1);
     }
     foreach ($cpt as $n => $v) {
         $cpt->{$n} = utf8_decode($cpt->{$n});
     }
     $pdf->SetFont('Arial', 'B', '10');
     $pdf->Ln();
     $pdf->Cell(160, 6, utf8_decode(_("Bank references")) . " ", "LTR", 0, "C");
     $pdf->Ln();
     $pdf->SetFont('Arial', '', '8');
     $pdf->Cell(35, 6, utf8_decode(_("Bank")) . " : ", "L");
     $pdf->Cell(125, 6, $cpt->banque, "R");
     $pdf->Ln();
     $pdf->Cell(35, 6, "IBAN : ", "L");
     $pdf->Cell(125, 6, $cpt->iban, "R");
     $pdf->Ln();
     $pdf->Cell(35, 6, "SWIFT/BIC : ", "LB");
     $pdf->Cell(125, 6, $cpt->swift, "BR");
     $pdf->Ln();
     $pdf->SetAuthor($societe->raison_sociale);
     $pdf->SetCreator('Webfinance $Id: gen_facture.php 532 2012-11-10 10:32:19Z pierre $ Using FPDF');
     $pdf->SetSubject(ucfirst($facture->type_doc) . utf8_decode(_(' #')) . " " . $facture->num_facture . " " . utf8_decode(_("for")) . " " . $facture->nom_client);
     $pdf->SetTitle(ucfirst($facture->type_doc) . utf8_decode(_(' #')) . " " . $facture->num_facture);
     if ($target == 'file') {
         $pdf->Output($filename, 'F');
     } else {
         $pdf->Output(basename($filename), 'I');
     }
     $pdf->Close();
     // Delete temporary logo file
     unlink($tempfile_logo);
     global $language;
     foreach (array(LC_MESSAGES, LC_TIME, LC_MONETARY, LC_CTYPE) as $locale) {
         setlocale($locale, $language . ".UTF-8") or die("locale {$locale} language failed {$language}");
     }
     bindtextdomain('webfinance', dirname(__FILE__) . '/../../lang') or die("Set gettext bindtextdomain language failed\n");
     textdomain('webfinance') or die("Set gettext textdomain language failed\n");
     return $filename;
 }
Example #14
0
 public function test()
 {
     //        $rgb_arr = sscanf('rgb(243, 243, 243)', "rgb(%d, %d, %d)");
     //        print_r($this->rgbToCmyk($rgb_arr[0], $rgb_arr[1], $rgb_arr[2]));
     //        exit();
     //
     $img = new Imagick('test.jpg');
     $img->resizeimage(1076, 720, Imagick::FILTER_LANCZOS, 1);
     $img->setresolution(300, 300);
     $img->setimageformat('pdf');
     $img->writeimage('test.pdf');
     include_once APPPATH . 'libraries/tcpdf/tcpdf.php';
     include_once APPPATH . 'libraries/tcpdf/fpdi.php';
     // создаём лист
     $pdf = new FPDI('L', 'mm', array(91, 61), true, 'UTF-8', false);
     $pdf->AddPage('L');
     // загрузим ранее сохранённый шаблон
     $pdf->setSourceFile('test.pdf');
     $pdf->SetMargins(0, 0, 0, true);
     $tplIdx = $pdf->importPage(1);
     $pdf->useTemplate($tplIdx, null, null, 0, 0, true);
     // установим опции для pdf
     $pdf->SetMargins(0, 0, 0, true);
     $pdf->setCellHeightRatio(1);
     $pdf->setCellPaddings(0, 0, 0, 0);
     $pdf->setCellMargins(1, 1, 1, 1);
     $pdf->SetAutoPageBreak(false);
     $pdf->SetPrintHeader(false);
     $pdf->SetPrintFooter(false);
     $pdf->Image('qwe.png', 30, 30, 20, '', '', '', '', false, 300);
     $pdf->SetTextColor(0, 0, 0, 100);
     $pdf->SetFont('helvetica', 'BI', 10, '', 'false');
     $pdf->Text(12, 9, 'Black CMYK');
     $pdf->Output($_SERVER['DOCUMENT_ROOT'] . '/uploads/fynal.pdf', 'F');
     $im = new Imagick();
     $im->setResolution(300, 300);
     $im->readimage('uploads/fynal.pdf[0]');
     $im->setImageFormat('jpeg');
     $im->resizeimage(538, 360, Imagick::FILTER_LANCZOS, 1);
     $im->writeImage('uploads/fynal.jpg');
     $im->clear();
     $im->destroy();
     //        include_once APPPATH . 'libraries/drawer.php';
     //
     //        $drawer = new Drawer();
     //        $drawer->init();
     //        $drawer->setLayout();
     //        $drawer->setBackground('test.jpg');
     //        $drawer->drawImage('test.jpg', 10, 10, 30);
     //        $drawer->drawText('Maxim', 10, 10, 'TimesNewRoman', 20, 'rgb(77, 77, 77)');
     //        $drawer->savePdf($_SERVER['DOCUMENT_ROOT'] . '/1.pdf');
     //        $drawer->makePreview($_SERVER['DOCUMENT_ROOT'] . '/1.pdf', $_SERVER['DOCUMENT_ROOT'] . '/1.jpg');
 }
function FlyerRendering($config, $inputFile, $outputPath, $outputPostfix, $anschnitt = 0.0)
{
    // Breite der einzelnen Seiten
    $wRechts = 99.0;
    //mm
    $wMitte = 98.0;
    //mm
    $wLinks = 97.0;
    //mm
    // Community Name
    $communityNamePositionX = $wLinks + $wMitte + $config['communityNamePositionOffsetX'];
    //mm
    $communityNamePositionY = 12.2 + $config['communityNamePositionOffsetY'];
    //mm
    // Kontakt Titel
    $kontaktTitelPositionX = $wLinks + 3.975;
    //mm
    $kontaktTitelPositionY = 10.425;
    //mm
    $kontaktTitelFontSize = 15.0;
    //pt
    // Kontakt Info
    $kontaktInfoTextPositionX = $kontaktTitelPositionX + 25.0;
    //mm
    $kontaktInfoPositionY = $kontaktTitelPositionY + 7.0;
    //mm
    $kontaktInfoZeilenOffsetY = 4.7;
    //mm
    $kontaktInfoFontSize = 10.9;
    //pt
    // Kontakt Logo
    $kontaktLogoPositionX = $wLinks + $wMitte / 2 - $config['kontaktLogoWidth'] / 2;
    // Kontakt Footer
    $kontaktFooterPositionX = $wLinks;
    //mm
    $kontaktFooterPositionY = 95.40000000000001;
    //mm
    $kontaktFooterWidth = $wMitte;
    //mm
    $kontaktFooterFontSize = 10.9;
    //pt
    // Output-Dasteiname zusammenbauen
    $outputFile = $outputPath . DIRECTORY_SEPARATOR . $outputPostfix . '_' . basename($inputFile);
    // initiate FPDI
    $pdf = new FPDI();
    echo 'Input: ' . basename($inputFile) . PHP_EOL;
    $pageCount = $pdf->setSourceFile($inputFile);
    // Importiere Vorder- und Rueckseite
    $Vorderseite = $pdf->ImportPage(1);
    $Rueckseite = $pdf->ImportPage(2);
    // Seitenabmessungen holen
    $size = $pdf->getTemplateSize($Vorderseite);
    $dokumentBreite = round($size['w'], 2);
    $dokumentHoehe = round($size['h'], 2);
    echo 'Dokumenten Breite: ' . $dokumentBreite . 'mm' . PHP_EOL;
    echo 'Dokumenten Hoehe: ' . $dokumentHoehe . 'mm' . PHP_EOL;
    echo 'Anschnitt: ' . $anschnitt . 'mm' . PHP_EOL;
    // Vorderseite uebernehmen
    // Anfang eines bloeden Hacks wegen des FooterZeilen-Textes.
    // Der Footertext laesst sich nur einfügen, wenn die Seite eine A4 Seite ist.
    // Keine Ahnung warum!
    $pdf->AddPage('L');
    $tplVorderseite = $pdf->importPage(1);
    $pdf->useTemplate($tplVorderseite);
    //Margin ist wegen der Rand-Platzierung des Community Names wichtig.
    $pdf->SetMargins(0, 0, 0);
    // erstmal alle Fonts laden
    echo 'Lade Fonts...' . PHP_EOL;
    $pdf->AddFont('lato-bold');
    $pdf->AddFont('lato-regular');
    $pdf->AddFont('alternategothic');
    // Rendern Titel Text
    echo 'Verarbeite Titel Text...' . PHP_EOL;
    $pdf->SetFont('lato-bold');
    $pdf->SetFontSize($kontaktTitelFontSize);
    $pdf->SetTextColor(0, 0, 0);
    //schwarz
    $pdf->SetXY($kontaktTitelPositionX + $anschnitt, $kontaktTitelPositionY + $anschnitt);
    $pdf->Write(0, iconv('UTF-8', 'windows-1252', $config['kontaktTitelText']));
    // Rendern Info Text
    echo 'Verarbeite Info Text...' . PHP_EOL;
    $pdf->SetTextColor(0, 0, 0);
    //schwarz
    $pdf->SetFontSize($kontaktInfoFontSize);
    foreach ($config['kontaktInfoTexte'] as $a) {
        $pdf->SetFont('lato-bold');
        $pdf->SetXY($kontaktTitelPositionX + $anschnitt, $kontaktInfoPositionY + $anschnitt);
        $pdf->Write(0, iconv('UTF-8', 'windows-1252', $a[0]));
        $pdf->SetFont('lato-regular');
        $pdf->SetXY($kontaktInfoTextPositionX + $anschnitt, $kontaktInfoPositionY + $anschnitt);
        $pdf->Write(0, iconv('UTF-8', 'windows-1252', $a[1]));
        $kontaktInfoPositionY = $kontaktInfoPositionY + $kontaktInfoZeilenOffsetY;
    }
    // Rendern Community Logo
    echo 'Verarbeite Logo...' . PHP_EOL;
    $pdf->Image($config['kontaktLogoDateiName'], $kontaktLogoPositionX + $anschnitt, $config['kontaktLogoPositionY'] + $anschnitt, $config['kontaktLogoWidth'], 0);
    // Rendern Fusszeilen Text
    echo 'Verarbeite Fusszeile...' . PHP_EOL;
    $pdf->SetFont('lato-regular');
    $pdf->SetFontSize($kontaktFooterFontSize);
    $pdf->SetTextColor(255, 255, 255);
    //weiss
    $pdf->SetXY($kontaktFooterPositionX + $anschnitt, $kontaktFooterPositionY + $anschnitt);
    $pdf->Cell($kontaktFooterWidth, 0, iconv('UTF-8', 'windows-1252', $config['kontaktFusszeileText']), 0, 0, 'C');
    // Rendern Community Name
    echo 'Verarbeite Community Name...' . PHP_EOL;
    $pdf->SetFont('alternategothic');
    $pdf->SetFontSize($config['communityNameFontSize']);
    $pdf->SetTextColor(0, 0, 0);
    //schwarz
    $pdf->SetXY($communityNamePositionX + $anschnitt, $communityNamePositionY + $anschnitt);
    $pdf->MultiCell($wRechts, 10, iconv('UTF-8', 'windows-1252', $config['communityNameText']), 0, 'C');
    // Das war's mit dem Editieren
    // Original PDF Rueckseit uebernehmen
    $pdf->AddPage('L', array($dokumentBreite, $dokumentHoehe));
    $tplRueckseite = $pdf->importPage(2);
    $pdf->useTemplate($tplRueckseite);
    // und erstmal abspeichern
    echo 'Zwischenspeichern...' . PHP_EOL;
    $pdf->Output($outputFile);
    // Hier geht jetzt der Hack wegen der Footerzeile weiter
    // Die gerade abgespeicherte Datei wird erneut eingelesen
    // um dann im Seiten-Format der Ursprungsdatei erneut abgespeichert zu werden.
    // Is' doof, muss aber sein
    $pdf_2 = new FPDI();
    echo 'Erneut laden...' . PHP_EOL;
    $pageCount = $pdf_2->setSourceFile($outputFile);
    echo 'Feinschliff...' . PHP_EOL;
    $Vorderseite_2 = $pdf_2->ImportPage(1);
    $Rueckseite_2 = $pdf_2->ImportPage(2);
    $pdf_2->AddPage('L', array($dokumentBreite, $dokumentHoehe));
    $tplVorderseite = $pdf_2->importPage(1);
    $pdf_2->useTemplate($tplVorderseite);
    $pdf_2->AddPage('L', array($dokumentBreite, $dokumentHoehe));
    $tplRueckseite = $pdf_2->importPage(2);
    $pdf_2->useTemplate($tplRueckseite);
    echo 'Output: ' . basename($outputFile) . PHP_EOL;
    $pdf_2->Output($outputFile);
    unset($pdf);
    unset($pdf_2);
}