Esempio n. 1
0
 function parse($value)
 {
     if ($value == '') {
         return null;
     }
     // First attempt to create media with predefined name
     if (preg_match('/^(\\w+)(?:\\s+(portrait|landscape))?$/', $value, $matches)) {
         $name = $matches[1];
         $landscape = isset($matches[2]) && $matches[2] == 'landscape';
         $media =& Media::predefined($name);
         if (is_null($media)) {
             return null;
         }
         return array('size' => array('width' => $media->get_width(), 'height' => $media->get_height()), 'landscape' => $landscape);
     }
     // Second, attempt to create media with predefined size
     $parts = preg_split('/\\s+/', $value);
     $width_str = $parts[0];
     $height_str = isset($parts[1]) ? $parts[1] : $parts[0];
     $width = units2pt($width_str);
     $height = units2pt($height_str);
     if ($width == 0 || $height == 0) {
         return null;
     }
     return array('size' => array('width' => $width / mm2pt(1) / pt2pt(1), 'height' => $height / mm2pt(1) / pt2pt(1)), 'landscape' => false);
 }
Esempio n. 2
0
 function init()
 {
     // Include the class file and create Html2ps instance
     App::import('vendor', 'Html2PsConfig', array('file' => 'html2ps' . DS . 'config.inc.php'));
     App::import('vendor', 'Html2Ps', array('file' => 'html2ps' . DS . 'pipeline.factory.class.php'));
     parse_config_file(APP . 'vendors' . DS . 'html2ps' . DS . 'html2ps.config');
     global $g_config;
     $g_config = array('cssmedia' => 'screen', 'renderimages' => true, 'renderforms' => false, 'renderlinks' => true, 'mode' => 'html', 'debugbox' => false, 'draw_page_border' => false);
     $this->media = Media::predefined('A4');
     $this->media->set_landscape(false);
     $this->media->set_margins(array('left' => 0, 'right' => 0, 'top' => 0, 'bottom' => 0));
     $this->media->set_pixels(1024);
     global $g_px_scale;
     $g_px_scale = mm2pt($this->media->width() - $this->media->margins['left'] - $this->media->margins['right']) / $this->media->pixels;
     global $g_pt_scale;
     $g_pt_scale = $g_pt_scale * 1.43;
     $this->p = PipelineFactory::create_default_pipeline("", "");
     switch ($this->output) {
         case 'download':
             $this->p->destination = new DestinationDownload($this->filename);
             break;
         case 'file':
             $this->p->destination = new DestinationFile($this->filename);
             break;
         default:
             $this->p->destination = new DestinationBrowser($this->filename);
             break;
     }
 }
