Exemplo n.º 1
1
/**
 * Imports the OMR fonts
 *
 * @param string $echo
 *            if echoes the result
 */
function emarking_import_omr_fonts($echo = false)
{
    global $CFG;
    // The list of extensions a font in the tcpdf installation has
    $fontfilesextensions = array('.ctg.z', '.php', '.z');
    // The font files required for OMR
    $fonts = array('3of9_new' => '/mod/emarking/lib/omr/3OF9_NEW.TTF', 'omrbubbles' => '/mod/emarking/lib/omr/OMRBubbles.ttf', 'omrextnd' => '/mod/emarking/lib/omr/OMRextnd.ttf');
    // We delete previous fonts if any and then import it
    foreach ($fonts as $fontname => $fontfile) {
        // Deleteing the previous fonts
        foreach ($fontfilesextensions as $extension) {
            $fontfilename = $CFG->libdir . '/tcpdf/fonts/' . $fontname . $extension;
            if (file_exists($fontfilename)) {
                echo "Deleting {$fontfilename}<br/>";
                unlink($fontfilename);
            } else {
                echo "{$fontfilename} does not exist, it must be created<br/>";
            }
        }
        // Import the font
        $ttfontname = TCPDF_FONTS::addTTFfont($CFG->dirroot . $fontfile, 'TrueType', 'ansi', 32);
        // Validate if import went well
        if ($ttfontname !== $fontname) {
            echo "Fatal error importing font {$fontname}<br/>";
            return false;
        } else {
            echo "{$fontname} imported!<br/>";
        }
    }
    return true;
}
Exemplo n.º 2
0
 /**
  * process uploaded font file and convert to format for use with tcpdf
  *
  * @return void
  */
 protected function _afterSave()
 {
     if ($this->getValue()) {
         TCPDF_FONTS::addTTFfont(Mage::getBaseDir('media') . DS . 'pdf-printouts' . DS . $this->getValue());
         //Alternative if encoding of font can't be determined correctly
         //$pdf->addTTFfont(Mage::getBaseDir('media') . DS . 'pdf-printouts' . DS . $this->getValue(),'TrueType','ansi');
     }
 }
Exemplo n.º 3
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');
 }
Exemplo n.º 4
0
 public function run($fonts = null)
 {
     if (\Cli::option('help', \Cli::option('h', false)) or empty($fonts)) {
         empty($fonts) and \Cli::error(\Cli::color('No font given.', 'red'));
         return static::help();
     }
     $pdf = new \TCPDF();
     $type = \Cli::option('type', \Cli::option('t', ''));
     $enc = \Cli::option('enc', \Cli::option('e', ''));
     $flags = \Cli::option('flags', \Cli::option('f', 32));
     $outpath = \Cli::option('outpath', \Cli::option('o', K_PATH_FONTS));
     $platid = \Cli::option('platid', \Cli::option('p', 3));
     $encid = \Cli::option('encid', \Cli::option('n', 1));
     $addcbbox = \Cli::option('addcbbox', \Cli::option('b', false));
     $link = \Cli::option('link', \Cli::option('l', false));
     $path = \Cli::option('path', \Cli::option('p'));
     if (!is_null($path) and !\Str::ends_with($path, DS)) {
         $path .= DS;
     }
     $fonts = explode(',', $fonts);
     foreach ($fonts as $font) {
         if (strpos($font, DS) === false and !is_null($path)) {
             $font = $path . $font;
         }
         $fontfile = realpath($font);
         $fontname = \TCPDF_FONTS::addTTFfont($fontfile, $type, $enc, $flags, $outpath, $platid, $encid, $addcbbox, $link);
         if ($fontname == false) {
             $errors = true;
             \Cli::error(\Cli::color($font . ' cannot be added.', 'red'));
         } else {
             \Cli::write(\Cli::color($font . ' added.', 'green'));
         }
     }
     if (!empty($errors)) {
         \Cli::error(\Cli::color('Process finished with errors.', 'red'));
     } else {
         \Cli::write(\Cli::color('Process successfully finished.', 'green'));
     }
 }
