/** * Creates the PDF and does a specific output (see PDF_Generator function above for $output variable types) */ public function PDF_processing($html, $filename, $id, $output = 'view', $arguments) { /* * DOMPDF replaced with mPDF in v3.0.0 * Check which version of mpdf we are calling * Full, Lite or Tiny */ if (!class_exists('mPDF')) { if (FP_PDF_ENABLE_MPDF_TINY === true) { include FP_PDF_PLUGIN_DIR . '/mPDF/mpdf-extra-lite.php'; } elseif (FP_PDF_ENABLE_MPDF_LITE === true) { include FP_PDF_PLUGIN_DIR . '/mPDF/mpdf-lite.php'; } else { include FP_PDF_PLUGIN_DIR . '/mPDF/mpdf.php'; } } /* * Initialise class and set the paper size and orientation */ $paper_size = $arguments['pdf_size']; if (!is_array($paper_size)) { $orientation = $arguments['orientation'] == 'landscape' ? '-L' : ''; $paper_size = $paper_size . $orientation; } else { $orientation = $arguments['orientation'] == 'landscape' ? 'L' : 'P'; } $mpdf = new mPDF('', $paper_size, 0, '', 15, 15, 16, 16, 9, 9, $orientation); /* * Display PDF is full-page mode which allows the entire PDF page to be viewed * Normally PDF is zoomed right in. */ $mpdf->SetDisplayMode('fullpage'); if (FP_PDF_ENABLE_SIMPLE_TABLES === true) { $mpdf->simpleTables = true; } /* * Automatically detect fonts and substitue as needed */ if (FP_PDF_DISABLE_FONT_SUBSTITUTION === true) { $mpdf->useSubstitutions = false; } else { $mpdf->SetAutoFont(AUTOFONT_ALL); $mpdf->useSubstitutions = true; } /* * Set Creator Meta Data */ $mpdf->SetCreator('Formidable Pro PDF Extended v' . FP_PDF_EXTENDED_VERSION . '. http://formidablepropdfextended.com'); /* * Set RTL languages at user request */ if ($arguments['rtl'] === true) { $mpdf->SetDirectionality('rtl'); } /* * Set up security if user requested */ if ($arguments['security'] === true && $arguments['pdfa1b'] !== true && $arguments['pdfx1a'] !== true) { $password = strlen($arguments['pdf_password']) > 0 ? $arguments['pdf_password'] : ''; $master_password = strlen($arguments['pdf_master_password']) > 0 ? $arguments['pdf_master_password'] : null; $pdf_privileges = is_array($arguments['pdf_privileges']) ? $arguments['pdf_privileges'] : array(); $mpdf->SetProtection($pdf_privileges, $password, $master_password, 128); } /* PDF/A1-b support added in v3.4.0 */ if ($arguments['pdfa1b'] === true) { $mpdf->PDFA = true; $mpdf->PDFAauto = true; } else { if ($arguments['pdfx1a'] === true) { $mpdf->PDFX = true; $mpdf->PDFXauto = true; } } /* * Check if we should auto prompt to print the document on open */ if (isset($_GET['print'])) { $mpdf->SetJS('this.print();'); } /* load HTML block */ $mpdf->WriteHTML($html); switch ($output) { case 'download': $mpdf->Output($filename, 'D'); exit; break; case 'view': $mpdf->Output(time(), 'I'); exit; break; case 'save': /* * PDF wasn't writing to file with the F method - http://mpdf1.com/manual/index.php?tid=125 * Return as a string and write to file manually */ $pdf = $mpdf->Output('', 'S'); return $this->savePDF($pdf, $filename, $id); break; } }
public function pdf($content, $namafile, $paper_size = '', $orientation = 'P', $border = true, $title = '', $subject = '', $mode = 'D', $watermark = false) { $margin = 20; $namafile = preg_replace('/\\.pdf$/', '', $namafile); $mL = $mR = $mT = $mB = $margin; // $mB = $margin + 50; $mH = 0; $mF = 0; if (!$paper_size) { $paper_size = array(215, 330); } Yii::import('system.docotel.cms.extensions.mpdf.mPDF'); $mpdf = new mPDF('', $paper_size, 0, '', $mL, $mR, $mT, $mB, $mH, $mF, $orientation); $mpdf->SetDefaultFont('Arial'); $mpdf->SetProtection(array('print', 'print-highres'), '', md5(time()), 128); $mpdf->SetTitle($title); $mpdf->SetAuthor('Makarim & Taira'); $mpdf->SetCreator('News'); $mpdf->SetSubject($subject); $mpdf->h2toc = array('H4' => 0, 'H5' => 1); //$mpdf->setFooter('{PAGENO}'); // $stylesheet = file_get_contents(Yii::app()->getBaseUrl(true).'/themes/flatlab/assets/css/bootstrap.min.css'); // external css // $mpdf->WriteHTML($stylesheet,1); // echo $content; exit; $mpdf->WriteHTML($content); $mpdf->Output($namafile . '.pdf', $mode); if ($mode === 'D' or $mode === 'I') { exit; } }
static public function mpdf( $html_path, $pdf_path, $css_rel_path, $format = 'A4', $download = false) { // reporting komplett abschalten $error_reporting = error_reporting(); error_reporting(0); ProjectConfiguration::registerMPDF(); $mpdf=new mPDF('ch-DE',$format,'8','DejaVuSansCondensed',15,15,30,15,10,10); $mpdf->packTableData = true; //$mpdf->debug = true; $mpdf->SetDisplayMode('fullpage'); $mpdf->defaultfooterfontstyle=''; $mpdf->defaultfooterfontsize='8'; $mpdf->SetFooter(basename($pdf_path).'|Stand: {DATE j.m.Y H:i}|Seite {PAGENO}/{nbpg}'); $mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list $mpdf->shrink_tables_to_fit=1; // LOAD a stylesheet #$stylesheet = file_get_contents(sfConfig::get('sf_web_dir').'/css/backend/pdf/class_etat.css'); $stylesheet = file_get_contents(sfConfig::get('sf_web_dir').'/css/'.$css_rel_path); $mpdf->WriteHTML($stylesheet,1); // parameter 1 indicates this is css $html = file_get_contents($html_path); $mpdf->WriteHTML($html,2); //$mpdf->SetTitle(); $mpdf->SetAuthor(''); $mpdf->SetCreator('rockstep'); if ($download) { $mpdf->Output( $pdf_path, 'I'); } else { $mpdf->Output( $pdf_path, 'F'); } error_reporting($error_reporting); }
/** * Export a pdf * * @static * @param string $title Document title * @param string $css CSS Contents * @param string $html HTML Contents * @param string $page_format Default A4 * @param string $orientation Can be P|L * @return boolean */ public static function pdf_export($title, $css, $html, $page_format = 'A4', $orientation = 'P') { // language set $l = array(); $l['a_meta_charset'] = 'UTF-8'; $l['a_meta_dir'] = 'rtl'; $l['a_meta_language'] = X4Route_core::$lang; $l['w_page'] = _PAGE; X4Core_core::auto_load('mpdf_library'); // create the PDF object $mpdf = new mPDF(X4Route_core::$lang, $page_format, 0, 0, 0, 0, 0, 0, $orientation); $title = SERVICE . ' - ' . $title . ' - ' . date('Y-m-d H:i:s'); $mpdf->SetAuthor($_SESSION['nickname']); $mpdf->SetCreator(SERVICE); $mpdf->SetTitle($title); $mpdf->SetDisplayMode('fullwidth'); $mpdf->WriteHTML($css, 1); $mpdf->WriteHTML($html, 2); $filename = X4Utils_helper::unspace(str_replace(' - ', '-', $title), true); $mpdf->Output($filename . '.pdf', 'D'); exit; }
<?php # THIS ONE DOES NOT HAVE AddPageByArray include "../mpdf.php"; $html_data = file_get_contents("body.html"); $html = substr($html_data, 12, strlen($html_data) - 27); $style_data = file_get_contents("style_current.css"); $frontmatter_data = file_get_contents("frontmatter_current.html"); $mpdf = new mPDF(); // Make it DOUBLE SIDED document $mpdf->mirrorMargins = 1; $mpdf->bleedMargin = 4; $mpdf->h2toc = array(); $mpdf->WriteHTML($style_data, 1); $html = "<sethtmlpagefooter name=\"footer-left\" page=\"E\" value=\"on\" />" . $html; $html = "<sethtmlpagefooter name=\"footer-right\" page=\"O\" value=\"on\" />" . $html; $mpdf->WriteHTML($frontmatter_data, 2); $mpdf->WriteHTML($html, 2); $mpdf->SetTitle("Title"); $mpdf->SetAuthor("Author"); $mpdf->SetCreator("Booktype"); $mpdf->Output(); ?>
/** * Retorna o PDF em forma de string binária * O objetivo é permitir envio do PDF através de anexo de e-mail */ protected function _getPDFBinaryString($css, $html) { // Foi difícil, mas achei a solução: http://stackoverflow.com/a/9178296/846419 try { ob_start(); // This is very important to start output buffering and to catch out any possible notices require_once MPDF_PATH; $mpdf = new mPDF('utf-8', 'A4', 10, 'Arial', 5, 5, 48, 25, 10, 10); $mpdf->debug = true; $mpdf->allow_output_buffering = true; $mpdf->useOnlyCoreFonts = true; // false is default $mpdf->SetTitle($this->doc_titulo); $mpdf->SetAuthor($this->doc_autor); $mpdf->SetCreator($this->doc_criador); $mpdf->SetWatermarkText("SiGE"); $mpdf->showWatermarkText = true; $mpdf->watermark_font = 'DejaVuSansCondensed'; $mpdf->watermarkTextAlpha = 0.1; $mpdf->SetDisplayMode('fullpage'); // $mpdf->SetAutoFont(0); // deprecated $mpdf->autoScriptToLang = FALSE; $mpdf->WriteHTML($css, 1); $mpdf->WriteHTML($html); $pdf_binary = $mpdf->Output('', 'S'); // With the binary PDF data in $pdf we can do whatever we want - attach it to email, save to filesystem, push to browser's PDF plugin or offer it to user for download // ob_get_contents(); // Here we catch out previous output from buffer (and can log it, email it, or throw it away as I do :-) ) ob_end_clean(); // Finaly we clean output buffering and turn it off return $pdf_binary; } catch (Exception $e) { throw $e; } }
/** * Generate the PDF file using the mPDF library. * * @param string $html * contents of the template already with the node data. * @param string $filename * name of the PDF file to be generated. */ public function generate($html, $config, $filename = 'newPdfDocument') { // International Paper Sizes ( width x height). $paper_size = array('4A0' => array('w' => 1682, 'h' => 2378), '2A0' => array('w' => 1189, 'h' => 1682), 'A0' => array('w' => 841, 'h' => 1189), 'A1' => array('w' => 594, 'h' => 841), 'A2' => array('w' => 420, 'h' => 594), 'A3' => array('w' => 297, 'h' => 420), 'A4' => array('w' => 210, 'h' => 297), 'A5' => array('w' => 148, 'h' => 210), 'A6' => array('w' => 105, 'h' => 148), 'A7' => array('w' => 74, 'h' => 105), 'A8' => array('w' => 52, 'h' => 74), 'A9' => array('w' => 37, 'h' => 52), 'A10' => array('w' => 26, 'h' => 37), 'B0' => array('w' => 1000, 'h' => 1414), 'B1' => array('w' => 707, 'h' => 1000), 'B2' => array('w' => 500, 'h' => 707), 'B3' => array('w' => 353, 'h' => 500), 'B4' => array('w' => 250, 'h' => 353), 'B5' => array('w' => 176, 'h' => 250), 'B6' => array('w' => 125, 'h' => 176), 'B7' => array('w' => 88, 'h' => 125), 'B8' => array('w' => 62, 'h' => 88), 'B9' => array('w' => 44, 'h' => 62), 'B10' => array('w' => 31, 'h' => 44), 'C0' => array('w' => 917, 'h' => 1297), 'C1' => array('w' => 648, 'h' => 917), 'C2' => array('w' => 458, 'h' => 648), 'C3' => array('w' => 324, 'h' => 458), 'C4' => array('w' => 229, 'h' => 324), 'C5' => array('w' => 162, 'h' => 229), 'C6' => array('w' => 114, 'h' => 162), 'C7' => array('w' => 81, 'h' => 114), 'C8' => array('w' => 57, 'h' => 81), 'C9' => array('w' => 40, 'h' => 57), 'C10' => array('w' => 28, 'h' => 40), 'RA0' => array('w' => 860, 'h' => 1220), 'RA1' => array('w' => 610, 'h' => 860), 'RA2' => array('w' => 430, 'h' => 610), 'SRA0' => array('w' => 900, 'h' => 1280), 'SRA1' => array('w' => 640, 'h' => 900), 'SRA2' => array('w' => 450, 'h' => 640), 'Letter' => array('w' => 215.9, 'h' => 279.4), 'Legal' => array('w' => 215.9, 'h' => 355.6), 'Ledger' => array('w' => 279.4, 'h' => 431.8)); $page = $config['page_type']; //conf $font_size = $config['font_size']; $font_style = $config['font_style']; // DEFAULT PDF margin Values. $margin_top = $config['margin_top']; //conf $margin_right = $config['margin_right']; $margin_bottom = $config['margin_bottom']; $margin_left = $config['margin_left']; $margin_header = $config['margin_header']; $margin_footer = $config['margin_footer']; // Creating Instance of mPDF Class Library. require_once 'Src/Modules/Pdf/Libs/mpdf60/mpdf.php'; $mpdf = new \mPDF('', array($paper_size[$page]['w'], $paper_size[$page]['h']), $font_size, $font_style, $margin_left, $margin_right, $margin_top, $margin_bottom, $margin_header, $margin_footer); // set document DPI $mpdf->dpi = 96; // Set image DPI $mpdf->img_dpi = 96; // Enabling header option if available. $header = $config['header']; //string in conf if (isset($header) && $header != NULL) { //$header = token_replace($header); $mpdf->SetHTMLHeader($header); } // Enabling Footer option if available. $footer = $config['footer']; if (isset($footer) && $footer != NULL) { //$footer = token_replace($footer); $mpdf->SetHTMLFooter($footer); } // Setting Watermark Text to PDF. $watermark_option = 'text'; //conf $watermark_opacity = $config['watermark_opacity']; // For watermark Text. if ($watermark_option == 'text') { $text = $config['watermark_text']; if (isset($text) && $text != NULL) { $mpdf->SetWatermarkText($text, $watermark_opacity); $mpdf->showWatermarkText = TRUE; } } // Setting Title to PDF. $title = $config['doc_title']; if (isset($title) && $title != NULL) { $mpdf->SetTitle($title); } // Setting Author to PDF. $author = $config['doc_author']; //conf if (isset($author) && $author != NULL) { $mpdf->SetAuthor($author); } // Setting Subject to PDF. $subject = $config['doc_subject']; if (isset($subject) && $subject != NULL) { $mpdf->SetSubject($subject); } // Setting creator to PDF. $creator = $config['doc_creator']; if (isset($creator) && $creator != NULL) { $mpdf->SetCreator($creator); } // Setting Password to PDF. $password = $config['password']; if (isset($password) && $password != NULL) { // Print and Copy is allowed. $mpdf->SetProtection(array('print', 'copy'), $password, $password); } // Setting CSS stylesheet to PDF. if (!empty($config['stylesheets'])) { $cssArr = explode('<br />', nl2br($config['stylesheets'])); $cssArr = array_map('trim', $cssArr); $cssArr = array_filter($cssArr); foreach ($cssArr as $key => $stylesheet) { $stylesheet_content = NULL; if (isset($stylesheet) && $stylesheet != NULL) { $stylesheet_content = file_get_contents($stylesheet); $mpdf->WriteHTML($stylesheet_content, 1); } } } // Writing html content for pdf buffer. $mpdf->WriteHTML($html); return $mpdf->Output($filename . '.pdf', $config['save_option']); }
* PURPOSE. See the GNU Affero General Public License for more details. * * * * You should have received a copy of the GNU Affero General Public * * License along with eLabFTW. If not, see <http://www.gnu.org/licenses/>. * * * ********************************************************************************/ require_once 'inc/common.php'; require_once ELAB_ROOT . 'inc/locale.php'; require_once ELAB_ROOT . 'vendor/autoload.php'; // Check id is valid and assign it to $id if (isset($_GET['id']) && is_pos_int($_GET['id'])) { $id = $_GET['id']; } else { die(_("The id parameter is not valid!")); } // check the type if ($_GET['type'] === 'experiments' || $_GET['type'] === 'items') { $type = $_GET['type']; } else { die(_("The type parameter is not valid.")); } // do the pdf $pdf = new \Elabftw\Elabftw\MakePdf($id, $type); $mpdf = new mPDF(); $mpdf->SetAuthor($pdf->author); $mpdf->SetTitle($pdf->title); $mpdf->SetSubject('eLabFTW pdf'); $mpdf->SetKeywords($pdf->tags); $mpdf->SetCreator('www.elabftw.net'); $mpdf->WriteHTML($pdf->content); $mpdf->Output($pdf->getFileName(), 'I');
<?php # THIS ONE DOES NOT HAVE AddPageByArray ANY MORE :-) include "../mpdf.php"; $html_data = file_get_contents("body.html"); $html = substr($html_data, 12, strlen($html_data) - 27); $style_data = file_get_contents("style_setheader.css"); $frontmatter_data = file_get_contents("frontmatter_setheader.html"); // Create new PDF with font subsetting, 234mm wide, 297mm high $mpdf = new mPDF('s', array(234, 297)); // Make it DOUBLE SIDED document with 4mm bleed $mpdf->mirrorMargins = 1; $mpdf->bleedMargin = 4; $mpdf->h2toc = array(); $mpdf->WriteHTML($style_data, 1); $mpdf->WriteHTML($frontmatter_data, 2); $mpdf->WriteHTML($html, 2); $mpdf->SetTitle("An Example Title"); $mpdf->SetAuthor("Aco"); $mpdf->SetCreator("Booktype 2.0 and mPDF 6.0"); $mpdf->Output(); ?>
public function setCreator($strCreator) { $this->objPdf->SetCreator($strCreator); }
public function generate_pdf($content, $name = 'download.pdf', $output_type = NULL, $footer = NULL, $margin_bottom = NULL, $header = NULL, $margin_top = NULL, $orientation = 'P') { if (!$output_type) { $output_type = 'D'; } if (!$margin_bottom) { $margin_bottom = 10; } if (!$margin_top) { $margin_top = 10; } $this->load->library('pdf'); $pdf = new mPDF('utf-8', 'A4-' . $orientation, '13', '', 10, 10, $margin_top, $margin_bottom, 9, 9); $pdf->debug = false; $pdf->autoScriptToLang = true; $pdf->autoLangToFont = true; $pdf->SetProtection(array('print')); // You pass 2nd arg for user password (open) and 3rd for owner password (edit) //$pdf->SetProtection(array('print', 'copy')); // Comment above line and uncomment this to allow copying of content $pdf->SetTitle($this->Settings->site_name); $pdf->SetAuthor($this->Settings->site_name); $pdf->SetCreator($this->Settings->site_name); $pdf->SetDisplayMode('fullpage'); $stylesheet = file_get_contents('assets/bs/bootstrap.min.css'); $pdf->WriteHTML($stylesheet, 1); $pdf->WriteHTML($content); if ($header != '') { $pdf->SetHTMLHeader('<p class="text-center">' . $header . '</p>', '', TRUE); } if ($footer != '') { $pdf->SetHTMLFooter('<p class="text-center">' . $footer . '</p>', '', TRUE); } //$pdf->SetHeader($this->Settings->site_name.'||{PAGENO}', '', TRUE); // For simple text header //$pdf->SetFooter($this->Settings->site_name.'||{PAGENO}', '', TRUE); // For simple text footer if ($output_type == 'S') { $file_content = $pdf->Output('', 'S'); write_file('assets/uploads/' . $name, $file_content); return 'assets/uploads/' . $name; } else { $pdf->Output($name, $output_type); } }
/** * Save PHPExcel to file * * @param string $pFilename Name of the file to save as * @throws PHPExcel_Writer_Exception */ public function save($pFilename = NULL) { $fileHandle = parent::prepareForSave($pFilename); // Default PDF paper size $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) // Check for paper size and page orientation if (is_null($this->getSheetIndex())) { $orientation = $this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P'; $printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize(); $printMargins = $this->_phpExcel->getSheet(0)->getPageMargins(); } else { $orientation = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P'; $printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); $printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins(); } $this->setOrientation($orientation); // Override Page Orientation if (!is_null($this->getOrientation())) { $orientation = $this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT ? PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT : $this->getOrientation(); } $orientation = strtoupper($orientation); // Override Paper Size if (!is_null($this->getPaperSize())) { $printPaperSize = $this->getPaperSize(); } if (isset(self::$_paperSizes[$printPaperSize])) { $paperSize = self::$_paperSizes[$printPaperSize]; } // Create PDF $pdf = new mPDF(); $ortmp = $orientation; $pdf->_setPageSize(strtoupper($paperSize), $ortmp); $pdf->DefOrientation = $orientation; $pdf->AddPage($orientation); // Document info $pdf->SetTitle($this->_phpExcel->getProperties()->getTitle()); $pdf->SetAuthor($this->_phpExcel->getProperties()->getCreator()); $pdf->SetSubject($this->_phpExcel->getProperties()->getSubject()); $pdf->SetKeywords($this->_phpExcel->getProperties()->getKeywords()); $pdf->SetCreator($this->_phpExcel->getProperties()->getCreator()); $pdf->WriteHTML($this->generateHTMLHeader(FALSE) . $this->generateSheetData() . $this->generateHTMLFooter()); // Write to file fwrite($fileHandle, $pdf->Output('', 'S')); parent::restoreStateAfterSave($fileHandle); }
/** * 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; } }
include "../mpdf-6.1.2/mpdf.php"; $html_data = file_get_contents("body-ar.html"); $style_data = file_get_contents("style-ar.css"); // Create new PDF with font subsetting, 210mm wide, 297mm high $mpdf = new mPDF('s', array(210, 297)); // Make it a double sided document with 4mm bleed $mpdf->mirrorMargins = 1; $mpdf->bleedMargin = 4; // Set right to left text $mpdf->SetDirectionality('rtl'); // Generate the table of contents from H3 elements $mpdf->h2toc = array('H3' => 0); // Write the stylesheet $mpdf->WriteHTML($style_data, 1); // The parameter 1 tells mPDF that this is CSS and not HTML // Write the main text $mpdf->WriteHTML($html_data, 2); // Set the metadata $mpdf->SetTitle("An Example Title"); $mpdf->SetAuthor("Cicero"); $mpdf->SetCreator("mPDF 6.1.2"); $mpdf->SetSubject("Lorem Ipsum"); $mpdf->SetKeywords("Lorem, Ipsum"); // Generate the PDF file $mpdf->Output('arabic.pdf', 'F'); // Stop mPDF exit; ?>
/** * Set PDF Meta Creator. * * @param string $str The page creator * * @return PdfInterface The current instance */ public function setMetaCreator(string $str) : PdfInterface { $this->setProperty('metaCreator', $str); $this->mpdf->SetCreator($this->metaCreator); return $this; }
function email($purchase_id, $to, $cc = NULL, $bcc = NULL, $from_name, $from, $subject, $note) { $data['message'] = validation_errors() ? validation_errors() : $this->session->flashdata('message'); $data['rows'] = $this->inventories_model->getAllInventoryItems($purchase_id); $inv = $this->inventories_model->getInventoryByPurchaseID($purchase_id); $supplier_id = $inv->supplier_id; $data['supplier'] = $this->inventories_model->getSupplierByID($supplier_id); $data['inv'] = $inv; $data['pid'] = $purchase_id; $data['page_title'] = $this->lang->line("inventory"); $html = $this->load->view('view_inventory', $data, TRUE); $this->load->library('MPDF/mpdf'); $mpdf = new mPDF('utf-8', 'A4', '12', '', 10, 10, 10, 10, 9, 9); $mpdf->useOnlyCoreFonts = true; $mpdf->SetProtection(array('print')); $mpdf->SetTitle(SITE_NAME); $mpdf->SetAuthor(SITE_NAME); $mpdf->SetCreator(SITE_NAME); $mpdf->SetDisplayMode('fullpage'); $mpdf->SetAutoFont(); $stylesheet = file_get_contents('assets/css/bootstrap-' . THEME . '.css'); $mpdf->WriteHTML($stylesheet, 1); $search = array("<div class=\"row-fluid\">", "<div class=\"span6\">"); $replace = array("<div style='width: 100%;'>", "<div style='width: 48%; float: left;'>"); $html = str_replace($search, $replace, $html); $name = $this->lang->line("inventory") . "-" . $inv->id . ".pdf"; $mpdf->WriteHTML($html); $mpdf->Output($name, 'F'); if ($note) { $message = html_entity_decode($note) . "<br><hr>" . $html; } else { $message = $html; } $this->load->library('email'); $config['mailtype'] = 'html'; $config['wordwrap'] = TRUE; $this->email->initialize($config); $this->email->from($from, $from_name); $this->email->to($to); if ($cc) { $this->email->cc($cc); } if ($bcc) { $this->email->bcc($bcc); } $this->email->subject($subject); $this->email->message($message); $this->email->attach($name); if ($this->email->send()) { // email sent unlink($name); return true; } else { //email not sent unlink($name); //echo $this->email->print_debugger(); return false; } }
function mpdf_output($wp_content = '', $do_pdf = false, $outputToBrowser = true, $pdfName = '', $templatePath = '') { global $post; $pdf_ofilename = $post->post_name . '.pdf'; if (!empty($pdfName)) { $pdf_filename = $pdfName . '.pdf'; } else { $pdf_filename = $pdf_ofilename; } /** * Allow to override the pdf file name */ $pdf_filename = apply_filters('mpdf_output_pdf_filename', $pdf_filename); /** * Geshi Support */ if (get_option('mpdf_geshi') == true) { require_once dirname(__FILE__) . '/geshi.inc.php'; $wp_content = ParseGeshi($wp_content); } /** * Run the content default filter */ $wp_content = apply_filters('the_content', $wp_content); /** * Run the mpdf filter */ $wp_content = mpdf_filter($wp_content, $do_pdf); if ($do_pdf === false) { echo $wp_content; } else { $cacheDirectory = mpdf_getcachedir(); if (!is_dir($cacheDirectory . 'tmp')) { @mkdir($cacheDirectory . 'tmp'); } define('_MPDF_PATH', dirname(__FILE__) . '/mpdf/'); define('_MPDF_TEMP_PATH', $cacheDirectory . 'tmp/'); define('_MPDF_TTFONTDATAPATH', _MPDF_TEMP_PATH); require_once _MPDF_PATH . 'mpdf.php'; global $pdf_margin_left; global $pdf_margin_right; global $pdf_margin_top; global $pdf_margin_bottom; global $pdf_margin_header; global $pdf_margin_footer; global $pdf_html_header; global $pdf_html_footer; if ($pdf_margin_left !== 0 && $pdf_margin_left == '') { $pdf_margin_left = 15; } if ($pdf_margin_right !== 0 && $pdf_margin_right == '') { $pdf_margin_right = 15; } if ($pdf_margin_top !== 0 && $pdf_margin_top == '') { $pdf_margin_top = 16; } if ($pdf_margin_bottom !== 0 && $pdf_margin_bottom == '') { $pdf_margin_bottom = 16; } if ($pdf_margin_header !== 0 && $pdf_margin_header == '') { $pdf_margin_header = 9; } if ($pdf_margin_footer !== 0 && $pdf_margin_footer == '') { $pdf_margin_footer = 9; } if (empty($pdf_html_header)) { $pdf_html_header = false; } if (empty($pdf_html_footer)) { $pdf_html_footer = false; } global $pdf_orientation; if ($pdf_orientation == '') { $pdf_orientation = 'P'; } $cp = 'utf-8'; if (get_option('mpdf_code_page') != '') { $cp = get_option('mpdf_code_page'); } $mpdf = new mPDF($cp, 'A4', '', '', $pdf_margin_left, $pdf_margin_right, $pdf_margin_top, $pdf_margin_bottom, $pdf_margin_header, $pdf_margin_footer, $pdf_orientation); $mpdf->SetUserRights(); $mpdf->title2annots = false; //$mpdf->annotMargin = 12; $mpdf->use_embeddedfonts_1252 = true; // false is default $mpdf->SetBasePath($templatePath); //Set PDF Template if it's set global $pdf_template_pdfpage; global $pdf_template_pdfpage_page; global $pdf_template_pdfdoc; if (isset($pdf_template_pdfdoc) && $pdf_template_pdfdoc != '') { $mpdf->SetImportUse(); $mpdf->SetDocTemplate($templatePath . $pdf_template_pdfdoc, true); } else { if (isset($pdf_template_pdfpage) && $pdf_template_pdfpage != '' && isset($pdf_template_pdfpage_page) && is_numeric($pdf_template_pdfpage_page)) { $mpdf->SetImportUse(); $pagecount = $mpdf->SetSourceFile($templatePath . $pdf_template_pdfpage); if ($pdf_template_pdfpage_page < 1) { $pdf_template_pdfpage_page = 1; } else { if ($pdf_template_pdfpage_page > $pagecount) { $pdf_template_pdfpage_page = $pagecount; } } $tplId = $mpdf->ImportPage($pdf_template_pdfpage_page); $mpdf->UseTemplate($tplId); } } $user_info = get_userdata($post->post_author); $mpdf->SetAuthor($user_info->first_name . ' ' . $user_info->last_name . ' (' . $user_info->user_login . ')'); $mpdf->SetCreator('wp-mpdf'); //The Header and Footer global $pdf_footer; global $pdf_header; $mpdf->startPageNums(); // Required for TOC use after AddPage(), and to use Headers and Footers if ($pdf_html_header) { $mpdf->SetHTMLHeader($pdf_header); } else { $mpdf->setHeader($pdf_header); } if ($pdf_html_footer) { $mpdf->SetHTMLFooter($pdf_footer); } else { $mpdf->setFooter($pdf_footer); } if (get_option('mpdf_theme') != '' && file_exists($templatePath . get_option('mpdf_theme') . '.css')) { //Read the StyleCSS $tmpCSS = file_get_contents($templatePath . get_option('mpdf_theme') . '.css'); $mpdf->WriteHTML($tmpCSS, 1); } //My Filters require_once dirname(__FILE__) . '/myfilters.inc.php'; $wp_content = mpdf_myfilters($wp_content); if (get_option('mpdf_debug') == true) { if (!is_dir(dirname(__FILE__) . '/debug/')) { mkdir(dirname(__FILE__) . '/debug/'); } file_put_contents(dirname(__FILE__) . '/debug/' . get_option('mpdf_theme') . '_' . $pdf_ofilename . '.html', $wp_content); } //die($wp_content); $mpdf->WriteHTML($wp_content); /** * Allow to process the pdf by an 3th party plugin */ do_action('mpdf_output', $mpdf, $pdf_filename); if (get_option('mpdf_caching') == true) { file_put_contents(mpdf_getcachedir() . get_option('mpdf_theme') . '_' . $pdf_ofilename . '.cache', $post->post_modified_gmt); $mpdf->Output(mpdf_getcachedir() . get_option('mpdf_theme') . '_' . $pdf_ofilename, 'F'); if ($outputToBrowser == true) { $mpdf->Output($pdf_filename, 'I'); } } else { if ($outputToBrowser == true) { $mpdf->Output($pdf_filename, 'I'); } } } }
$individual = file_get_contents("individual-contributor-license-agreement.html"); $style_data = file_get_contents("contributor.css"); $entity = file_get_contents("entity-contributor-license-agreement.html"); // Create new PDF with font subsetting, 210mm wide, 297mm high $mpdf = new mPDF('s', array(210, 297)); // Make it DOUBLE SIDED document $mpdf->mirrorMargins = 1; $mpdf->WriteHTML($style_data, 1); $mpdf->WriteHTML($individual, 2); $mpdf->SetTitle("Booktype GmbH Individual Contributor License Agreement"); $mpdf->SetAuthor("Booktype GmbH"); $mpdf->SetCreator("mPDF 6.0"); $mpdf->SetSubject("Booktype Contributor Agreements"); $mpdf->SetKeywords("Booktype, AGPL, GitHub"); $mpdf->Output("individual-contributor-license-agreement.pdf", 'F'); // Create new PDF with font subsetting, 210mm wide, 297mm high $mpdf = new mPDF('s', array(210, 297)); // Make it DOUBLE SIDED document $mpdf->mirrorMargins = 1; $mpdf->WriteHTML($style_data, 1); $mpdf->WriteHTML($entity, 2); $mpdf->SetTitle("Booktype GmbH Entity Contributor License Agreement"); $mpdf->SetAuthor("Booktype GmbH"); $mpdf->SetCreator("mPDF 6.0"); $mpdf->SetSubject("Booktype Contributor Agreements"); $mpdf->SetKeywords("Booktype, AGPL, GitHub"); $mpdf->Output("entity-contributor-license-agreement.pdf", 'F'); ?>
function pdf_echo($filename = "") { global $__pdf_html, $__pdf_orientation, $__pdf_wm_text, $__pdf_wm_img, $__pdg_pgn_pos, $__pdf_title, $__pdf_subject, $__pdf_author, $__pdf_creator, $__pdf_keywords, $__pdf_wm_talpha, $__pdf_wm_font, $__pdf_wm_ialpha, $__pdf_pgn_text, $__pdf_pgn_pos, $__pdf_pgn_oalign, $__pdf_pgn_ealign, $__pdf_pgn_show, $__pdf_pgn_fcolor, $__pdf_pgn_ftype, $__pdf_pgn_fsize, $__pdf_pgn_fstyle, $__pdf_pgn_lstyle, $__pdf_pgn_lwidth, $__pdf_pgn_lcolor, $__pdf_pgmargin_l, $__pdf_pgmargin_r, $__pdf_pgmargin_t, $__pdf_pgmargin_b, $__pdf_pgmargin_h, $__pdf_pgmargin_f; require_once dirname(__FILE__) . "/__RES__/mpdf.php"; $pdf = new mPDF("th"); $pdf->useOddEven = 1; if ($__pdf_pgn_show) { $dv1 = "<div style=\"{$__pdf_pgn_fcolor};width:auto;text-align:"; $dv2 = ";{$__pdf_pgn_ftype}{$__pdf_pgn_fsize}{$__pdf_pgn_fstyle}"; $dv3 = "style:{$__pdf_pgn_lstyle};"; $dv4 = "width:{$__pdf_pgn_lwidth};"; $dv5 = "color:{$__pdf_pgn_lcolor};"; $dv6 = "\">{$__pdf_pgn_text}</div>"; if ($__pdf_pgn_pos == "TOP") { $align = $__pdf_pgn_oalign; $border = "border-bottom-"; $pgh_o = "{$dv1}{$align}{$dv2}{$border}{$dv3}{$border}{$dv4}{$border}{$dv5}{$dv6}"; $pdf->DefHTMLHeaderByName("ho", $pgh_o); $align = $__pdf_pgn_ealign; $pgh_e = "{$dv1}{$align}{$dv2}{$border}{$dv3}{$border}{$dv4}{$border}{$dv5}{$dv6}"; $pdf->DefHTMLHeaderByName("he", $pgh_e); $pdf->AddPage($__pdf_orientation, '', '', '', '', $__pdf_pgmargin_l, $__pdf_pgmargin_r, $__pdf_pgmargin_t, $__pdf_pgmargin_b, $__pdf_pgmargin_h, $__pdf_pgmargin_f, 'html_ho', 'html_he', '', '', 1, 1, 0, 0); } else { if ($__pdf_pgn_pos == "BOTTOM") { $align = $__pdf_pgn_oalign; $border = "border-top-"; $pgf_o = "{$dv1}{$align}{$dv2}{$border}{$dv3}{$border}{$dv4}{$border}{$dv5}{$dv6}"; $pdf->DefHTMLFooterByName("fo", $pgf_o); $align = $__pdf_pgn_ealign; $pgf_e = "{$dv1}{$align}{$dv2}{$border}{$dv3}{$border}{$dv4}{$border}{$dv5}{$dv6}"; $pdf->DefHTMLFooterByName("fe", $pgf_e); $pdf->AddPage($__pdf_orientation, '', '', '', '', $__pdf_pgmargin_l, $__pdf_pgmargin_r, $__pdf_pgmargin_t, $__pdf_pgmargin_b, $__pdf_pgmargin_h, $__pdf_pgmargin_f, '', '', 'html_fo', 'html_fe', 0, 0, 1, 1); } } } else { $pdf->AddPage($__pdf_orientation); } $pdf->SetTitle($__pdf_title); $pdf->SetAuthor($__pdf_author); $pdf->SetCreator($__pdf_creator); $pdf->SetSubject($__pdf_subject); $pdf->SetKeywords($__pdf_keywords); if ($__pdf_wm_text != "") { $pdf->SetWatermarkText($__pdf_wm_text, $__pdf_wm_talpha); $pdf->showWatermarkText = true; if ($__pdf_wm_font) { $pdf->watermark_font = $__pdf_wm_font; } } if (file_exists($__pdf_wm_img)) { $pdf->SetWatermarkImage($__pdf_wm_img, $__pdf_wm_ialpha); $pdf->showWatermarkImage = true; } $pdf->WriteHTML($__pdf_html); $pdf->Output($filename, $dest); }
function transfer_pdf($transfer_id = NULL) { if ($this->input->get('id')) { $transfer_id = $this->input->get('id'); } $data['message'] = validation_errors() ? validation_errors() : $this->session->flashdata('message'); $data['rows'] = $this->transfers_model->getAllTransferItems($transfer_id); $transfer = $this->transfers_model->getTransferByID($transfer_id); $data['from_warehouse'] = $this->transfers_model->getWarehouseByID($transfer->from_warehouse_id); $data['to_warehouse'] = $this->transfers_model->getWarehouseByID($transfer->to_warehouse_id); $data['transfer'] = $transfer; $data['tid'] = $transfer_id; $data['page_title'] = $this->lang->line("transfer"); $this->load->library('MPDF/mpdf'); $mpdf = new mPDF('utf-8', 'A4', '', '', 15, 15, 25, 25, 9, 9, 'L'); $mpdf->useOnlyCoreFonts = true; // false is default $mpdf->SetProtection(array('print')); $mpdf->SetTitle(SITE_NAME); $mpdf->SetAuthor(SITE_NAME); $mpdf->SetCreator(SITE_NAME); $mpdf->SetDisplayMode('fullpage'); $mpdf->SetAutoFont(); $stylesheet = file_get_contents('assets/css/bootstrap-' . THEME . '.css'); $mpdf->WriteHTML($stylesheet, 1); $html = $this->load->view('view_transfer', $data, TRUE); $name = "Transfer No. " . $transfer_id . ".pdf"; $search = array("<div class=\"row-fluid\">", "<div class=\"span6\">", "<div class=\"span5\">", "<div class=\"span5 offset2\">"); $replace = array("<div style='width: 100%;'>", "<div style='width: 48%; float: left;'>", "<div style='width: 40%; float: left;'>", "<div style='width: 40%; float: right;'>"); $html = str_replace($search, $replace, $html); $html = str_replace($search, $replace, $html); $mpdf->WriteHTML($html); $mpdf->Output($name, 'D'); exit; }