Esempio n. 3
0
 function runPipeline($html, &$media = null, &$pipeline = null, &$context = null, &$postponed = null)
 {
     parse_config_file('../html2ps.config');
     if (is_null($media)) {
         $media = Media::predefined("A4");
     }
     $pipeline = $this->preparePipeline($media);
     $tree = $this->layoutPipeline($html, $pipeline, $media, $context, $postponed);
     return $tree;
 }
 function runPipeline($html)
 {
     $pipeline = PipelineFactory::create_default_pipeline("", "");
     $pipeline->configure(array('scalepoints' => false));
     $pipeline->fetchers = array(new MyFetcherMemory($html, ""));
     $pipeline->data_filters[] = new DataFilterHTML2XHTML();
     $pipeline->destination = new DestinationFile("test.pdf");
     parse_config_file('../html2ps.config');
     $media = Media::predefined("A5");
     $pipeline->_prepare($media);
     return $pipeline->_layout_item("", $media, 0, $context, $positioned_filter);
 }
 function testCSSParseMarginBoxesTopLeftSize()
 {
     parse_config_file('../html2ps.config');
     $media =& Media::predefined('A4');
     $media->set_margins(array('left' => 10, 'top' => 10, 'right' => 10, 'bottom' => 10));
     $pipeline =& PipelineFactory::create_default_pipeline('utf-8', 'test.pdf');
     $pipeline->_prepare($media);
     $pipeline->_cssState = array(new CSSState(CSS::get()));
     parse_css_atpage_rules('@page { @top-left { content: "TEXT"; } }', $pipeline);
     $boxes = $pipeline->reflow_margin_boxes(1, $media);
     $box =& $boxes[CSS_MARGIN_BOX_SELECTOR_TOP_LEFT];
     $this->assertNotEqual($box->get_width(), 0);
     $expected_width = $pipeline->output_driver->stringwidth('TEXT', 'Times-Roman', 'iso-8859-1', 12);
     $this->assertTrue($box->get_width() >= $expected_width);
     $this->assertEqual($box->get_height(), mm2pt(10));
 }
    function testCheckedRadioPngRender()
    {
        parse_config_file('../html2ps.config');
        $media = Media::predefined("A4");
        $pipeline = $this->preparePipeline($media);
        $pipeline->output_driver = new OutputDriverPng();
        $pipeline->fetchers = array(new MyFetcherMemory('
<html>
<head></head>
<body>
<input type="radio" name="name" checked="checked"/>
</body>
</html>
', ''));
        $tree = $pipeline->_layout_item('', $media, 0, $context, $postponed_filter);
        $this->assertNotNull($tree);
        $pipeline->_show_item($tree, 0, $context, $media, $postponed_filter);
    }
/**
 * Runs the HTML->PDF conversion with default settings
 *
 * Warning: if you have any files (like CSS stylesheets and/or images referenced by this file,
 * use absolute links (like http://my.host/image.gif).
 *
 * @param $path_to_html String path to source html file.
 * @param $path_to_pdf  String path to file to save generated PDF to.
 */
function convert_to_pdf($path_to_html, $path_to_pdf)
{
    $pipeline = PipelineFactory::create_default_pipeline("", "");
    // Override HTML source
    $pipeline->fetchers[] = new MyFetcherLocalFile($path_to_html);
    $filter = new PreTreeFilterHeaderFooter("HEADER", "FOOTER");
    $pipeline->pre_tree_filters[] = $filter;
    // Override destination to local file
    $pipeline->destination = new MyDestinationFile($path_to_pdf);
    $baseurl = "";
    $media = Media::predefined("A4");
    $media->set_landscape(false);
    $media->set_margins(array('left' => 0, 'right' => 0, 'top' => 10, 'bottom' => 10));
    $media->set_pixels(1024);
    global $g_config;
    $g_config = array('cssmedia' => 'screen', 'scalepoints' => '1', 'renderimages' => true, 'renderlinks' => true, 'renderfields' => true, 'renderforms' => false, 'mode' => 'html', 'encoding' => '', 'debugbox' => false, 'pdfversion' => '1.4', 'draw_page_border' => false);
    $pipeline->configure($g_config);
    $pipeline->process($baseurl, $media);
}
/**
 * Runs the HTML->PDF conversion with default settings
 *
 * Warning: if you have any files (like CSS stylesheets and/or images referenced by this file,
 * use absolute links (like http://my.host/image.gif).
 *
 * @param $path_to_html String HTML code to be converted
 * @param $path_to_pdf  String path to file to save generated PDF to.
 * @param $base_path    String base path to use when resolving relative links in HTML code.
 */
function convert_to_pdf($html, $path_to_pdf, $base_path = '')
{
    $pipeline = PipelineFactory::create_default_pipeline('', '');
    // Override HTML source
    // @TODO: default http fetcher will return null on incorrect images
    // Bug submitted by 'imatronix' (tufat.com forum).
    $pipeline->fetchers[] = new MyFetcherMemory($html, $base_path);
    // Override destination to local file
    $pipeline->destination = new MyDestinationFile($path_to_pdf);
    $baseurl = '';
    $media =& Media::predefined('A4');
    $media->set_landscape(false);
    $media->set_margins(array('left' => 0, 'right' => 0, 'top' => 0, 'bottom' => 0));
    $media->set_pixels(1024);
    global $g_config;
    $g_config = array('cssmedia' => 'screen', 'scalepoints' => '1', 'renderimages' => true, 'renderlinks' => true, 'renderfields' => true, 'renderforms' => false, 'mode' => 'html', 'encoding' => '', 'debugbox' => false, 'pdfversion' => '1.4', 'draw_page_border' => false);
    $pipeline->configure($g_config);
    $pipeline->process_batch(array($baseurl), $media);
}
Esempio n. 9
0
// 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($_REQUEST['cssmedia']) ? $_REQUEST['cssmedia'] : "screen", 'media' => isset($_REQUEST['media']) ? $_REQUEST['media'] : "A4", 'scalepoints' => isset($_REQUEST['scalepoints']), 'renderimages' => isset($_REQUEST['renderimages']), 'renderfields' => isset($_REQUEST['renderfields']), 'renderforms' => isset($_REQUEST['renderforms']), 'pslevel' => isset($_REQUEST['pslevel']) ? $_REQUEST['pslevel'] : 3, 'renderlinks' => isset($_REQUEST['renderlinks']), 'pagewidth' => isset($_REQUEST['pixels']) ? (int) $_REQUEST['pixels'] : 800, 'landscape' => isset($_REQUEST['landscape']), 'method' => isset($_REQUEST['method']) ? $_REQUEST['method'] : "fpdf", 'margins' => array('left' => isset($_REQUEST['leftmargin']) ? (int) $_REQUEST['leftmargin'] : 0, 'right' => isset($_REQUEST['rightmargin']) ? (int) $_REQUEST['rightmargin'] : 0, 'top' => isset($_REQUEST['topmargin']) ? (int) $_REQUEST['topmargin'] : 0, 'bottom' => isset($_REQUEST['bottommargin']) ? (int) $_REQUEST['bottommargin'] : 0), 'encoding' => isset($_REQUEST['encoding']) ? $_REQUEST['encoding'] : "", 'ps2pdf' => isset($_REQUEST['ps2pdf']), 'compress' => isset($_REQUEST['compress']), 'output' => isset($_REQUEST['output']) ? $_REQUEST['output'] : 0, 'pdfversion' => isset($_REQUEST['pdfversion']) ? $_REQUEST['pdfversion'] : "1.2", 'transparency_workaround' => isset($_REQUEST['transparency_workaround']), 'imagequality_workaround' => isset($_REQUEST['imagequality_workaround']), 'draw_page_border' => isset($_REQUEST['pageborder']), 'debugbox' => isset($_REQUEST['debugbox']), 'html2xhtml' => !isset($_REQUEST['html2xhtml']), 'mode' => 'html');
// ========== Entry point
parse_config_file('./html2ps.config');
// validate input data
if ($g_config['pagewidth'] == 0) {
    die("Please specify non-zero value for the pixel width!");
}
// 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
Esempio n. 10
0
function fn_html_to_pdf($html, $name)
{
    if (!fn_init_pdf()) {
        fn_redirect(!empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : INDEX_SCRIPT);
    }
    $pipeline = PipelineFactory::create_default_pipeline('', '');
    if (!is_array($html)) {
        $html = array($html);
    }
    $pipeline->fetchers = array(new PdfFetcherMemory($html, Registry::get('config.current_location') . '/'), new FetcherURL());
    $pipeline->destination = new PdfDestinationDownload($name);
    $pipeline->data_filters = array(new DataFilterDoctype(), new DataFilterHTML2XHTML());
    $media =& Media::predefined('A4');
    $media->set_landscape(false);
    $media->set_margins(array('left' => 20, 'right' => 20, 'top' => 20, 'bottom' => 0));
    $media->set_pixels(600);
    $_config = array('cssmedia' => 'print', 'scalepoints' => '1', 'renderimages' => true, 'renderlinks' => true, 'renderfields' => true, 'renderforms' => false, 'mode' => 'html', 'encoding' => 'utf8', 'debugbox' => false, 'pdfversion' => '1.4', 'draw_page_border' => false, 'smartpagebreak' => true);
    $pipeline->configure($_config);
    $pipeline->process_batch(array_keys($html), $media);
}
         function get_data($dummy1)
         {
             return new FetchedDataURL($this->_content, array(), "");
         }
         function get_base_url()
         {
             return "";
         }
     }
 }
 $pipeline = PipelineFactory::create_default_pipeline("", "");
 // Attempt to auto-detect encoding
 // Override HTML source
 $pipeline->fetchers[] = new MyFetcherLocalFile($html_to_pdf);
 $baseurl = "";
 $media = Media::predefined($config->export->pdf->papersize);
 $media->set_landscape(false);
 global $g_config;
 $g_config = array('cssmedia' => 'screen', 'renderimages' => true, 'renderlinks' => true, 'renderfields' => true, 'renderforms' => false, 'mode' => 'html', 'encoding' => '', 'debugbox' => false, 'pdfversion' => '1.4', 'process_mode' => 'single', 'pixels' => $config->export->pdf->screensize, 'media' => $config->export->pdf->papersize, 'margins' => array('left' => $config->export->pdf->leftmargin, 'right' => $config->export->pdf->rightmargin, 'top' => $config->export->pdf->topmargin, 'bottom' => $config->export->pdf->bottommargin), 'transparency_workaround' => 1, 'imagequality_workaround' => 1, 'draw_page_border' => false);
 $media->set_margins($g_config['margins']);
 $media->set_pixels($config->export->pdf->screensize);
 /*
 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 	// Date in the past
 
 header("Location: $myloc");
 */
 global $g_px_scale;
 $g_px_scale = mm2pt($media->width() - $media->margins['left'] - $media->margins['right']) / $media->pixels;
 global $g_pt_scale;
 $g_pt_scale = $g_px_scale * 1.43;
