/** * @inheritdoc */ public function __invoke($uri) { $this->assertUriObject($uri); static $modifier; if (!$modifier instanceof Pipeline) { $modifier = new Pipeline([new HostToAscii(), new RemoveDotSegments(), new KsortQuery()]); } return $modifier->process($uri)->withScheme(mb_strtolower($uri->getScheme(), 'UTF-8')); }
/** * Constructor. Additionally, it fetches the SessionInfo object from * the session information * * */ function BlogAction($actionInfo, $request) { $this->Action($actionInfo, $request); // we use the HttpVars package since then we can access the session object // independently wether we're using php ver. < 4.1.0 or not $session = HttpVars::getSession(); $this->_session = $session['SessionInfo']; $this->_config =& Config::getConfig(); $this->_getBlogInfo(); // save the blogid in the session $this->_session->setValue('blogId', $this->_blogInfo->getId()); $this->checkDateParameter(); // initialize the plugin manager $this->_pm =& PluginManager::getPluginManager(); $this->_pm->setBlogInfo($this->_blogInfo); $this->_pm->setUserInfo($this->_userInfo); // locale $this->_locale = $this->_blogInfo->getLocale(); // // security stuff // $pipeline = new Pipeline($request, $this->_blogInfo); $result = $pipeline->process(); // // if the pipeline blocked the request, then we have // to let the user know if (!$result->isValid()) { $message = $this->_locale->tr('error_you_have_been_blocked') . '<br/><br/>'; $message .= $result->getErrorMessage(); $this->_view = new ErrorView($this->_blogInfo, $message); $this->setCommonData(); $this->_view->render(); die; } // update the referrers, if needed $this->_updateReferrer(); $this->articles = new Articles(); }
public function generateHtml2ps_pdf($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $aProperties = array()) { define("MAX_FREE_FRACTION", 1); define('PATH_OUTPUT_FILE_DIRECTORY', PATH_HTML . 'files/' . $_SESSION['APPLICATION'] . '/outdocs/'); G::verifyPath(PATH_OUTPUT_FILE_DIRECTORY, true); require_once PATH_THIRDPARTY . 'html2ps_pdf/config.inc.php'; require_once PATH_THIRDPARTY . 'html2ps_pdf/pipeline.factory.class.php'; parse_config_file(PATH_THIRDPARTY . 'html2ps_pdf/html2ps.config'); $GLOBALS['g_config'] = array('cssmedia' => 'screen', 'media' => 'Letter', 'scalepoints' => false, 'renderimages' => true, 'renderfields' => true, 'renderforms' => false, 'pslevel' => 3, 'renderlinks' => true, 'pagewidth' => 800, 'landscape' => $sLandscape, 'method' => 'fpdf', 'margins' => array('left' => 15, 'right' => 15, 'top' => 15, 'bottom' => 15), 'encoding' => '', 'ps2pdf' => false, 'compress' => true, 'output' => 2, 'pdfversion' => '1.3', 'transparency_workaround' => false, 'imagequality_workaround' => false, 'draw_page_border' => isset($_REQUEST['pageborder']), 'debugbox' => false, 'html2xhtml' => true, 'mode' => 'html', 'smartpagebreak' => true); $GLOBALS['g_config'] = array_merge($GLOBALS['g_config'], $aProperties); $g_media = Media::predefined($GLOBALS['g_config']['media']); $g_media->set_landscape($GLOBALS['g_config']['landscape']); $g_media->set_margins($GLOBALS['g_config']['margins']); $g_media->set_pixels($GLOBALS['g_config']['pagewidth']); if (isset($GLOBALS['g_config']['pdfSecurity'])) { if (isset($GLOBALS['g_config']['pdfSecurity']['openPassword']) && $GLOBALS['g_config']['pdfSecurity']['openPassword'] != "") { $GLOBALS['g_config']['pdfSecurity']['openPassword'] = G::decrypt($GLOBALS['g_config']['pdfSecurity']['openPassword'], $sUID); } if (isset($GLOBALS['g_config']['pdfSecurity']['ownerPassword']) && $GLOBALS['g_config']['pdfSecurity']['ownerPassword'] != "") { $GLOBALS['g_config']['pdfSecurity']['ownerPassword'] = G::decrypt($GLOBALS['g_config']['pdfSecurity']['ownerPassword'], $sUID); } $g_media->set_security($GLOBALS['g_config']['pdfSecurity']); require_once HTML2PS_DIR . 'pdf.fpdf.encryption.php'; } $pipeline = new Pipeline(); if (extension_loaded('curl')) { require_once HTML2PS_DIR . 'fetcher.url.curl.class.php'; $pipeline->fetchers = array(new FetcherURLCurl()); if (isset($proxy)) { if ($proxy != '') { $pipeline->fetchers[0]->set_proxy($proxy); } } } else { require_once HTML2PS_DIR . 'fetcher.url.class.php'; $pipeline->fetchers[] = new FetcherURL(); } $pipeline->data_filters[] = new DataFilterDoctype(); $pipeline->data_filters[] = new DataFilterUTF8($GLOBALS['g_config']['encoding']); if ($GLOBALS['g_config']['html2xhtml']) { $pipeline->data_filters[] = new DataFilterHTML2XHTML(); } else { $pipeline->data_filters[] = new DataFilterXHTML2XHTML(); } $pipeline->parser = new ParserXHTML(); $pipeline->pre_tree_filters = array(); $header_html = ''; $footer_html = ''; $filter = new PreTreeFilterHeaderFooter($header_html, $footer_html); $pipeline->pre_tree_filters[] = $filter; if ($GLOBALS['g_config']['renderfields']) { $pipeline->pre_tree_filters[] = new PreTreeFilterHTML2PSFields(); } if ($GLOBALS['g_config']['method'] === 'ps') { $pipeline->layout_engine = new LayoutEnginePS(); } else { $pipeline->layout_engine = new LayoutEngineDefault(); } $pipeline->post_tree_filters = array(); if ($GLOBALS['g_config']['pslevel'] == 3) { $image_encoder = new PSL3ImageEncoderStream(); } else { $image_encoder = new PSL2ImageEncoderStream(); } switch ($GLOBALS['g_config']['method']) { case 'fastps': if ($GLOBALS['g_config']['pslevel'] == 3) { $pipeline->output_driver = new OutputDriverFastPS($image_encoder); } else { $pipeline->output_driver = new OutputDriverFastPSLevel2($image_encoder); } break; case 'pdflib': $pipeline->output_driver = new OutputDriverPDFLIB16($GLOBALS['g_config']['pdfversion']); break; case 'fpdf': $pipeline->output_driver = new OutputDriverFPDF(); break; case 'png': $pipeline->output_driver = new OutputDriverPNG(); break; case 'pcl': $pipeline->output_driver = new OutputDriverPCL(); break; default: die('Unknown output method'); } if (isset($GLOBALS['g_config']['watermarkhtml'])) { $watermark_text = $GLOBALS['g_config']['watermarkhtml']; } else { $watermark_text = ''; } $pipeline->output_driver->set_watermark($watermark_text); if ($watermark_text != '') { $dispatcher =& $pipeline->getDispatcher(); } if ($GLOBALS['g_config']['debugbox']) { $pipeline->output_driver->set_debug_boxes(true); } if ($GLOBALS['g_config']['draw_page_border']) { $pipeline->output_driver->set_show_page_border(true); } if ($GLOBALS['g_config']['ps2pdf']) { $pipeline->output_filters[] = new OutputFilterPS2PDF($GLOBALS['g_config']['pdfversion']); } if ($GLOBALS['g_config']['compress'] && $GLOBALS['g_config']['method'] == 'fastps') { $pipeline->output_filters[] = new OutputFilterGZip(); } if (!isset($GLOBALS['g_config']['process_mode'])) { $GLOBALS['g_config']['process_mode'] = ''; } if ($GLOBALS['g_config']['process_mode'] == 'batch') { $filename = 'batch'; } else { $filename = $sFilename; } switch ($GLOBALS['g_config']['output']) { case 0: $pipeline->destination = new DestinationBrowser($filename); break; case 1: $pipeline->destination = new DestinationDownload($filename); break; case 2: $pipeline->destination = new DestinationFile($filename); break; } copy($sPath . $sFilename . '.html', PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html'); try { $status = $pipeline->process((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . '/files/' . $_SESSION['APPLICATION'] . '/outdocs/' . $sFilename . '.html', $g_media); copy(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf', $sPath . $sFilename . '.pdf'); unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf'); unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html'); } catch (Exception $e) { if ($e->getMessage() == 'ID_OUTPUT_NOT_GENERATE') { include_once 'classes/model/AppDocument.php'; $dataDocument = explode('_', $sFilename); if (!isset($dataDocument[1])) { $dataDocument[1] = 1; } $oAppDocument = new AppDocument(); $oAppDocument->remove($dataDocument[0], $dataDocument[1]); G::SendTemporalMessage(G::LoadTranslation('ID_OUTPUT_NOT_GENERATE'), 'Error'); } } }
} // 110723, dwildt + // Start the conversion $time = time(); if (get_var('process_mode', $_REQUEST) == 'batch') { $batch = get_var('batch', $_REQUEST); for ($i = 0; $i < count($batch); $i++) { if (trim($batch[$i]) != "") { if (!preg_match("/^https?:/", $batch[$i])) { $batch[$i] = "http://" . $batch[$i]; } } } $status = $pipeline->process_batch($batch, $g_media); } else { $status = $pipeline->process($g_baseurl, $g_media); } // 110723, dwildt + if ($this->b_drs_perform) { $endTime = $this->TT->getDifferenceToStarttime(); t3lib_div::devLog('[INFO/PERFORMANCE] html2ps has finished the conversion: ' . ($endTime - $this->startTime) . ' ms', $this->extKey, 0); } // 110723, dwildt + error_log(sprintf("Processing of '%s' completed in %u seconds", $g_baseurl, time() - $time)); if ($status == null) { print $pipeline->error_message(); error_log("Error in conversion pipeline"); die; } // 110723, dwildt + if ($this->b_drs_perform) {
} function get_base_url() { return ""; } } $media = Media::predefined("A4"); $media->set_landscape(false); $media->set_margins(array('left' => 0, 'right' => 0, 'top' => 0, 'bottom' => 0)); $media->set_pixels(1024); $GLOBALS['g_config'] = array('cssmedia' => 'screen', 'renderimages' => true, 'renderforms' => false, 'renderlinks' => true, 'renderfields' => true, 'mode' => 'html', 'debugbox' => false, 'draw_page_border' => false); $g_px_scale = mm2pt($media->width() - $media->margins['left'] - $media->margins['right']) / $media->pixels; $g_pt_scale = $g_px_scale * 1.43; $pipeline = new Pipeline(); $pipeline->configure($GLOBALS['g_config']); $pipeline->fetchers[] = new MyFetcherLocalFile(); // $pipeline->destination = new MyDestinationFile($pdf); $pipeline->destination = new MyDestinationDownload($pdf); $pipeline->data_filters[] = new DataFilterHTML2XHTML(); $pipeline->pre_tree_filters = array(); $header_html = "test"; $footer_html = "test"; $filter = new PreTreeFilterHeaderFooter($header_html, $footer_html); $pipeline->pre_tree_filters[] = $filter; $pipeline->pre_tree_filters[] = new PreTreeFilterHTML2PSFields(); $pipeline->parser = new ParserXHTML(); $pipeline->layout_engine = new LayoutEngineDefault(); $pipeline->output_driver = new OutputDriverFPDF($media); $pipeline->process('', $media); } convert_to_pdf("test");
parse_config_file(dirname(__FILE__) . '/../html2ps.config'); $g_config = array('cssmedia' => 'screen', 'renderimages' => true, 'renderforms' => true, 'renderlinks' => true, 'mode' => 'html', 'debugbox' => false, 'draw_page_border' => false); require_once dirname(__FILE__) . '/../config.inc.php'; require_once HTML2PS_DIR . 'pipeline.class.php'; require_once HTML2PS_DIR . 'fetcher.url.class.php'; parse_config_file(HTML2PS_DIR . 'html2ps.config'); $g_config = array('cssmedia' => 'screen', 'renderimages' => true, 'renderforms' => false, 'renderlinks' => true, 'mode' => 'html', 'debugbox' => false, 'draw_page_border' => false); $media = Media::predefined('A4'); $media->set_landscape(false); $media->set_margins(array('left' => 0, 'right' => 0, 'top' => 0, 'bottom' => 0)); $media->set_pixels(1024); $g_px_scale = mm2pt($media->width() - $media->margins['left'] - $media->margins['right']) / $media->pixels; $g_pt_scale = $g_px_scale * 1.43; foreach ($urls as $url) { $url_file = str_replace('http://', '', $url); $url_file = str_replace(':', '_', $url_file); $url_file = str_replace('/', '_', $url_file); $url_file = str_replace('.', '_', $url_file); $pipeline = new Pipeline(); $pipeline->configure($g_config); $pipeline->fetchers[] = new FetcherURL(); $pipeline->data_filters[] = new DataFilterHTML2XHTML(); $pipeline->parser = new ParserXHTML(); $pipeline->layout_engine = new LayoutEngineDefault(); $pipeline->output_driver = new OutputDriverFPDF($media); $pipeline->destination = new DestinationFile($url_file); if (!file_exists(dirname(__FILE__) . '/../out/' . $url_file . '.pdf')) { print $url . "\n"; $pipeline->process($url, $media); } }
<?php require_once 'pipeline.class.php'; parse_config_file('html2ps.config'); $g_config = array('cssmedia' => 'screen', 'renderimages' => true, 'renderforms' => false, 'renderlinks' => true, 'mode' => 'html', 'debugbox' => false, 'draw_page_border' => false); $media = Media::predefined('A4'); $media->set_landscape(false); $media->set_margins(array('left' => 0, 'right' => 0, 'top' => 0, 'bottom' => 0)); $media->set_pixels(1024); $g_px_scale = mm2pt($media->width() - $media->margins['left'] - $media->margins['right']) / $media->pixels; $g_pt_scale = $g_px_scale * 1.43; $pipeline = new Pipeline(); $pipeline->fetchers[] = new FetcherURL(); $pipeline->data_filters[] = new DataFilterHTML2XHTML(); $pipeline->parser = new ParserXHTML(); $pipeline->layout_engine = new LayoutEngineDefault(); $pipeline->output_driver = new OutputDriverFPDF($media); $pipeline->destination = new DestinationFile(null); $pipeline->process('http://localhost:81/testing/ww.html', $media);
$pipeline->pre_tree_filters[] = new PreTreeFilterHTML2PSFields(); // *** Layout engine $pipeline->layout_engine = new LayoutEngineDefault(); // *** Post-tree filters $pipeline->post_tree_filters = array(); // *** Output driver $pipeline->output_driver = new OutputDriverFPDF(); // *** Destination $pipeline->destination = new DestinationDownload($fo); // *** Install event handler $dispatcher =& $pipeline->getDispatcher(); $dispatcher->add_observer('before-page', 'visible_hidden_by_id'); /*****************************************************************************/ /** Main */ // ** Generate PDF file $status = $pipeline->process($fi, $g_media); if ($status == null) { print $pipeline->error_message(); syslog(LOG_ERR, "PHP: Error in conversion pipeline"); die; } /*****************************************************************************/ /** Functions */ // ** Event handler function visible_hidden_by_id($params) { global $POST_PROCESSING_DIRECTIVES; // ** Read page number $exppag = $params["pipeline"]->output_driver->get_expected_pages(); $pageno = $params["pageno"] + 1; // Plus 1 because in "before-page" pageno isn't yet incremented
function validate() { // before we do anything, let's find out the blogId and if there isn't any, quit $this->_getBlogInfo(); if ($this->_blogInfo == false) { // return 404 not found because the blog id is not correct! $this->_view = new ResourceServerView(); $this->_view->addHeaderResponse("HTTP/1.1 404 Not Found"); $this->_view->addHeaderResponse("Status: 404 Not Found"); $this->_view->addHeaderResponse("X-pLog-Error: Blog {$resId} is not correct"); return false; } // // security stuff // // :KLUDGE: the problem with the security Pipeline and the PluginManager in this // action is that we need to reimplement the whole stuff because... this action does not // inherit from BlogAction and therefore nobody is doing these things for us! I don't really // like to do it like this but while I think of a better way, let's leave like it // $pipeline = new Pipeline($this->_request, $this->_blogInfo); $result = $pipeline->process(); // if the pipeline blocked the request, then we have to let the user know and quit // processing if (!$result->isValid()) { $this->_view = new ResourceServerView(); $this->_view->addHeaderResponse("HTTP/1.1 403 Forbidden"); $this->_view->addHeaderResponse("Status: 403 Forbidden"); $this->_view->addHeaderResponse("X-pLog-Error: Access is blocked"); return false; } // now if the blog id was correct, then we can proceed to get the rest of the parameters $this->_resName = $this->_request->getValue("resource"); $this->_resId = $this->_request->getValue("resId"); $this->_albumId = $this->_request->getValue("albumId"); $this->_albumName = $this->_request->getValue("albumName"); $this->_mode = $this->_request->getValue("mode"); // check if we need to load the album to figure out the correct album id // because we got an album name instead of an album id if (!empty($this->_albumId) || !empty($this->_albumName)) { if ($this->_albumName) { $albums = new GalleryAlbums(); $album = $albums->getAlbumByName($this->_albumName); if (!$album) { $this->_view = new ResourceServerView(); $this->_view->addHeaderResponse("HTTP/1.1 404 Not Found"); $this->_view->addHeaderResponse("Status: 404 Not Found"); $this->_view->addHeaderResponse("X-pLog-Error: Album {$albumId} not found"); return false; } $this->_albumId = $album->getId(); } } return true; }
global $g_px_scale; $g_px_scale = mm2pt($g_media->width() - $g_media->margins['left'] - $g_media->margins['right']) / $g_media->pixels; global $g_pt_scale; $g_pt_scale = $g_px_scale * 1.43; // for fetching the css files require_once HTML2PS_DIR . 'fetcher.local.class.php'; $pipeline->fetchers[] = new FetcherLocalfile($sourcefn); //require_once(HTML2PS_DIR.'fetcher.url.curl.class.php'); //$pipeline->fetchers[] = new FetcherUrlCurl(); #toc! if ($_CONFIG['CreateTOC']) { $pipeline->add_feature('toc', array('location', 'before')); } $header_html = file_get_contents($headerFile); $footer_html = file_get_contents($footerFile); $pipeline->pre_tree_filters = array(); if ($header_html != '' || $footer_html != '') { $filter = new PreTreeFilterHeaderFooter($header_html, $footer_html); $pipeline->pre_tree_filters[] = $filter; } $image_encoder = new PSL3ImageEncoderStream(); $pipeline->data_filters[] = new DataFilterDoctype(); $pipeline->data_filters[] = new DataFilterUTF8('iso-8859-15'); $pipeline->data_filters[] = new DataFilterHTML2XHTML(); $pipeline->parser = new ParserXHTML(); $pipeline->post_tree_filters = array(); $pipeline->layout_engine = new LayoutEngineDefault(); $pipeline->output_driver = new OutputDriverFPDF(); $pipeline->destination = new DestinationFile($destfn, "", $outputdir); $pipeline->process($sourcefn, $g_media); ob_end_clean();
<?php require_once dirname(__FILE__) . '/../config.inc.php'; require_once HTML2PS_DIR . 'pipeline.class.php'; require_once HTML2PS_DIR . 'fetcher.url.class.php'; parse_config_file(HTML2PS_DIR . 'html2ps.config'); $g_config = array('cssmedia' => 'screen', 'renderimages' => true, 'renderforms' => false, 'renderlinks' => true, 'mode' => 'html', 'debugbox' => false, 'draw_page_border' => false); $media = Media::predefined('A4'); $media->set_landscape(false); $media->set_margins(array('left' => 0, 'right' => 0, 'top' => 0, 'bottom' => 0)); $media->set_pixels(1024); $g_px_scale = mm2pt($media->width() - $media->margins['left'] - $media->margins['right']) / $media->pixels; $g_pt_scale = $g_px_scale * 1.43; $pipeline = new Pipeline(); $pipeline->configure($g_config); $pipeline->fetchers[] = new FetcherURL(); $pipeline->data_filters[] = new DataFilterHTML2XHTML(); $pipeline->parser = new ParserXHTML(); $pipeline->layout_engine = new LayoutEngineDefault(); $pipeline->output_driver = new OutputDriverFPDF($media); $pipeline->destination = new DestinationFile(null); $pipeline->process('http://tests.office/html2ps/sample.html', $media);
public function generate($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $sTypeDocToGener = 'BOTH', $aProperties = array()) { if ($sUID != '' && is_array($aFields) && $sPath != '') { $sContent = G::unhtmlentities($sContent); $iAux = 0; $iOcurrences = preg_match_all('/\\@(?:([\\>])([a-zA-Z\\_]\\w*)|([a-zA-Z\\_][\\w\\-\\>\\:]*)\\(((?:[^\\\\\\)]*(?:[\\\\][\\w\\W])?)*)\\))((?:\\s*\\[[\'"]?\\w+[\'"]?\\])+)?/', $sContent, $aMatch, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); if ($iOcurrences) { for ($i = 0; $i < $iOcurrences; $i++) { preg_match_all('/@>' . $aMatch[2][$i][0] . '([\\w\\W]*)' . '@<' . $aMatch[2][$i][0] . '/', $sContent, $aMatch2, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); $sGridName = $aMatch[2][$i][0]; $sStringToRepeat = $aMatch2[1][0][0]; if (isset($aFields[$sGridName])) { if (is_array($aFields[$sGridName])) { $sAux = ''; foreach ($aFields[$sGridName] as $aRow) { foreach ($aRow as $sKey => $vValue) { if (!is_array($vValue)) { $aRow[$sKey] = nl2br($aRow[$sKey]); } } $sAux .= G::replaceDataField($sStringToRepeat, $aRow); } } } $sContent = str_replace('@>' . $sGridName . $sStringToRepeat . '@<' . $sGridName, $sAux, $sContent); } } foreach ($aFields as $sKey => $vValue) { if (!is_array($vValue)) { $aFields[$sKey] = nl2br($aFields[$sKey]); } } $sContent = G::replaceDataField($sContent, $aFields); G::verifyPath($sPath, true); /* Start - Create .doc */ $oFile = fopen($sPath . $sFilename . '.doc', 'wb'); $size = array(); $size["Letter"] = "216mm 279mm"; $size["Legal"] = "216mm 357mm"; $size["Executive"] = "184mm 267mm"; $size["B5"] = "182mm 257mm"; $size["Folio"] = "216mm 330mm"; $size["A0Oversize"] = "882mm 1247mm"; $size["A0"] = "841mm 1189mm"; $size["A1"] = "594mm 841mm"; $size["A2"] = "420mm 594mm"; $size["A3"] = "297mm 420mm"; $size["A4"] = "210mm 297mm"; $size["A5"] = "148mm 210mm"; $size["A6"] = "105mm 148mm"; $size["A7"] = "74mm 105mm"; $size["A8"] = "52mm 74mm"; $size["A9"] = "37mm 52mm"; $size["A10"] = "26mm 37mm"; $size["Screenshot640"] = "640mm 480mm"; $size["Screenshot800"] = "800mm 600mm"; $size["Screenshot1024"] = "1024mm 768mm"; $sizeLandscape["Letter"] = "279mm 216mm"; $sizeLandscape["Legal"] = "357mm 216mm"; $sizeLandscape["Executive"] = "267mm 184mm"; $sizeLandscape["B5"] = "257mm 182mm"; $sizeLandscape["Folio"] = "330mm 216mm"; $sizeLandscape["A0Oversize"] = "1247mm 882mm"; $sizeLandscape["A0"] = "1189mm 841mm"; $sizeLandscape["A1"] = "841mm 594mm"; $sizeLandscape["A2"] = "594mm 420mm"; $sizeLandscape["A3"] = "420mm 297mm"; $sizeLandscape["A4"] = "297mm 210mm"; $sizeLandscape["A5"] = "210mm 148mm"; $sizeLandscape["A6"] = "148mm 105mm"; $sizeLandscape["A7"] = "105mm 74mm"; $sizeLandscape["A8"] = "74mm 52mm"; $sizeLandscape["A9"] = "52mm 37mm"; $sizeLandscape["A10"] = "37mm 26mm"; $sizeLandscape["Screenshot640"] = "480mm 640mm"; $sizeLandscape["Screenshot800"] = "600mm 800mm"; $sizeLandscape["Screenshot1024"] = "768mm 1024mm"; if (!isset($aProperties['media'])) { $aProperties['media'] = 'Letter'; } if ($sLandscape) { $media = $sizeLandscape[$aProperties['media']]; } else { $media = $size[$aProperties['media']]; } $marginLeft = '15'; if (isset($aProperties['margins']['left'])) { $marginLeft = $aProperties['margins']['left']; } $marginRight = '15'; if (isset($aProperties['margins']['right'])) { $marginRight = $aProperties['margins']['right']; } $marginTop = '15'; if (isset($aProperties['margins']['top'])) { $marginTop = $aProperties['margins']['top']; } $marginBottom = '15'; if (isset($aProperties['margins']['bottom'])) { $marginBottom = $aProperties['margins']['bottom']; } fwrite($oFile, '<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=Content-Type content="text/html; charset=utf-8"> <meta name=ProgId content=Word.Document> <meta name=Generator content="Microsoft Word 9"> <meta name=Originator content="Microsoft Word 9"> <!--[if !mso]> <style> v\\:* {behavior:url(#default#VML);} o\\:* {behavior:url(#default#VML);} w\\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <![endif]--> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Print</w:View> <w:DoNotHyphenateCaps/> <w:PunctuationKerning/> <w:DrawingGridHorizontalSpacing>9.35 pt</w:DrawingGridHorizontalSpacing> <w:DrawingGridVerticalSpacing>9.35 pt</w:DrawingGridVerticalSpacing> </w:WordDocument> </xml><![endif]--> <style> <!-- @page WordSection1 {size:' . $media . '; margin-left:' . $marginLeft . 'mm; margin-right:' . $marginRight . 'mm; margin-bottom:' . $marginBottom . 'mm; margin-top:' . $marginTop . 'mm; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} --> </style> </head> <body> <div class=WordSection1>'); fwrite($oFile, $sContent); fwrite($oFile, "\n</div></body></html>\n\n"); fclose($oFile); /* End - Create .doc */ if ($sTypeDocToGener == 'BOTH' || $sTypeDocToGener == 'PDF') { /* Start - Create .pdf */ $oFile = fopen($sPath . $sFilename . '.html', 'wb'); fwrite($oFile, $sContent); fclose($oFile); define('PATH_OUTPUT_FILE_DIRECTORY', PATH_HTML . 'files/' . $_SESSION['APPLICATION'] . '/outdocs/'); G::verifyPath(PATH_OUTPUT_FILE_DIRECTORY, true); require_once PATH_THIRDPARTY . 'html2ps_pdf/config.inc.php'; require_once PATH_THIRDPARTY . 'html2ps_pdf/pipeline.factory.class.php'; parse_config_file(PATH_THIRDPARTY . 'html2ps_pdf/html2ps.config'); $GLOBALS['g_config'] = array('cssmedia' => 'screen', 'media' => 'Letter', 'scalepoints' => false, 'renderimages' => true, 'renderfields' => true, 'renderforms' => false, 'pslevel' => 3, 'renderlinks' => true, 'pagewidth' => 800, 'landscape' => $sLandscape, 'method' => 'fpdf', 'margins' => array('left' => 15, 'right' => 15, 'top' => 15, 'bottom' => 15), 'encoding' => '', 'ps2pdf' => false, 'compress' => false, 'output' => 2, 'pdfversion' => '1.3', 'transparency_workaround' => false, 'imagequality_workaround' => false, 'draw_page_border' => isset($_REQUEST['pageborder']), 'debugbox' => false, 'html2xhtml' => true, 'mode' => 'html', 'smartpagebreak' => true); $GLOBALS['g_config'] = array_merge($GLOBALS['g_config'], $aProperties); $g_media = Media::predefined($GLOBALS['g_config']['media']); $g_media->set_landscape($GLOBALS['g_config']['landscape']); $g_media->set_margins($GLOBALS['g_config']['margins']); $g_media->set_pixels($GLOBALS['g_config']['pagewidth']); if (isset($GLOBALS['g_config']['pdfSecurity'])) { if (isset($GLOBALS['g_config']['pdfSecurity']['openPassword']) && $GLOBALS['g_config']['pdfSecurity']['openPassword'] != "") { $GLOBALS['g_config']['pdfSecurity']['openPassword'] = G::decrypt($GLOBALS['g_config']['pdfSecurity']['openPassword'], $sUID); } if (isset($GLOBALS['g_config']['pdfSecurity']['ownerPassword']) && $GLOBALS['g_config']['pdfSecurity']['ownerPassword'] != "") { $GLOBALS['g_config']['pdfSecurity']['ownerPassword'] = G::decrypt($GLOBALS['g_config']['pdfSecurity']['ownerPassword'], $sUID); } $g_media->set_security($GLOBALS['g_config']['pdfSecurity']); require_once HTML2PS_DIR . 'pdf.fpdf.encryption.php'; } $pipeline = new Pipeline(); if (extension_loaded('curl')) { require_once HTML2PS_DIR . 'fetcher.url.curl.class.php'; $pipeline->fetchers = array(new FetcherURLCurl()); if (isset($proxy)) { if ($proxy != '') { $pipeline->fetchers[0]->set_proxy($proxy); } } } else { require_once HTML2PS_DIR . 'fetcher.url.class.php'; $pipeline->fetchers[] = new FetcherURL(); } $pipeline->data_filters[] = new DataFilterDoctype(); $pipeline->data_filters[] = new DataFilterUTF8($GLOBALS['g_config']['encoding']); if ($GLOBALS['g_config']['html2xhtml']) { $pipeline->data_filters[] = new DataFilterHTML2XHTML(); } else { $pipeline->data_filters[] = new DataFilterXHTML2XHTML(); } $pipeline->parser = new ParserXHTML(); $pipeline->pre_tree_filters = array(); $header_html = ''; $footer_html = ''; $filter = new PreTreeFilterHeaderFooter($header_html, $footer_html); $pipeline->pre_tree_filters[] = $filter; if ($GLOBALS['g_config']['renderfields']) { $pipeline->pre_tree_filters[] = new PreTreeFilterHTML2PSFields(); } if ($GLOBALS['g_config']['method'] === 'ps') { $pipeline->layout_engine = new LayoutEnginePS(); } else { $pipeline->layout_engine = new LayoutEngineDefault(); } $pipeline->post_tree_filters = array(); if ($GLOBALS['g_config']['pslevel'] == 3) { $image_encoder = new PSL3ImageEncoderStream(); } else { $image_encoder = new PSL2ImageEncoderStream(); } switch ($GLOBALS['g_config']['method']) { case 'fastps': if ($GLOBALS['g_config']['pslevel'] == 3) { $pipeline->output_driver = new OutputDriverFastPS($image_encoder); } else { $pipeline->output_driver = new OutputDriverFastPSLevel2($image_encoder); } break; case 'pdflib': $pipeline->output_driver = new OutputDriverPDFLIB16($GLOBALS['g_config']['pdfversion']); break; case 'fpdf': $pipeline->output_driver = new OutputDriverFPDF(); break; case 'png': $pipeline->output_driver = new OutputDriverPNG(); break; case 'pcl': $pipeline->output_driver = new OutputDriverPCL(); break; default: die('Unknown output method'); } if (isset($GLOBALS['g_config']['watermarkhtml'])) { $watermark_text = $GLOBALS['g_config']['watermarkhtml']; } else { $watermark_text = ''; } $pipeline->output_driver->set_watermark($watermark_text); if ($watermark_text != '') { $dispatcher =& $pipeline->getDispatcher(); } if ($GLOBALS['g_config']['debugbox']) { $pipeline->output_driver->set_debug_boxes(true); } if ($GLOBALS['g_config']['draw_page_border']) { $pipeline->output_driver->set_show_page_border(true); } if ($GLOBALS['g_config']['ps2pdf']) { $pipeline->output_filters[] = new OutputFilterPS2PDF($GLOBALS['g_config']['pdfversion']); } if ($GLOBALS['g_config']['compress'] && $GLOBALS['g_config']['method'] == 'fastps') { $pipeline->output_filters[] = new OutputFilterGZip(); } if (!isset($GLOBALS['g_config']['process_mode'])) { $GLOBALS['g_config']['process_mode'] = ''; } if ($GLOBALS['g_config']['process_mode'] == 'batch') { $filename = 'batch'; } else { $filename = $sFilename; } switch ($GLOBALS['g_config']['output']) { case 0: $pipeline->destination = new DestinationBrowser($filename); break; case 1: $pipeline->destination = new DestinationDownload($filename); break; case 2: $pipeline->destination = new DestinationFile($filename); break; } copy($sPath . $sFilename . '.html', PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html'); $status = $pipeline->process((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . '/files/' . $_SESSION['APPLICATION'] . '/outdocs/' . $sFilename . '.html', $g_media); copy(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf', $sPath . $sFilename . '.pdf'); unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.pdf'); unlink(PATH_OUTPUT_FILE_DIRECTORY . $sFilename . '.html'); } //end if $sTypeDocToGener /* End - Create .pdf */ } else { return PEAR::raiseError(null, G_ERROR_USER_UID, null, null, 'You tried to call to a generate method without send the Output Document UID, fields to use and the file path!', 'G_Error', true); } }
function generate($config) { global $fpdf_charwidths; global $g_baseurl; global $g_border; global $g_box_uid; global $g_boxes; global $g_colors; global $g_config; global $g_css; global $g_css_defaults_obj; global $g_css_handlers; global $g_css_index; global $g_css_obj; global $g_font_family; global $g_font_resolver; global $g_font_resolver_pdf; global $g_font_size; global $g_frame_level; global $g_html_entities; global $g_image_cache; global $g_last_assigned_font_id; global $g_list_item_nums; global $g_manager_encodings; global $g_media; global $g_predefined_media; global $g_pt_scale; global $g_px_scale; global $g_stylesheet_title; global $g_table_border; global $g_tag_attrs; global $g_unicode_glyphs; global $g_utf8_converters; global $g_utf8_to_encodings_mapping_pdf; global $g_valign; global $psdata; global $g_font_style; global $g_font_family; global $g_font_weight; global $g_font_size; global $g_line_height; // global $base_font_size; $context = pobject::getContext(); $me = $context["arCurrentObject"]; require_once HTML2PS_LOCATION . 'pipeline.factory.class.php'; set_time_limit(600); check_requirements(); $g_baseurl = trim($config['URL']); if ($g_baseurl === "") { $me->error = "Please specify URL to process!"; return false; } // Add HTTP protocol if none specified if (!preg_match("/^https?:/", $g_baseurl)) { $g_baseurl = 'http://' . $g_baseurl; } $g_css_index = 0; // Title of styleshee to use (empty if no preferences are set) $g_stylesheet_title = ""; $g_config = array('cssmedia' => isset($config['cssmedia']) ? $config['cssmedia'] : "screen", 'convert' => isset($config['convert']), 'media' => isset($config['media']) ? $config['media'] : "A4", 'scalepoints' => isset($config['scalepoints']), 'renderimages' => isset($config['renderimages']), 'renderfields' => isset($config['renderfields']), 'renderforms' => isset($config['renderforms']), 'pslevel' => isset($config['pslevel']) ? $config['pslevel'] : 2, 'renderlinks' => isset($config['renderlinks']), 'pagewidth' => isset($config['pixels']) ? (int) $config['pixels'] : 800, 'landscape' => isset($config['landscape']), 'method' => isset($config['method']) ? $config['method'] : "fpdf", 'margins' => array('left' => isset($config['leftmargin']) ? (int) $config['leftmargin'] : 0, 'right' => isset($config['rightmargin']) ? (int) $config['rightmargin'] : 0, 'top' => isset($config['topmargin']) ? (int) $config['topmargin'] : 0, 'bottom' => isset($config['bottommargin']) ? (int) $config['bottommargin'] : 0), 'encoding' => isset($config['encoding']) ? $config['encoding'] : "", 'ps2pdf' => isset($config['ps2pdf']) ? $config['ps2pdf'] : 0, 'compress' => isset($config['compress']) ? $config['compress'] : 0, 'output' => isset($config['output']) ? $config['output'] : 0, 'pdfversion' => isset($config['pdfversion']) ? $config['pdfversion'] : "1.2", 'transparency_workaround' => isset($config['transparency_workaround']), 'imagequality_workaround' => isset($config['imagequality_workaround']), 'draw_page_border' => isset($config['pageborder']), 'debugbox' => isset($config['debugbox']), 'watermarkhtml' => isset($config['watermarkhtml']), 'smartpagebreak' => isset($config['smartpagebreak']), 'html2xhtml' => !isset($config['html2xhtml']), 'mode' => 'html'); // ========== Entry point parse_config_file(HTML2PS_LOCATION . './.html2ps.config'); // validate input data if ($g_config['pagewidth'] == 0) { $me->error = "Please specify non-zero value for the pixel width!"; return false; } // begin processing $g_media = Media::predefined($g_config['media']); $g_media->set_landscape($g_config['landscape']); $g_media->set_margins($g_config['margins']); $g_media->set_pixels($g_config['pagewidth']); $g_px_scale = mm2pt($g_media->width() - $g_media->margins['left'] - $g_media->margins['right']) / $g_media->pixels; if ($g_config['scalepoints']) { $g_pt_scale = $g_px_scale * 1.43; // This is a magic number, just don't touch it, or everything will explode! } else { $g_pt_scale = 1.0; } // Initialize the coversion pipeline $pipeline = new Pipeline(); // Configure the fetchers $pipeline->fetchers[] = new FetcherURL(); // Configure the data filters $pipeline->data_filters[] = new DataFilterDoctype(); $pipeline->data_filters[] = new DataFilterUTF8($g_config['encoding']); if ($g_config['html2xhtml']) { $pipeline->data_filters[] = new DataFilterHTML2XHTML(); } else { $pipeline->data_filters[] = new DataFilterXHTML2XHTML(); } $pipeline->parser = new ParserXHTML(); $pipeline->pre_tree_filters = array(); if ($g_config['renderfields']) { $pipeline->pre_tree_filters[] = new PreTreeFilterHTML2PSFields("", "", ""); } if ($g_config['method'] === 'ps') { $pipeline->layout_engine = new LayoutEnginePS(); } else { $pipeline->layout_engine = new LayoutEngineDefault(); } $pipeline->post_tree_filters = array(); // Configure the output format if ($g_config['pslevel'] == 3) { $image_encoder = new PSL3ImageEncoderStream(); } else { $image_encoder = new PSL2ImageEncoderStream(); } switch ($g_config['method']) { case 'ps': $pipeline->output_driver = new OutputDriverPS($g_config['scalepoints'], $g_config['transparency_workaround'], $g_config['imagequality_workaround'], $image_encoder); break; case 'fastps': $pipeline->output_driver = new OutputDriverFastPS($image_encoder); break; case 'pdflib': $pipeline->output_driver = new OutputDriverPDFLIB($g_config['pdfversion']); break; case 'fpdf': $pipeline->output_driver = new OutputDriverFPDF(); break; default: $me->error = "Unknown output method"; return false; } if ($g_config['debugbox']) { $pipeline->output_driver->set_debug_boxes(true); } if ($g_config['draw_page_border']) { $pipeline->output_driver->set_show_page_border(true); } if ($g_config['ps2pdf']) { $pipeline->output_filters[] = new OutputFilterPS2PDF($g_config['pdfversion']); } if ($g_config['compress']) { $pipeline->output_filters[] = new OutputFilterGZip(); } $pipeline->destination = new DestinationBrowser($g_baseurl); $dest_filename = $pipeline->destination->filename_escape($pipeline->destination->get_filename()); ldSetContent("application/pdf"); if (!$me->cached("html2ps_" . md5($dest_filename))) { // Start the conversion $status = $pipeline->process($g_baseurl, $g_media); if ($status == null) { ldSetContent("text/html"); $me->error = "Error in conversion pipeline: " . $pipeline->error_message(); $me->savecache(0); return false; } else { $me->savecache(999); } } return true; }