当前位置: 首页>>代码示例>>PHP>>正文


PHP FPDI::Rotate方法代码示例

本文整理汇总了PHP中FPDI::Rotate方法的典型用法代码示例。如果您正苦于以下问题:PHP FPDI::Rotate方法的具体用法?PHP FPDI::Rotate怎么用?PHP FPDI::Rotate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FPDI的用法示例。


在下文中一共展示了FPDI::Rotate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: watermark_and_sent

function watermark_and_sent(stdClass $issuedcert)
{
    global $CFG, $USER, $COURSE, $DB, $PAGE;
    if ($issuedcert->haschange) {
        //This issue have a haschange flag, try to reissue
        if (empty($issuedcert->timedeleted)) {
            require_once $CFG->dirroot . '/mod/simplecertificate/locallib.php';
            try {
                // Try to get cm
                $cm = get_coursemodule_from_instance('simplecertificate', $issuedcert->certificateid, 0, false, MUST_EXIST);
                $context = context_module::instance($cm->id);
                //Must set a page context to issue ....
                $PAGE->set_context($context);
                $simplecertificate = new simplecertificate($context, null, null);
                $file = $simplecertificate->get_issue_file($issuedcert);
            } catch (moodle_exception $e) {
                // Only debug, no errors
                debugging($e->getMessage(), DEBUG_DEVELOPER, $e->getTrace());
            }
        } else {
            //Have haschange and timedeleted, somehting wrong, it will be impossible to reissue
            //add wraning
            debugging("issued certificate [{$issuedcert->id}], have haschange and timedeleted");
        }
        $issuedcert->haschange = 0;
        $DB->update_record('simplecertificate_issues', $issuedcert);
    }
    if (empty($file)) {
        $fs = get_file_storage();
        if (!$fs->file_exists_by_hash($issuedcert->pathnamehash)) {
            print_error(get_string('filenotfound', 'simplecertificate', ''));
        }
        $file = $fs->get_file_by_hash($issuedcert->pathnamehash);
    }
    $canmanage = false;
    if (!empty($COURSE)) {
        $canmanage = has_capability('mod/simplecertificate:manage', context_course::instance($COURSE->id));
    }
    if ($canmanage || !empty($USER) && $USER->id == $issuedcert->userid) {
        send_stored_file($file, 0, 0, true);
    } else {
        require_once $CFG->libdir . '/pdflib.php';
        require_once $CFG->dirroot . '/mod/simplecertificate/lib/fpdi/fpdi.php';
        // copy to a tmp file
        $tmpfile = $file->copy_content_to_temp();
        // TCPF doesn't import files yet, so i must use FPDI
        $pdf = new FPDI();
        $pageCount = $pdf->setSourceFile($tmpfile);
        for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
            // import a page
            $templateId = $pdf->importPage($pageNo);
            // get the size of the imported page
            $size = $pdf->getTemplateSize($templateId);
            // create a page (landscape or portrait depending on the imported page size)
            if ($size['w'] > $size['h']) {
                $pdf->AddPage('L', array($size['w'], $size['h']));
                // Font size 1/3 Height if it landscape
                $fontsize = $size['h'] / 3;
            } else {
                $pdf->AddPage('P', array($size['w'], $size['h']));
                // Font size 1/3 Width if it portrait
                $fontsize = $size['w'] / 3;
            }
            // use the imported page
            $pdf->useTemplate($templateId);
            // Calculating the rotation angle
            $rotAngle = atan($size['h'] / $size['w']) * 180 / pi();
            // Find the middle of the page to use as a pivot at rotation.
            $mX = $size['w'] / 2;
            $mY = $size['h'] / 2;
            // Set the transparency of the text to really light
            $pdf->SetAlpha(0.25);
            $pdf->StartTransform();
            $pdf->Rotate($rotAngle, $mX, $mY);
            $pdf->SetFont("freesans", "B", $fontsize);
            $pdf->SetXY(0, $mY);
            $boder_style = array('LTRB' => array('width' => 2, 'dash' => $fontsize / 5, 'cap' => 'round', 'join' => 'round', 'phase' => $fontsize / $mX));
            $pdf->Cell($size['w'], $fontsize, get_string('certificatecopy', 'simplecertificate'), $boder_style, 0, 'C', false, '', 4, true, 'C', 'C');
            $pdf->StopTransform();
            // Reset the transparency to default
            $pdf->SetAlpha(1);
        }
        // Set protection seems not work, so comment
        // $pdf->SetProtection(array('print', 'modify', 'print-high'),null, random_string(), '1',null);
        // For DEGUG
        // $pdf->Output($file->get_filename(), 'I');
        // Save and send tmpfiles
        $pdf->Output($tmpfile, 'F');
        send_temp_file($tmpfile, $file->get_filename());
    }
}
开发者ID:v--k,项目名称:moodle-mod_simplecertificate,代码行数:91,代码来源:wmsendfile.php

示例2: rotate

 /**
  * Rotate
  *
  * @access public
  * @param int $degrees
  */
 public function rotate($degrees)
 {
     $pdf = new \FPDI();
     $pagecount = $pdf->setSourceFile($this->get_path());
     for ($i = 1; $i <= $pagecount; $i++) {
         $templateId = $pdf->importPage($i);
         $size = $pdf->getTemplateSize($templateId);
         if ($size['w'] > $size['h']) {
             $pdf->AddPage('L', [$size['w'], $size['h'], 'Rotate' => $degrees]);
         } else {
             $pdf->AddPage('P', [$size['w'], $size['h'], 'Rotate' => $degrees]);
         }
         $pdf->useTemplate($templateId);
     }
     $pdf->Rotate($degrees);
     $content = $pdf->Output('ignored', 'S');
     $file = \Skeleton\File\File::store('page_' . $i . '.pdf', $content);
     return $file;
 }
开发者ID:tigron,项目名称:skeleton-file-pdf,代码行数:25,代码来源:Pdf.php


注:本文中的FPDI::Rotate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。