Esempio n. 12
0
    #		fwrite($fd,$GLOBALS{TSFE}->content);
    #		fclose($fd);
}
//------------------------------------------
// now pipe the html through html2ps
parse_config_file(t3lib_extMgm::extPath('pdf_generator2', 'html2ps/html2ps.config'));
$pdffile = tempnam('typo3temp', 'pdf_');
$pipeline = PipelineFactory::create_default_pipeline("", "");
// Override HTML source, passsing our original root directory
$pipeline->fetchers = array(new MyFetcherLocalFile());
// Override destination to local file
$pipeline->destination = new MyDestinationFile($pdffile);
if (preg_match('/^(\\d+(\\.\\d+)?)x(\\d+(\\.\\d+)?)$/i', $html2pdf_size, $match)) {
    $media = new Media(array('width' => $match[1], 'height' => $match[3]), array('top' => 0, 'bottom' => 0, 'left' => 0, 'right' => 0));
} else {
    $media = Media::predefined($html2pdf_size);
}
$media->set_landscape($html2pdf_landscape);
$media->set_margins(array('left' => $html2pdf_left, 'right' => $html2pdf_right, 'top' => $html2pdf_top, 'bottom' => $html2pdf_bottom));
$media->set_pixels($html2pdf_browserwidth);
global $g_config;
$g_config = array('cssmedia' => $html2pdf_cssmedia, 'renderimages' => true, 'renderlinks' => $html2pdf_renderlinks, 'renderfields' => $html2pdf_renderfields, 'renderforms' => $html2pdf_renderforms, 'mode' => 'html', 'encoding' => '', 'debugbox' => false, 'pdfversion' => $html2pdf_pdfversion, 'draw_page_border' => false);
if ($g_config['renderfields']) {
    $pipeline->pre_tree_filters[] = new PreTreeFilterHTML2PSFields();
}
// caclulate scaling
global $g_px_scale;
$g_px_scale = mm2pt($media->width() - $media->margins['left'] - $media->margins['right']) / $media->pixels;
global $g_pt_scale;
$g_pt_scale = $g_px_scale * 1.43;
if ($html2pdf_use_pdflib) {
Esempio n. 13
0
 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);
     }
 }
