Ejemplo n.º 1
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;
     }
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 4
0
function get_extra_conf($safe_category)
{
    $template_dir = get_template_dir();
    if (!$safe_category) {
        return false;
    }
    $custom_path = $template_dir . strtolower(preg_replace("/[^\\w]/i", "", $safe_category)) . "/" . strtolower(preg_replace("/[^\\w]/i", "", $safe_category)) . ".conf";
    if (file_exists($custom_path)) {
        $data = file_get_contents($custom_path);
        parse_config_file($data);
    }
}
 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));
 }
Ejemplo n.º 6
0
    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);
    }
Ejemplo n.º 7
0
function convert_html2pdf($html, $pdf)
{
    // start conversion
    //require_once('includes/html2ps/dave.php');
    $library = module_config::c('pdf_library');
    if (!$library && file_exists(dirname(__FILE__) . '/mpdf/mpdf.php')) {
        $library = 'mpdf';
    }
    switch ($library) {
        case 'mpdf':
            if (file_exists(dirname(__FILE__) . '/mpdf/mpdf.php')) {
                //require_once ( dirname( __FILE__ ) . '/mpdf/mpdf.php' );
                require_once module_theme::include_ucm('includes/plugin_pdf/mpdf/mpdf.php');
                $html_contents = file_get_contents($html);
                $mpdf = new mPDF('', module_config::c('pdf_media_size', 'A4'), 0, '', module_config::c('pdf_media_left', '10'), module_config::c('pdf_media_right', '10'), module_config::c('pdf_media_top', '10'), module_config::c('pdf_media_bottom', '10'), 8, 8);
                $mpdf->debug = true;
                $mpdf->WriteHTML($html_contents);
                //$mpdf->Output($pdf,'D'); // Download
                $mpdf->Output($pdf, 'F');
                break;
            }
        default:
            ini_set('error_reporting', E_ERROR);
            ini_set("display_errors", true);
            require_once 'html2ps/config.inc.php';
            require_once HTML2PS_DIR . 'pipeline.factory.class.php';
            set_time_limit(120);
            parse_config_file(HTML2PS_DIR . 'html2ps.config');
            global $g_font_resolver_pdf;
            //    print_r($g_font_resolver_pdf->ttf_mappings); exit;
            $g_font_resolver_pdf->ttf_mappings['Arial Unicode MS'] = module_config::c('pdf_unicode_font', 'arialuni.ttf');
            /**
             * Handles the saving generated PDF to user-defined output file on server
             */
            if (!class_exists('MyDestinationFile', false)) {
                class MyDestinationFile extends Destination
                {
                    /**
                     * @var String result file name / path
                     * @access private
                     */
                    var $_dest_filename;
                    function MyDestinationFile($dest_filename)
                    {
                        $this->_dest_filename = $dest_filename;
                    }
                    function process($tmp_filename, $content_type)
                    {
                        copy($tmp_filename, $this->_dest_filename);
                    }
                }
                class MyFetcherLocalFile extends Fetcher
                {
                    var $_content;
                    function MyFetcherLocalFile($file)
                    {
                        $this->_content = file_get_contents($file);
                    }
                    function get_data($dummy1)
                    {
                        return new FetchedDataURL($this->_content, array(), "");
                    }
                    function get_base_url()
                    {
                        return "http://" . $_SERVER['HTTP_HOST'] . '/';
                    }
                }
                /**
                 * 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(module_config::c('pdf_media_size', 'A4'));
                    $media->set_landscape(false);
                    $media->set_margins(array('left' => module_config::c('pdf_media_left', '0'), 'right' => module_config::c('pdf_media_right', '0'), 'top' => module_config::c('pdf_media_top', '0'), 'bottom' => module_config::c('pdf_media_bottom', '0')));
                    $media->set_pixels(module_config::c('pdf_media_pixels', '1010'));
                    global $g_config;
                    $g_config = array('compress' => true, 'cssmedia' => 'screen', 'scalepoints' => '1', 'renderimages' => true, 'renderlinks' => true, 'renderfields' => true, 'renderforms' => false, 'mode' => 'html', 'encoding' => 'UTF-8', 'debugbox' => false, 'pdfversion' => '1.4', 'draw_page_border' => false, 'media' => module_config::c('pdf_media_size', 'A4'));
                    $pipeline->configure($g_config);
                    //$pipeline->add_feature('toc', array('location' => 'before'));
                    $pipeline->process($baseurl, $media);
                }
            }
            convert_to_pdf($html, $pdf);
            break;
    }
    return str_replace(_UCM_FOLDER, '', $pdf);
}
Ejemplo n.º 8
0
<?php

$path_to_pipeline = "../";
$GLOBALS['path_to_pipeline'] = $path_to_pipeline;
# need to get a listing of the .conf files in the conf directory...
$config_files = glob($path_to_pipeline . "conf/*.conf");
$config_file = $path_to_pipeline . "conf/default.conf";
if ($config_files) {
    foreach ($config_files as $current_config_file) {
        if ($current_config_file != $config_file) {
            $config_file = $current_config_file;
        }
    }
}
$config = array();
$data = file_get_contents($config_file);
parse_config_file($data);
function parse_config_file($data)
{
    global $config;
    $config_lines = preg_split("/[\n\r]/", $data);
    foreach ($config_lines as $config_line) {
        $matches = array();
        if (preg_match("/(.*)=(.*)/", $config_line, $matches)) {
            $config[$matches[1]] = $matches[2];
        }
    }
}
# to debug, uncomment the line below
# foreach ($config as $key => $val) {print "$key ==> $val\n";}
Ejemplo n.º 9
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);
     }
 }
Ejemplo n.º 10
0
function edit_config()
{
    global $input;
    if (isset($input['confirm']) && !empty($input['confirm'])) {
        $allow_recorder = $input['recording_enabled'] == 'on';
        $add_users = $input['add_users_enabled'] == 'on';
        $pwd_storage = $input['password_storage_enabled'] == 'on';
        $use_course_name = $input['courses_by_name'] == 'on';
        $use_user_name = $input['users_by_name'] == 'on';
        update_config_file($allow_recorder, $add_users, $pwd_storage, $use_course_name, $use_user_name);
        $alert = '<div class="alert alert-success">' . template_get_message('save_successful', get_lang()) . '</div>';
    }
    $params = parse_config_file();
    //update_config_file(false, true, true);
    include template_getpath('div_main_header.php');
    include template_getpath('div_edit_config.php');
    include template_getpath('div_main_footer.php');
}
Ejemplo n.º 11
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');
         }
     }
 }
Ejemplo n.º 12
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;
 }
<?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);
Ejemplo n.º 14
0
$GLOBALS['g_config'] = array('compress' => isset($_REQUEST['compress']), 'cssmedia' => get_var('cssmedia', $_REQUEST, 255, "screen"), 'debugbox' => isset($_REQUEST['debugbox']), 'debugnoclip' => isset($_REQUEST['debugnoclip']), 'draw_page_border' => isset($_REQUEST['pageborder']), 'encoding' => get_var('encoding', $_REQUEST, 255, ""), 'html2xhtml' => !isset($_REQUEST['html2xhtml']), 'imagequality_workaround' => isset($_REQUEST['imagequality_workaround']), 'landscape' => isset($_REQUEST['landscape']), 'margins' => array('left' => (int) get_var('leftmargin', $_REQUEST, 10, 0), 'right' => (int) get_var('rightmargin', $_REQUEST, 10, 0), 'top' => (int) get_var('topmargin', $_REQUEST, 10, 0), 'bottom' => (int) get_var('bottommargin', $_REQUEST, 10, 0)), 'media' => get_var('media', $_REQUEST, 255, "A4"), 'method' => get_var('method', $_REQUEST, 255, "fpdf"), 'mode' => 'html', 'output' => get_var('output', $_REQUEST, 255, ""), 'pagewidth' => (int) get_var('pixels', $_REQUEST, 10, 800), 'pdfversion' => get_var('pdfversion', $_REQUEST, 255, "1.2"), 'ps2pdf' => isset($_REQUEST['ps2pdf']), 'pslevel' => (int) get_var('pslevel', $_REQUEST, 1, 3), 'renderfields' => isset($_REQUEST['renderfields']), 'renderforms' => isset($_REQUEST['renderforms']), 'renderimages' => isset($_REQUEST['renderimages']), 'renderlinks' => isset($_REQUEST['renderlinks']), 'scalepoints' => isset($_REQUEST['scalepoints']), 'smartpagebreak' => isset($_REQUEST['smartpagebreak']), 'transparency_workaround' => isset($_REQUEST['transparency_workaround']));
// dwildt, 110725
//var_dump($GLOBALS['g_config']);
//return;
$proxy = get_var('proxy', $_REQUEST, 255, '');
// 110723, dwildt +
if ($this->b_drs_perform) {
    $endTime = $this->TT->getDifferenceToStarttime();
    t3lib_div::devLog('[INFO/PERFORMANCE] html2ps is parsing the config file: ' . ($endTime - $this->startTime) . ' ms', $this->extKey, 0);
}
// 110723, dwildt +
// ========== Entry point
// 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']);
Ejemplo n.º 15
0
    $mt = isset($POST_PROCESSING_DIRECTIVES["margin_top"]) ? $POST_PROCESSING_DIRECTIVES["margin_top"] : 0;
}
if ($mb == -1) {
    $mb = isset($POST_PROCESSING_DIRECTIVES["margin_bottom"]) ? $POST_PROCESSING_DIRECTIVES["margin_bottom"] : 0;
}
// ** Overwrite page width value with directives
if ($pw == -1) {
    $pw = isset($POST_PROCESSING_DIRECTIVES["page_width"]) ? $POST_PROCESSING_DIRECTIVES["page_width"] : 800;
}
/*****************************************************************************/
/** Configuration */
$GLOBALS['g_config'] = array('cssmedia' => "screen", 'media' => "A4", 'scalepoints' => true, 'renderimages' => true, 'renderfields' => true, 'renderforms' => false, 'pslevel' => 3, 'renderlinks' => true, 'pagewidth' => $pw, 'landscape' => false, 'method' => "fpdf", 'margins' => array('left' => $ml, 'right' => $mr, 'top' => $mt, 'bottom' => $mb), 'encoding' => "", 'ps2pdf' => false, 'compress' => false, 'output' => 1, 'pdfversion' => "1.2", 'transparency_workaround' => false, 'imagequality_workaround' => false, 'draw_page_border' => false, 'debugbox' => false, 'html2xhtml' => true, 'mode' => 'html', 'smartpagebreak' => true);
/*****************************************************************************/
/** Inizializza pipeline */
// ** Parse configuration file
parse_config_file(HTML2PS_BASEDIR . "html2ps.config");
// ** Media
$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']);
// ** Pipeline
// *** Initialize the coversion pipeline
$pipeline = new Pipeline();
// *** Fetchers
$pipeline->fetchers[] = new FetcherUrl();
// *** Data filters
$pipeline->data_filters[] = new DataFilterDoctype();
$pipeline->data_filters[] = new DataFilterUTF8("");
$pipeline->data_filters[] = new DataFilterHTML2XHTML();
// *** Parser
Ejemplo n.º 16
0
/**
 * Init pdf engine
 *
 * @return boolean always true
 */
function fn_init_pdf()
{
    // pdf can't be generated correctly without DOM extension (DOMDocument class)
    if (!class_exists('DOMDocument')) {
        $msg = AREA == 'A' ? fn_get_lang_var('error_generate_pdf_admin') : fn_get_lang_var('error_generate_pdf_customer');
        fn_set_notification('E', fn_get_lang_var('error'), $msg);
        return false;
    }
    if (defined('PDF_STARTED')) {
        return true;
    }
    define('CACHE_DIR', DIR_CACHE . 'pdf/cache');
    define('OUTPUT_FILE_DIRECTORY', DIR_CACHE . 'pdf/out');
    define('WRITER_TEMPDIR', DIR_CACHE . 'pdf/temp');
    if (!is_dir('CACHE_DIR')) {
        fn_mkdir(CACHE_DIR);
    }
    if (!is_dir('OUTPUT_FILE_DIRECTORY')) {
        fn_mkdir(OUTPUT_FILE_DIRECTORY);
    }
    if (!is_dir('WRITER_TEMPDIR')) {
        fn_mkdir(WRITER_TEMPDIR);
    }
    require DIR_CORE . 'class.pdf_converter.php';
    parse_config_file(HTML2PS_DIR . 'html2ps.config');
    fn_define('PDF_STARTED', true);
    return true;
}
Ejemplo n.º 17
0
function pdfThis($html, $file_location = "", $pdfname)
{
    global $config;
    //	set_include_path("../../../../library/pdf/");
    require_once './library/pdf/config.inc.php';
    require_once './library/pdf/pipeline.factory.class.php';
    require_once './library/pdf/pipeline.class.php';
    parse_config_file('./library/pdf/html2ps.config');
    require_once "./include/init.php";
    // for getInvoice() and getPreference()
    #$invoice_id = $_GET['id'];
    #$invoice = getInvoice($invoice_id);
    #$preference = getPreference($invoice['preference_id']);
    #$pdfname = trim($preference['pref_inv_wording']) . $invoice_id;
    #error_reporting(E_ALL);
    #ini_set("display_errors","1");
    #@set_time_limit(10000);
    /**
     * 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.
     */
    if (!function_exists(convert_to_pdf)) {
        function convert_to_pdf($html_to_pdf, $pdfname, $file_location = "")
        {
            global $config;
            $destination = $file_location == "download" ? "DestinationDownload" : "DestinationFile";
            /**
             * Handles the saving generated PDF to user-defined output file on server
             */
            if (!class_exists(MyFetcherLocalFile)) {
                class MyFetcherLocalFile extends Fetcher
                {
                    var $_content;
                    function MyFetcherLocalFile($html_to_pdf)
                    {
                        //$this->_content = file_get_contents($file);
                        $this->_content = $html_to_pdf;
                    }
                    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;
            $pipeline->configure($g_config);
            $pipeline->data_filters[] = new DataFilterUTF8("");
            $pipeline->destination = new $destination($pdfname);
            $pipeline->process($baseurl, $media);
        }
    }
    //echo "location: ".$file_location;
    convert_to_pdf($html, $pdfname, $file_location);
}
Ejemplo n.º 18
0
//---------------------------- make links absolute --------------
function fix_links_callback($matches)
{
    return $matches[1] . t3lib_div::locationHeaderUrl($matches[2]) . $matches[3];
}
$GLOBALS[TSFE]->content = preg_replace_callback('/(<a [^>]*href=\\")(?!#)(.*?)(\\")/', 'fix_links_callback', $GLOBALS[TSFE]->content);
$GLOBALS[TSFE]->content = preg_replace_callback('/(<form [^>]*action=\\")(?!#)(.*?)(\\")/', 'fix_links_callback', $GLOBALS[TSFE]->content);
// write the html for debugging puposes
if (0) {
    #		$fd=fopen('typo3temp/html2ps.html', 'wb');
    #		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;
Ejemplo n.º 19
-1
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);
    }
}