Exemplo n.º 5
0
 function init()
 {
     parent::init();
     $target_dir = DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'html' . DIRECTORY_SEPARATOR . 'xepan2' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'xepan' . DIRECTORY_SEPARATOR . 'commerce' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR;
     $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
     $uploadOk = 1;
     $fontFileType = pathinfo($target_file, PATHINFO_EXTENSION);
     // Check if image file is a actual image or fake image
     if (isset($_POST["submit"])) {
         $font_format = explode('-', $target_file);
         if (!in_array($font_format[1], array('Regular.ttf', 'Bold.ttf', 'Italic.ttf', 'BoldItalic.ttf'))) {
             $this->api->js(true, $this->js()->reload())->univ()->errorMessage('Wrong Font name ');
             $uploadOk = 0;
             echo $font_format[1];
         }
         if (file_exists($target_file)) {
             $this->api->js(true)->univ()->errorMessage('File Already Exist');
             $uploadOk = 0;
         }
         if ($fontFileType != "ttf") {
             $this->api->js(true)->univ()->errorMessage('Only ttf file is upload');
             $uploadOk = 0;
         }
         if ($uploadOk == 1) {
             if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
                 $this->api->js(true, $this->js()->reload())->univ()->successMessage('Font File ' . basename($_FILES["fileToUpload"]["name"] . " has been uploded"));
                 /*TTF File To Convert & create TCPDF Font file*/
                 $pdf = new \TCPDF('l', 'pt', '', true, 'UTF-8', false);
                 $fontname = \TCPDF_FONTS::addTTFfont($target_file, 'TrueTypeUnicode', '', 32);
                 $pdf->AddFont($fontname, '', 14, '', false);
             } else {
                 $this->app->js(true)->univ()->errorMessage('Sorry, there was an error uploading your file');
             }
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Convert and add the selected TrueType or Type1 font to the fonts folder (that must be writeable).
  * @param $fontfile (string) Font file (full path).
  * @param $fonttype (string) Font type. Leave empty for autodetect mode. Valid values are: TrueTypeUnicode, TrueType, Type1, CID0JP = CID-0 Japanese, CID0KR = CID-0 Korean, CID0CS = CID-0 Chinese Simplified, CID0CT = CID-0 Chinese Traditional.
  * @param $enc (string) Name of the encoding table to use. Leave empty for default mode. Omit this parameter for TrueType Unicode and symbolic fonts like Symbol or ZapfDingBats.
  * @param $flags (int) Unsigned 32-bit integer containing flags specifying various characteristics of the font (PDF32000:2008 - 9.8.2 Font Descriptor Flags): +1 for fixed font; +4 for symbol or +32 for non-symbol; +64 for italic. Fixed and Italic mode are generally autodetected so you have to set it to 32 = non-symbolic font (default) or 4 = symbolic font.
  * @param $outpath (string) Output path for generated font files (must be writeable by the web server). Leave empty for default font folder.
  * @param $platid (int) Platform ID for CMAP table to extract (when building a Unicode font for Windows this value should be 3, for Macintosh should be 1).
  * @param $encid (int) Encoding ID for CMAP table to extract (when building a Unicode font for Windows this value should be 1, for Macintosh should be 0). When Platform ID is 3, legal values for Encoding ID are: 0=Symbol, 1=Unicode, 2=ShiftJIS, 3=PRC, 4=Big5, 5=Wansung, 6=Johab, 7=Reserved, 8=Reserved, 9=Reserved, 10=UCS-4.
  * @param $addcbbox (boolean) If true includes the character bounding box information on the php font file.
  * @return (string) TCPDF font name.
  * @author Nicola Asuni
  * @since 5.9.123 (2010-09-30)
  * @public
  * @deprecated
  */
 public function addTTFfont($fontfile, $fonttype = '', $enc = '', $flags = 32, $outpath = '', $platid = 3, $encid = 1, $addcbbox = false)
 {
     return TCPDF_FONTS::addTTFfont($fontfile, $fonttype, $enc, $flags, $outpath, $platid, $encid, $addcbbox);
 }
Exemplo n.º 7
0
<?php

tcpdf();
$fontnama = TCPDF_FONTS::addTTFfont('certificatebold.ttf', 'TrueTypeUnicode', '', 96);
$font = TCPDF_FONTS::addTTFfont('Chocolate Covered Raindrops BOLD.ttf', 'TrueTypeUnicode', '', 100);
$obj_pdf = new TCPDF('P', PDF_UNIT, "LEGAL", true, 'UTF-8', true);
$obj_pdf->SetCreator("Hendy Andrianto S.Kom (www.facebook.com/opchaky.it)");
$toko = "LEMBAGA PENDIDIKAN KETERAMPILAN";
$hal = "GITA PERTIWI";
$alamat = "PUSAT : JL. KEBON TIWU I NO. 10 TASIKMALAYA";
$tlp = "(0265) 323445 HP. 085295168608";
$cabang = "CABANG : JL. RAYA TIMUR BOROLONG CILAMPUNG HILIR SINGAPARNA" . "\n" . "HP. 085353292292";
$judul = $alamat . "\n" . "TELP. " . $tlp;
$foto = "profile.jpg";
$cknama = $this->db->get_where('view_member', array('kode' => $kode))->result();
foreach ($cknama as $row) {
    $nama = $row->nama;
    $tgl = date('d-m-Y', strtotime($row->tgl_lahir));
    $tempat = $row->tempat_lahir;
    $jns = strtoupper($row->nama_tipe);
}
$ckhasil = $this->db->get_where('tbl_status_izajah', array('id' => $status))->result();
foreach ($ckhasil as $key) {
    $hasil = $key->status;
}
$obj_pdf->SetTitle($toko);
$obj_pdf->SetHeaderData("", "", "", "");
$obj_pdf->SetPrintHeader(FALSE);
$obj_pdf->SetPrintFooter(FALSE);
$obj_pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', 9));
$obj_pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
Exemplo n.º 8
0
if (empty($options['fonts'])) {
    echo "ERROR: missing input fonts (try --help for usage)\n\n";
    exit(2);
}
// check the output path
if (!is_dir($options['outpath']) or !is_writable($options['outpath'])) {
    echo "ERROR: Can't write to " . $options['outpath'] . "\n\n";
    exit(3);
}
echo "\n>>> Converting fonts for TCPDF:\n";
echo '*** Output dir set to ' . $options['outpath'] . "\n";
// check if there are conversion errors
$errors = false;
foreach ($options['fonts'] as $font) {
    $fontfile = realpath($font);
    $fontname = TCPDF_FONTS::addTTFfont($fontfile, $options['type'], $options['enc'], $options['flags'], $options['outpath'], $options['platid'], $options['encid'], $options['addcbbox'], $options['link']);
    if ($fontname === false) {
        $errors = true;
        echo "--- ERROR: can't add " . $font . "\n";
    } else {
        echo "+++ OK   : " . $fontfile . ' added as ' . $fontname . "\n";
    }
}
if ($errors) {
    echo "--- Process completed with ERRORS!\n\n";
    exit(4);
}
echo ">>> Process successfully completed!\n\n";
exit(0);
//============================================================+
// END OF FILE
Exemplo n.º 9
0
 // 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;
     //logo
     $display_logo = false;
     if (!isset($_SESSION['fax']['cover_logo']['text'])) {
Exemplo n.º 10
0
 protected function addCustomFontsToPDF(\TCPDF &$pdf, array $arrFonts)
 {
     $objModels = \FilesModel::findMultipleByUuids($arrFonts);
     if ($objModels === null) {
         return false;
     }
     while ($objModels->next()) {
         if (!file_exists(TL_ROOT . '/' . $objModels->path)) {
             continue;
         }
         $font = \TCPDF_FONTS::addTTFfont(TL_ROOT . '/' . $objModels->path, 'TrueTypeUnicode', '', 96);
         $pdf->SetFont($font, '', $this->objModel->share_pdfFontSize ? $this->objModel->share_pdfFontSize : 13, false);
     }
 }
Exemplo n.º 11
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';
 }
 /**
  * Export a PDF report for a project
  *
  * @param \GIB\GradingTool\Domain\Model\Project $project
  */
 public function exportReportAction(\GIB\GradingTool\Domain\Model\Project $project)
 {
     // access check
     $this->checkOwnerOrAdministratorAndDenyIfNeeded($project);
     // The processed submission
     $submission = $this->submissionService->getProcessedSubmission($project);
     if ($submission['hasError']) {
         // Don't export the Grading if is has errors
         $message = new \TYPO3\Flow\Error\Message('The Grading has errors and therefore it cannot be exported. Review and correct the Grading.', \TYPO3\Flow\Error\Message::SEVERITY_ERROR);
         $this->flashMessageContainer->addMessage($message);
         $this->redirect('index', 'Standard');
     }
     // The flat data sheet
     $dataSheet = $this->dataSheetService->getFlatProcessedDataSheet($project);
     $pdf = new \GIB\GradingTool\Utility\TcPdf();
     // set font
     \TCPDF_FONTS::addTTFfont('resource://GIB.GradingTool/Private/Fonts/Cambria.ttf', 'TrueTypeUnicode');
     \TCPDF_FONTS::addTTFfont('resource://GIB.GradingTool/Private/Fonts/Cambria Bold.ttf', 'TrueTypeUnicode');
     \TCPDF_FONTS::addTTFfont('resource://GIB.GradingTool/Private/Fonts/Cambria Italic.ttf', 'TrueTypeUnicode');
     \TCPDF_FONTS::addTTFfont('resource://GIB.GradingTool/Private/Fonts/Cambria Bold Italic.ttf', 'TrueTypeUnicode');
     // set margins
     $pdf->SetMargins(20, 45);
     $pdf->SetHeaderMargin(20);
     $pdf->SetFooterMargin(20);
     $pdf->SetFont('Cambria', '', 10);
     $pdf->SetHeaderFont(array('Cambria', '', 10));
     $pdf->SetFooterFont(array('Cambria', '', 10));
     $pdf->setHtmlVSpace(array('h1' => array(array('h' => 0, 'n' => 0), array('h' => 0, 'n' => 0)), 'h2' => array(array('h' => 0, 'n' => 0), array('h' => 0, 'n' => 0)), 'h3' => array(array('h' => 0, 'n' => 0), array('h' => 1, 'n' => 3)), 'h6' => array(array('h' => 0, 'n' => 0), array('h' => 0, 'n' => 0)), 'p' => array(array('h' => 0, 'n' => 0), array('h' => 1, 'n' => 2.5)), 'ul' => array(array('h' => 0, 'n' => 0), array('h' => 1, 'n' => 2.5))));
     $pdf->setListIndentWidth(3);
     $pdf->SetPrintHeader(TRUE);
     $pdf->SetPrintFooter(TRUE);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('Global Infrastructure Basel Foundation');
     $pdf->SetTitle($project->getProjectTitle());
     $pdf->projectTitle = $project->getProjectTitle();
     $pdf->exportDate = strftime('%Y-%m-%d');
     // set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     // set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     // Must be an Illustrator 3 file
     $epsLogoResource = 'resource://GIB.GradingTool/Private/Images/logo_gib_print.eps';
     // one pixel png
     $onePixelResource = 'resource://GIB.GradingTool/Private/Images/one-pixel.png';
     // partners png
     $gibPartnersResource = 'resource://GIB.GradingTool/Private/Images/gib-partners.png';
     /*** FRONT PAGE ***/
     $pdf->addPage();
     $arguments = array('dataSheet' => $dataSheet, 'project' => $project, 'epsLogoResource' => $epsLogoResource, 'onePixelResource' => $onePixelResource);
     $pdf->writeHTML($this->pdfTemplateRenderer('Front', $arguments), TRUE, FALSE, TRUE);
     /*** PARTNERS PAGE ***/
     $pdf->addPage();
     $arguments = array('gibPartnersResource' => $gibPartnersResource, 'onePixelResource' => $onePixelResource);
     $pdf->writeHTML($this->pdfTemplateRenderer('Partners', $arguments), TRUE, FALSE, TRUE);
     /*** TOC PAGE IS INSERTED AT PAGE 3 ***/
     /*** DATA SHEET FRONT ***/
     $pdf->addPage();
     $pdf->SetAutoPageBreak(FALSE);
     $arguments = array('onePixelResource' => $onePixelResource);
     $pdf->writeHTML($this->pdfTemplateRenderer('DataSheetFront', $arguments), TRUE, FALSE, TRUE);
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     /*** DATA SHEET ***/
     $pdf->addPage();
     $arguments = array('dataSheet' => $dataSheet, 'project' => $project, 'onePixelResource' => $onePixelResource);
     $pdf->writeHTML($this->pdfTemplateRenderer('DataSheet', $arguments), TRUE, FALSE, TRUE);
     /*** GRADING FRONT ***/
     $pdf->addPage();
     $pdf->SetAutoPageBreak(FALSE);
     $arguments = array('onePixelResource' => $onePixelResource);
     $pdf->writeHTML($this->pdfTemplateRenderer('GradingFront', $arguments), TRUE, FALSE, TRUE);
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     /*** GRADING TOOL ***/
     $pdf->addPage();
     $arguments = array('submission' => $submission, 'project' => $project, 'scoreData' => $this->submissionService->getScoreData(), 'onePixelResource' => $onePixelResource);
     $pdf->writeHTML($this->pdfTemplateRenderer('Grading', $arguments), TRUE, FALSE, TRUE);
     /*** ANALYSIS FRONT ***/
     $pdf->addPage();
     $pdf->SetAutoPageBreak(FALSE);
     $arguments = array('onePixelResource' => $onePixelResource);
     $pdf->writeHTML($this->pdfTemplateRenderer('AnalysisFront', $arguments), TRUE, FALSE, TRUE);
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     /*** ANALYSIS ***/
     $pdf->addPage();
     $radarChartFileName = $this->submissionService->getRadarImage($project);
     $lineGraphFileName = $this->submissionService->getLineGraphImage($project);
     $answerLevelGraphFileName = $this->submissionService->getAnswerLevelBarChartImage($project);
     $arguments = array('radarChartFileName' => $radarChartFileName, 'lineGraphFileName' => $lineGraphFileName, 'answerLevelGraphFileName' => $answerLevelGraphFileName, 'onePixelResource' => $onePixelResource, 'submission' => $submission);
     $pdf->writeHTML($this->pdfTemplateRenderer('Analysis', $arguments), TRUE, FALSE, TRUE);
     /** This was the last page */
     $pdf->lastPage();
     /*** TOC PAGE ***/
     $pdf->addTOCPage();
     $arguments = array('dataSheet' => $dataSheet, 'project' => $project, 'onePixelResource' => $onePixelResource);
     $pdf->writeHTML($this->pdfTemplateRenderer('TOCBeforeTOC', $arguments), TRUE, FALSE, TRUE);
     $arguments = array('onePixelResource' => $onePixelResource);
     $afterContent = $this->pdfTemplateRenderer('TOCAfterTOC', $arguments);
     $bookmarkTemplates = array();
     $bookmarkTemplates[0] = '<style>td.blue { color: #0f4fa2; }	td.orange { color: #f36e21; } td.red { color: #c92938; } td.black { color: #000000; } td.grey { color: #555555; }</style><table border="0" cellpadding="0" cellspacing="0"><tr><td class="#TOC_CSSCLASS#" width="12%"><strong>#TOC_CHAPTERNUMBER#</strong></td><td class="black" width="78%"><strong>#TOC_DESCRIPTION#</strong></td><td width="10%"><span style="font-weight:bold;font-size:10pt;text-align:right;" align="right">#TOC_PAGE_NUMBER#</span></td></tr></table>';
     $bookmarkTemplates[1] = '<style>td.blue { color: #0f4fa2; }	td.orange { color: #f36e21; } td.red { color: #c92938; } td.black { color: #000000; } td.grey { color: #555555; }</style><table border="0" cellpadding="0" cellspacing="0"><tr><td class="#TOC_CSSCLASS#" width="12%"><strong>#TOC_CHAPTERNUMBER#</strong></td><td class="grey" width="78%">#TOC_DESCRIPTION#</td><td width="10%"><span style="font-size:10pt;text-align:right;" align="right">#TOC_PAGE_NUMBER#</span></td></tr></table>';
     $pdf->addHTMLTOC(3, 'INDEX', $bookmarkTemplates, TRUE, 'B', array(128, 0, 0), $afterContent);
     $pdf->endTOCPage();
     $pdf->Output('export.pdf', 'I');
 }
Exemplo n.º 13
0
 protected function init()
 {
     //set image scale factor
     $this->setImageScale(PDF_IMAGE_SCALE_RATIO);
     $this->SetDrawColor(125, 165, 65);
     $this->SetFillColor(248, 248, 248);
     $this->SetTextColor(0, 0, 0);
     $this->getAliasNbPages();
     $this->setJPEGQuality(100);
     $this->SetMargins(30, 60, 30);
     if (!empty(\GO::config()->tcpdf_font)) {
         $this->font = \GO::config()->tcpdf_font;
     }
     if (!empty(\GO::config()->tcpdf_ttf_font)) {
         $this->font = \TCPDF_FONTS::addTTFfont(\GO::config()->tcpdf_ttf_font);
         //$this->font=  TCPDF_FONTS::addTTFfont(\GO::config()->tcpdf_ttf_font,'TrueType'); // 2nd parameter is normally autodetected but sometimes this goes wrong.
     }
     if (!empty(\GO::config()->tcpdf_font_size)) {
         $this->font_size = \GO::config()->tcpdf_font_size;
     }
     $this->SetFont($this->font, '', $this->font_size);
     $this->pageWidth = $this->getPageWidth() - $this->lMargin - $this->rMargin;
     $this->SetAutoPageBreak(true, 30);
     // set font
     $this->SetFont($this->font, '', $this->font_size);
 }
Exemplo n.º 14
0
 /**
  * Scans K_PATH_MAIN.'fonts/' folder and moves all files to $this->_getfontpath() folder
  * Added ablity to use TTF fonts (functionality taken from newer version of TCPDF)
  * @uses TCPDF_FONTS::addTTFfont()
  * @uses wp_cache_get()
  * @uses wp_cache_set()
  * @return type
  * @author odokienko@UD
  * @since 1.37.6
  */
 protected function getFontsList()
 {
     $fontlist = wp_cache_get('fontlist', 'wpi_pdf_data');
     if (!empty($fontlist)) {
         $this->fontlist = $fontlist;
         return;
     }
     $uploads_fontsdir_name = $this->_getfontpath();
     if (!is_dir($uploads_fontsdir_name)) {
         @mkdir($uploads_fontsdir_name, 0777, true);
     }
     if (is_dir(K_PATH_MAIN . 'fonts/')) {
         $base_fontsdir = opendir(K_PATH_MAIN . 'fonts/');
         while (($file = readdir($base_fontsdir)) !== false) {
             if ($file == '.' || $file == '..' || file_exists($uploads_fontsdir_name . '/' . $file)) {
                 continue;
             }
             copy(K_PATH_MAIN . 'fonts/' . $file, $uploads_fontsdir_name . '/' . $file);
         }
         closedir($base_fontsdir);
     }
     $uploads_fontsdir = opendir($uploads_fontsdir_name);
     while (($file = readdir($uploads_fontsdir)) !== false) {
         if (strtolower(substr($file, -4)) == '.ttf') {
             include_once 'tcpdf_fonts.php';
             include_once 'tcpdf_static.php';
             $fontname = TCPDF_FONTS::addTTFfont($uploads_fontsdir_name . '/' . $file, '', '', 96, $uploads_fontsdir_name);
             if ($fontname) {
                 array_push($this->fontlist, $fontname);
                 unlink($uploads_fontsdir_name . '/' . $file);
             }
         }
         if (substr($file, -4) == '.php') {
             array_push($this->fontlist, strtolower(basename($file, '.php')));
         }
     }
     wp_cache_add('fontlist', $this->fontlist, 'wpi_pdf_data');
 }
Exemplo n.º 15
0
/**
 * [getPdfFile generate and save PDF file]
 * @param  int $idSpec
 * @return str or false
 */
function getPdfFile($idSpec)
{
    $arSpecification = getSpecification($idSpec);
    if ($arSpecification) {
        $allSumSpec = "";
        foreach ($arSpecification["ITEMS"] as $key => $arItems) {
            $allSumSpec += $arItems["DISCOUNT"]["PRICE"] * $arItems["PROPERTY_COUNT_VALUE"];
            $totalPrice += $arItems["DISCOUNT"]["DISCOUNT_PRICE"] * $arItems["PROPERTY_COUNT_VALUE"];
            $allDisSpec += $arItems["DISCOUNT"]["PRICE"] - $arItems["DISCOUNT"]["DISCOUNT_PRICE"];
            $allSumminDisSpec += $arItems["DISCOUNT"]["DISCOUNT_PRICE"] * $arItems["PROPERTY_COUNT_VALUE"];
        }
        include_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/include/tcpdf/tcpdf.php";
        $curDate = date("d.m.Y H:i:s");
        global $USER;
        $name = $USER->GetFirstName() . "_" . $USER->GetLastName() . "_" . str_replace(" ", "_", $arSpecification["NAME"]) . "_" . $curDate;
        $nameFile = CUtil::translit($name, "ru", translitParams());
        // create new PDF document
        $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
        $fontname = TCPDF_FONTS::addTTFfont($_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/include/tcpdf/font_arial/arial.ttf", '', '', 32);
        // set document information
        $pdf->SetAuthor($USER->GetFirstName() . " " . $USER->GetLastName());
        $pdf->SetTitle("Спецификация " . $arSpecification["NAME"]);
        // set font
        $pdf->SetFont($fontname, 'BI', 12);
        // add a page
        $pdf->AddPage();
        $text = "Спецификация: №" . $arSpecification["ID"];
        $pdf->Write(0, $text, '', 0, 'L', true, 0, false, false, 0);
        $text = "Дизайнер: " . $USER->GetFirstName() . " " . $USER->GetLastName();
        $pdf->Write(0, $text, '', 0, 'L', true, 0, false, false, 0);
        $text = "Название спецификации: " . $arSpecification["NAME"];
        $pdf->Write(0, $text, '', 0, 'L', true, 0, false, false, 0);
        $text = "Стоимость товаров: " . number_format($allSumSpec, 0, 0, " ") . " руб.";
        $pdf->Write(0, $text, '', 0, 'L', true, 0, false, false, 0);
        $text = "Со скидкой: " . number_format($allSumminDisSpec, 0, 0, " ") . " руб.";
        $pdf->Write(0, $text, '', 0, 'L', true, 0, false, false, 0);
        $text = "Экономия: " . number_format($allDisSpec, 0, 0, " ") . " руб.";
        $pdf->Write(0, $text, '', 0, 'L', true, 0, false, false, 0);
        $text = "ИТОГО: " . number_format($totalPrice, 0, 0, " ") . " руб.";
        $pdf->Write(0, $text, '', 0, 'L', true, 0, false, false, 0);
        $text = "Продукты:";
        $pdf->Write(0, $text, '', 0, 'L', true, 0, false, false, 0);
        foreach ($arSpecification["ITEMS"] as $key => $arItems) {
            $text = $key + 1 . ". Артикул: " . $arItems["PRODUCT"]["PROPERTY_ARTIKUL_VALUE"];
            $pdf->Write(0, $text, '', 0, 'L', true, 0, false, false, 0);
            $text = "    Идентификатор продукта: " . $arItems["PRODUCT"]["ID"];
            $pdf->Write(0, $text, '', 0, 'L', true, 0, false, false, 0);
            $text = "    Название: " . $arItems["PRODUCT"]["NAME"];
            $pdf->Write(0, $text, '', 0, 'L', true, 0, false, false, 0);
            $text = "    Цена: " . number_format($arItems["DISCOUNT"]["DISCOUNT_PRICE"], 0, 0, " ") . " руб.";
            $pdf->Write(0, $text, '', 0, 'L', true, 0, false, false, 0);
            $text = "    Количество: " . $arItems["PROPERTY_COUNT_VALUE"];
            $pdf->Write(0, $text, '', 0, 'L', true, 0, false, false, 0);
        }
        $filePath = $_SERVER["DOCUMENT_ROOT"] . "/upload/spec_files/" . $nameFile . ".pdf";
        $path = "/upload/spec_files/" . $nameFile . ".pdf";
        //Close and save PDF document
        $pdf->Output($filePath, 'F');
        return $path;
    }
    return false;
}
Exemplo n.º 16
0
 public function add_font()
 {
     require_once APPPATH . 'libraries/tcpdf/include/tcpdf_fonts.php';
     require APPPATH . 'libraries/tcpdf/tcpdf.php';
     error_reporting(1);
     $fontMaker = new TCPDF_FONTS();
     $font = $fontMaker->addTTFfont($_SERVER['DOCUMENT_ROOT'] . 'js/TEMPSITC_new.TTF');
     $pdfMaker = new TCPDF('L', 'mm', 'A4', true, 'utf-8');
     $pdfMaker->AddPage('L');
     $pdfMaker->SetMargins(0, 0, 0, true);
     $pdfMaker->SetFont($font);
     $pdfMaker->SetFontSize('20');
     $pdfMaker->SetTextColor(0, 0, 0);
     $pdfMaker->Text(10, 10, 'Hello!');
     echo '<pre>';
     print_r($font);
     echo ':)</pre>';
     //$pdfMaker->Output();
 }