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'); }
/** * Merges your provided PDFs and outputs to specified location. * @param $outputmode * @param $outputname * @return PDF */ public function merge($outputmode = 'browser', $outputpath = 'newfile.pdf') { if (!isset($this->_files) || !is_array($this->_files)) { throw new exception("No PDFs to merge."); } $fpdi = new FPDI(); $fpdi->setPrintHeader(FALSE); $fpdi->setPrintFooter(FALSE); //merger operations foreach ($this->_files as $file) { $filename = $file[0]; $filepages = $file[1]; $count = $fpdi->setSourceFile($filename); //add the pages if ($filepages == 'all') { for ($i = 1; $i <= $count; $i++) { $template = $fpdi->importPage($i); $size = $fpdi->getTemplateSize($template); $orientation = $size['w'] <= $size['h'] ? 'P' : 'L'; $fpdi->AddPage($orientation, array($size['w'], $size['h'])); $fpdi->useTemplate($template); } } else { foreach ($filepages as $page) { if (!($template = $fpdi->importPage($page))) { throw new exception("Could not load page '{$page}' in PDF '{$filename}'. Check that the page exists."); } $size = $fpdi->getTemplateSize($template); $orientation = $size['w'] <= $size['h'] ? 'P' : 'L'; $fpdi->AddPage($orientation, array($size['w'], $size['h'])); $fpdi->useTemplate($template); } } } //output operations $mode = $this->_switchmode($outputmode); if ($mode == 'S') { return $fpdi->Output($outputpath, 'S'); } else { if ($fpdi->Output($outputpath, $mode) == '') { return true; } else { throw new exception("Error outputting PDF to '{$outputmode}'."); return false; } } }
} //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;
/** * 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; }
public function download_tag() { $r1 = Input::has('r1') ? Input::get('r1') : 'Mr Sam Sample'; $r2 = Input::has('r2') ? Input::get('r2') : 'Sample Street'; $r3 = Input::has('r3') ? Input::get('r3') : 'Sampletown VIC 3000'; $r4 = Input::has('r4') ? Input::get('r4') : 'phone +61 414 141 414'; if ($user = Auth::user()) { $member = Member::where('user_id', '=', $user->id)->first(); $r1 = $member->firstname . ' ' . $member->lastname; $r2 = $member->address; $r3 = $member->suburb . ' ' . $member->state . ' ' . $member->postcode; $r4 = 'phone ' . $member->phone; } $pdf = new FPDI('L'); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->AddPage(); $pdf->setSourceFile(realpath(dirname(__FILE__)) . '/../../public/assets/pdf/luggage_tags.pdf'); $pdf->SetTextColor(0, 0, 0); $tplIdx = $pdf->importPage(1); $pdf->useTemplate($tplIdx); $pdf->SetFont('museosansrounded1000'); $pdf->SetXY(121, 40); $pdf->Write(20, $r1); $pdf->SetXY(121, 45); $pdf->Write(20, $r2); $pdf->SetXY(121, 50); $pdf->Write(20, $r3); $pdf->SetXY(121, 55); $pdf->Write(20, $r4); $pdf->Output('luggage-tag.pdf'); }
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'); }