Esempio n. 1
0
    /**
     * Create a PDF and export to defined path
     * @param $dir str directory of the source file to convert
     * @param $src str filename of the source file to convert
     * @param $path str path to export the resultant PDF to
     * @param $chapters array chapters to convert into a single PDF
     * @param $journalId int Id of the journal(imprint)
     * @param $args array arguments for the conversion (e.g. Description, cover image, etc)
     * @param $coverPath str path to export the front cover artwork to
     */
    function createPdf($dir = null, $src, $path, $chapters = array(), $journalId, $args = array(), $coverPath)
    {
        $mpdf = new mPDF('utf-8');
        $mpdf->useOddEven = 1;
        $htmlEncode = array('title', 'author');
        foreach ($htmlEncode as $encode) {
            $args[$encode] = htmlentities($args[$encode], ENT_QUOTES, "UTF-8");
        }
        isset($args['title']) ? $mpdf->SetTitle($args['title']) : $mpdf->SetTitle("No Title");
        isset($args['description']) ? $mpdf->SetSubject($args['description']) : $mpdf->SetSubject("No description");
        isset($args['author']) ? $mpdf->SetCreator($args['author']) : $mpdf->SetCreator("No author");
        $CBPPlatformDao =& DAORegistry::getDAO('CBPPlatformDAO');
        $imprintType = $CBPPlatformDao->getImprintType($journalId);
        $stylesheet = $CBPPlatformDao->getImprintStylesheet($journalId);
        $stylesheetContents = file_get_contents($this->stylesheetDir . "{$stylesheet}.css");
        $mpdf->WriteHTML($stylesheetContents, 1);
        $mpdf->WriteHTML($this->contentStart . '
			<htmlpagefooter name="myFooter1" style="display:none">
			<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; 
			    color: #000000; font-weight: bold; font-style: italic;"><tr>
			    <td width="33%" style="text-align: right; ">{PAGENO}</td>
			    </tr></table>
			</htmlpagefooter>
			<htmlpagefooter name="myFooter2" style="display:none">
			<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; 
			    color: #000000; font-weight: bold; font-style: italic;"><tr>
			    <td width="33%"><span style="font-weight: bold; font-style: italic;">{PAGENO}</span></td>
			    </tr></table>
			</htmlpagefooter>');
        $imagesize = getimagesize($args['cover']);
        if (substr($imagesize[1] / $imagesize[0], 0, strpos($imagesize[1] / $imagesize[0], '.') + 1 + 2) == 1.41 || substr($imagesize[1] / $imagesize[0], 0, strpos($imagesize[1] / $imagesize[0], '.') + 1 + 2) == 1.53) {
            $pdfContent .= '<div style="position: absolute; left:0; right: 0; top: 0; bottom: 0;"><img src="' . $args['cover'] . '" id="cover" /></div>';
        } else {
            $pdfContent .= "<div style='margin: 0 auto; width: 80%; text-align: center;'>";
            if (isset($args['title'])) {
                $pdfContent .= "<h1>" . $args['title'] . "</h1>";
            }
            if (isset($args['cover'])) {
                $pdfContent .= "<img src=\"" . $args['cover'] . "\" >";
            } else {
                $pdfContent .= "<br/>";
            }
            if (isset($args['author'])) {
                $pdfContent .= "<h2>" . $args['author'] . "</h2>";
            }
            $pdfContent .= "</div>";
        }
        $mpdf->WriteHTML($pdfContent);
        $mpdf->AddPage('', '', '', '', 'Off');
        $copyrightStatement = $CBPPlatformDao->getJournalCopyrightStatement($journalId);
        if (!empty($copyrightStatement)) {
            $copyrightStatement = reset($copyrightStatement);
            $mpdf->AddPage('', '', '', '', 'Off');
            $innerPageConent = "<div style='width: 90%; text-align: center; margin: 0 auto;'><p>" . $copyrightStatement . "</p></div>";
            $mpdf->WriteHTML($innerPageConent);
        }
        if (!empty($chapters)) {
            $mpdf->TOCpagebreakByArray(array('TOCusePaging' => true, 'TOCuseLinking' => true, 'toc_preHTML' => '<h1>Table of Contents</h1>', 'toc_postHTML' => '', 'resetpagenum' => 1, 'suppress' => 'true'));
            $chapterCount = 0;
            $authorBiographies = 0;
            foreach ($chapters as $chapter) {
                if (!isset($chapter['type']) && $chapter['type'] != "supp") {
                    $chapterCount++;
                } else {
                    if ($chapter['desc'] == "Author Biography") {
                        $authorBiographies++;
                    }
                    $suppChapters = true;
                }
            }
            for ($i = 0; $i < count($chapters); $i++) {
                $htmlEncode = array('name', 'author');
                foreach ($htmlEncode as $encode) {
                    $chapters[$i][$encode] = htmlentities($chapters[$i][$encode], ENT_QUOTES, "UTF-8");
                }
                $document = new TransformDoc();
                $document->setStrFile($chapters[$i]['src'], $chapters[$i]['dir']);
                $document->generateXHTML();
                //problem, here
                $document->validatorXHTML();
                if ($chapterCount == 1) {
                    $contentPreg = $this->stripTagsAddChapters($document->getStrXHTML());
                    $contentPreg = ltrim($contentPreg);
                    if (substr($contentPreg, 0, 13) == "<pagebreak />") {
                        $contentPreg = substr_replace($contentPreg, '', 0, 13);
                    }
                    $mpdf->addPage('', '', '', '', 'On');
                    $mpdf->PageNumSubstitutions[] = array('from' => $mpdf->page + 1, 'reset' => 1, 'type' => '1', 'suppress' => 'off');
                    $mpdf->WriteHTML("<div class='content'>", 2);
                    $mpdf->WriteHTML($contentPreg, 2);
                    if ($suppChapters == true) {
                        foreach ($chapters as $chapter) {
                            if (isset($chapter['type']) && $chapter['type'] == "supp") {
                                $document = new TransformDoc();
                                $document->setStrFile($chapter['src'], $chapter['dir']);
                                $document->generateXHTML();
                                $document->validatorXHTML();
                                if ($authorBiographies > 1) {
                                    $contentPreg = $this->stripTags($document->getStrXHTML());
                                    $mpdf->TOC_Entry($chapter['name']);
                                    $mpdf->WriteHTML("<pagebreak />" . $contentPreg, 2);
                                } else {
                                    $addAuthorBiographyToBack = true;
                                    $authorBiography = $this->stripTags($document->getStrXHTML());
                                }
                            }
                        }
                    }
                    break;
                } else {
                    $contentPreg = $this->stripTags($document->getStrXHTML());
                    $contentPreg = ltrim($contentPreg);
                    if (substr($contentPreg, 0, 13) == "<pagebreak />") {
                        $contentPreg = substr_replace($contentPreg, '', 0, 13);
                    }
                    if ($i != 0) {
                        $prepend = "<pagebreak />";
                    } else {
                        $mpdf->addPage('', 'E', '', '', 'On');
                        $mpdf->PageNumSubstitutions[] = array('from' => $mpdf->page + 1, 'reset' => 1, 'type' => '1', 'suppress' => 'off');
                        $mpdf->WriteHTML("<div class='content'>", 2);
                    }
                    if ($imprintType == "atomistic") {
                        $mpdf->WriteHTML($prepend . "<tocentry content='" . $chapters[$i]['name'] . "' level='0' />" . $contentPreg, 2);
                    } elseif ($imprintType == "collection") {
                        if ($chapters[$i]['description'] != "") {
                            $introduction = "<div class='submissionIntro'><h1>" . $chapters[$i]['author'] . "</h1>" . $this->stripTags($chapters[$i]['description'], true) . "</div><pagebreak /><tocentry content='" . $chapters[$i]['name'] . " by " . $chapters[$i]['author'] . "' level='0' />";
                        }
                        $mpdf->WriteHTML($prepend . $introduction . $contentPreg, 2);
                    }
                }
            }
            $mpdf->writeHTML("</div>");
            if (isset($args['description'])) {
                $mpdf->WriteHTML("<pagebreak page-selector='none' odd-footer-value = '' even-footer-value= '' /><pagebreak /><div style='width: 90%; text-align: center; margin: 0 auto;'><p>" . $this->stripTags($args['description'], true) . "</p></div>", 2);
                if ($addAuthorBiographyToBack == true) {
                    $backCoverContent .= "<div style='width: 90%; text-align: center; margin: 0 auto; margin-top: 10px;'><p>" . $authorBiography . "</p></div>";
                }
                $backCoverContent .= "<p style='width: 90%; text-align: center; margin: 0 auto;'><strong>Published " . date("F Y") . ", Scarborough, UK</strong></p>";
                $mpdf->WriteHTML($backCoverContent, 2);
            }
            $mpdf->WriteHTML("</body></html>");
            $pdfData = $mpdf->Output('', 'S');
            $pageCount = $mpdf->page;
            file_put_contents($path, $pdfData);
            if (file_exists($this->stylesheetDir . "{$stylesheet}-FC.css")) {
                $this->createCoverPdf($stylesheet, $pageCount, $args['cover'], $this->stripTags($args['description'], true), $addAuthorBiographyToBack, $authorBiography, $args['title'], $args['imprint'], $coverPath);
            }
            return true;
        } else {
            $document = new TransformDoc();
            $document->setStrFile($src, $dir);
            $document->generateXHTML();
            $document->validatorXHTML();
            $contentPreg = $this->stripTagsAddChapters($document->getStrXHTML());
            $contentPreg = ltrim($contentPreg);
            if (substr($contentPreg, 0, 13) == "<pagebreak />") {
                $contentPreg = substr_replace($contentPreg, '', 0, 13);
            }
            $mpdf->addPage('', 'E', '', '', 'On');
            $mpdf->PageNumSubstitutions[] = array('from' => $mpdf->page + 1, 'reset' => 1, 'type' => '1', 'suppress' => 'off');
            $mpdf->WriteHTML("<div class='content'>", 2);
            $mpdf->WriteHTML($contentPreg, 2);
            $mpdf->WriteHTML("</div></body></html>");
            $pdfData = $mpdf->Output('', 'S');
            file_put_contents($path, $pdfData);
            return true;
        }
    }
Esempio n. 2
0
<?php

include './mpdf/mpdf.php';
$mpdf = new mPDF();
$mpdf->TOCpagebreak();
$mpdf->TOC_Entry("X Acknowledgements");
$mpdf->Output();
exit;
Esempio n. 3
0
        </div>';

      $mpdf->TOCpagebreakByArray(array(
        'TOCuseLinking' => true,
        'toc_ohname' => 'indice',
        'toc_ohvalue' => 1,
        'toc_preHTML' => $previo, 
        'toc_postHTML' => $post,
        'resetpagenum' => 2,
        'ohname' => 'indice',
        'ohvalue' => 1,
        ));

      $valida = 0;
      $mpdf->WriteHTML('<b><h2>1. Objetivo General</h2></b>');
      $mpdf->TOC_Entry('<b style="font-family: roboto-light">1. Objetivo General</b>', 0);
      if($row["objetivo"] == ''){
        $mpdf->WriteHTML('<div style="text-align:justify;">No Aplica.</div>');
        $altura = $mpdf->y;
        if($altura > 205){
          $mpdf->AddPage();
        } else {
          $mpdf->WriteHTML('<br>');
        }
      }
      else {  
        $mpdf->WriteHTML('<div style="text-align:justify;">'.$row["objetivo"].'</div>');
        $altura = $mpdf->y;
        if($altura > 205){
          $mpdf->AddPage();
        } else {
Esempio n. 4
0
$mpdf->WriteHTML("<p style='font-size: 16px; text-align: left; float: left;'><i> Students: </i></span>");
$mpdf->WriteHTML("<columnbreak />");
$mpdf->WriteHTML("<p style='font-size: 16px; text-align: right; float: right;'><i> Faculty: </i> </span>");
$mpdf->WriteHTML("</div>");
$mpdf->TOCpagebreak(array('toc-preHTML' => '<h1> Contents </h1>'));
$mpdf->AddPage('P', 'Letter', '1');
//$mpdf->WriteHTML('<pagebreak resetpagenum="1" />');
$mpdf->WriteHTML('<columns column-count="2" column-gap="17" />');
$mpdf->keepColumns = true;
$mpdf->pagenumPrefix = "Page ";
$mpdf->SetHeader('{PAGENO}');
foreach ($sql as $name => $dep) {
    $result = $conn->query($dep);
    $mpdf->WriteHTML('<h4 class="text-align: center"> ' . strtoupper($name) . '</h4>');
    $letter = 'A';
    $mpdf->TOC_Entry($name, 0);
    if ($result->num_rows > 0) {
        while ($row = $result->fetch_assoc()) {
            $text = $row['abstract'];
            $title = $row['title'];
            $mpdf->TOC_Entry($title, 1);
            $text = iconv("UTF-8", "UTF-8//IGNORE", $text);
            $title = iconv("UTF-8", "UTF-8//IGNORE", $title);
            $authors = array();
            array_push($authors, $row['pauthor']);
            // getting authors
            $app_id = $row['app_id'];
            $author_sql = "SELECT author_name FROM authors WHERE app_id='{$app_id}'";
            $author_result = $conn->query($author_sql);
            if ($author_result->num_rows > 0) {
                while ($auth = $author_result->fetch_assoc()) {