Esempio n. 14
0
<?php

$urls = array('http://247realmedia.com', 'http://888.com', 'http://abetterinternet.com', 'http://adsense.google.com', 'http://allwomencentral.com/?r=sub', 'http://www.articlehub.com/add.html', 'http://aur.archlinux.org', 'http://bbc.co.uk', 'http://benews.net', 'http://casalemedia.com', 'http://cnn.com', 'http://www.codeguru.com/register.php', 'http://cra-arc.gc.ca/menu-e.html', 'http://crux.nu', 'http://cs.wisc.edu/~ghost/', 'http://distrowatch.com', 'http://dmoz.org/cgi-bin/apply.cgi?submit=Proceed&where=Business%2FEmployment%2FCareers&id=&lk=&loc=', 'http://download.com', 'http://ebay.com', 'http://ewizard.com', 'http://exactsearch.net', 'http://exitexchange.com', 'http://ezinearticles.com/submit', 'http://falkag.net', 'http://fedora.redhat.com', 'http://freebsd.org', 'http://freewho.com/expired/index.php', 'http://gentoo.org', 'http://geocities.com', 'http://www.getafreelancer.com/users/signup.php', 'http://gmail.com', 'http://go.com', 'http://google.co.in', 'http://google.com/about.html', 'http://google.com/froogle', 'http://google.com/services/', 'http://google.fi/fi', 'http://guru.com/pro/post_profile.cfm', 'http://hamster.sazco.net', 'http://www-128.ibm.com/developerworks/linux/library/l-proc.html', 'http://hotmail.com', 'http://indianrail.gov.in', 'http://internet-optimizer.com', 'http://jakpsatweb.cz/css/css-vertical-center-solution.html', 'http://jobsearch.monsterindia.com/advanced_job_search.html', 'http://johnlewis.com', 'http://kubuntu.org', 'http://lyrc.com.ar/en/add/add.php', 'http://microsoft.com', 'http://msn.com', 'http://myblog.de', 'http://myway.com', 'http://mywebsearch.com', 'http://net-offers.net', 'http://netscape.com', 'http://netvenda.com', 'http://offeroptimizer.com', 'http://onet.pl', 'http://opensuse.org', 'http://osnews.com', 'http://papajohns.com', 'http://partypoker.com', 'http://passport.com', 'http://php.net', 'http://pilger.carlton.com', 'http://priyank.one09.net', 'http://python.org/~guido/', 'http://realmedia.com', 'http://rentacoder.com', 'http://revenue.net', 'http://rubixlinux.org', 'http://sage.com/local/regionNorthAmerica.aspx', 'http://searchscout.com', 'http://search.ebay.in/ws/search/AdvSearch?sofindtype=13', 'http://services.princetonreview.com/register.asp?RUN=%2FstudentTools%2FstudentTool%2Easp&RCN=auth&RDN=1&ALD=http%3A%2F%2Ftestprep%2Eprincetonreview%2Ecom', 'http://smarty.php.net', 'http://stallman.org', 'http://stanton-finley.net/fedora_core_5_installation_notes.html', 'http://thefacebook.com', 'http://tickle.com', 'http://trafficmp.com', 'http://tufat.com', 'http://ubuntu.com', 'http://user.it.uu.se/~jan/html2ps.html', 'http://vianet.com.pl', 'http://website.in/domain.php', 'http://whenu.com', 'http://whitehouse.gov', 'http://whois.org/', 'http://en.wikipedia.org', 'http://en.wikipedia.org/w/index.php?title=Spangenhelm&action=edit', 'http://wolfram.com', 'http://www.xe.com/ucc', 'http://yahoo.com', 'http://yahoomail.com', 'http://edit.yahoo.com/config/eval_register', 'http://zango.com');
require_once dirname(__FILE__) . '/../config.inc.php';
require_once dirname(__FILE__) . '/../pipeline.class.php';
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);
Esempio n. 15
0
 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');
         }
     }
 }
Esempio n. 16
0
 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;
 }
Esempio n. 17
0
 {
     var $_content;
     function MyFetcherLocalFile()
     {
         $this->_content = "Test<!--NewPage-->Test<pagebreak/>Test<?page-break>Test";
     }
     function get_data($dummy1)
     {
         return new FetchedDataURL($this->_content, array(), "");
     }
     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";
Esempio n. 18
0
// 110723, dwildt -
//parse_config_file('../html2ps.config');
// 110723, dwildt +
parse_config_file(HTML2PS_DIR . 'html2ps.config');
// validate input data
if ($GLOBALS['g_config']['pagewidth'] == 0) {
    die("Please specify non-zero value for the pixel width!");
}
// 110723, dwildt +
if ($this->b_drs_perform) {
    $endTime = $this->TT->getDifferenceToStarttime();
    t3lib_div::devLog('[INFO/PERFORMANCE] html2ps is starting the process: ' . ($endTime - $this->startTime) . ' ms', $this->extKey, 0);
}
// 110723, dwildt +
// begin processing
$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']);
// Initialize the coversion pipeline
$pipeline = new Pipeline();
$pipeline->configure($GLOBALS['g_config']);
// Configure the fetchers
if (extension_loaded('curl')) {
    require_once HTML2PS_DIR . 'fetcher.url.curl.class.php';
    $pipeline->fetchers = array(new FetcherUrlCurl());
    if ($proxy != '') {
        $pipeline->fetchers[0]->set_proxy($proxy);
    }
} else {
    require_once HTML2PS_DIR . 'fetcher.url.class.php';
function cw_pdf_generate($file, $template, $save_to_file = false, $landscape = false, $pages_limit = 0, $page_margins = array('10', '10', '10', '10'), $show_pages = true)
{
    global $smarty, $var_dirs, $current_location;
    set_time_limit(2700);
    ini_set('memory_limit', '512M');
    $smarty->assign('is_pdf', true);
    # kornev, only for A4 && 1024 p/wide
    $wcr = $hcr = 1024 / 210;
    $smarty->assign('wcr', $wcr);
    $smarty->assign('hcr', $hcr);
    if ($save_to_file && $file) {
        $html = $file;
    } else {
        $html = cw_display($template, $smarty, false);
    }
    parse_config_file(HTML2PS_DIR . 'html2ps.config');
    $pipeline = PipelineFactory::create_default_pipeline('', '');
    $pipeline->fetchers[] = new MyFetcherMemory($html, $current_location);
    if ($save_to_file) {
        $pipeline->destination = new MyDestinationFile($save_to_file);
    } else {
        $pipeline->destination = new DestinationDownload($file);
    }
    if ($show_pages) {
        $pipeline->pre_tree_filters[] = new PreTreeFilterHeaderFooter('', '<div>' . cw_get_langvar_by_name('lbl_page', null, false, true) . ' ##PAGE## / ##PAGES## </div>');
    }
    $pipeline->pre_tree_filters[] = new PreTreeFilterHTML2PSFields();
    $media =& Media::predefined('A4');
    $media->set_landscape($landscape);
    $media->set_margins(array('left' => $page_margins[3], 'right' => $page_margins[1], 'top' => $page_margins[0], 'bottom' => $page_margins[2]));
    $media->set_pixels(1024);
    $g_config = array('cssmedia' => 'print', 'scalepoints' => '1', 'renderimages' => true, 'renderlinks' => false, 'renderfields' => false, 'renderforms' => false, 'mode' => 'html', 'encoding' => '', 'debugbox' => false, 'pdfversion' => '1.4', 'smartpagebreak' => true, 'draw_page_border' => false, 'html2xhtml' => false, 'method' => 'fpdf', 'pages_limit' => $pages_limit);
    $pipeline->configure($g_config);
    $pipeline->process_batch(array(''), $media);
    if (!$save_to_file) {
        exit(0);
    }
}