Créer une vue PDF dans un composant

Réduire
X
 
  • Filtrer
  • Heure
  • Afficher
Tout effacer
nouveaux messages

  • [Problème] Créer une vue PDF dans un composant

    Je n'arrive pas à créer une vue pdf dans le composant que je crée
    Pour un composant 2.5, j'utilisais http://docs.joomla.org/J2.5:Creating_PDF_views et ça fonctionnait très bien.
    Maintenant, dans J3, avec le même code, ça ne passe plus
    J'ai trouvé un autre gars qui avait le même problème : http://stackoverflow.com/questions/1...m-html-content mais sans solution
    J'ai essayé phoca et d'autres mais sans trop de succès
    J'ai l'impression que tout vient de ce code. Verriez-vous une incompatibilité criante avec j3?
    Code:
    <?php
    /**
     * @package             Joomla.Framework
     * @subpackage  Document
     * @copyright   Copyright (C) 2005 - 2012 Rob Clayburn
     * @license             GNU/GPL, see LICENSE.php
     * Joomla! is free software. This version may have been modified pursuant
     * to the GNU General Public License, and as distributed it includes or
     * is derivative of works licensed under the GNU General Public License or
     * other free or open source software licenses.
     * See COPYRIGHT.php for copyright notices and details.
     */
     
    // Check to ensure this file is within the rest of the framework
    defined('JPATH_BASE') or die();
     
    require_once(JPATH_LIBRARIES .'/joomla/document/html/html.php');
     
    /**
     * DocumentPDF class, provides an easy interface to parse and display a pdf document
     *
     * @package             Joomla.Framework
     * @subpackage  Document
     * @since               1.5
     */
    class JDocumentpdf extends JDocumentHTML
    {
            private $engine = null;
     
            private $name = 'joomla';
     
            /**
             * Class constructore
             * @param       array   $options Associative array of options
             */
     
            function __construct($options = array())
            {
                    parent::__construct($options);
     
                    //set mime type
                    $this->_mime = 'application/pdf';
     
                    //set document type
                    $this->_type = 'pdf';
     
                    if (!$this->iniDomPdf())
                    {
                            JError::raiseError(500, 'No PDF lib found');
                    }
            }
     
            protected function iniDomPdf()
            {
                    $file = JPATH_LIBRARIES .'/dompdf/dompdf_config.inc.php';
                    if (!JFile::exists($file))
                    {
                            return false;
                    }
                    if (!defined('DOMPDF_ENABLE_REMOTE'))
                    {
                            define('DOMPDF_ENABLE_REMOTE', true);
                    }
                    //set the font cache directory to Joomla's tmp directory
                    $config = JFactory::getConfig();
                    if (!defined('DOMPDF_FONT_CACHE'))
                    {
                            define('DOMPDF_FONT_CACHE', $config->get('tmp_path'));
                    }
                    require_once($file);
                    // Default settings are a portrait layout with an A4 configuration using millimeters as units
                    $this->engine =new DOMPDF();
                    return true;
            }
     
            /**
             * Sets the document name
             * @param   string   $name      Document name
             * @return  void
             */
     
            public function setName($name = 'joomla')
            {
                    $this->name = $name;
            }
     
            /**
             * Returns the document name
             * @return      string
             */
     
            public function getName()
            {
                    return $this->name;
            }
     
            /**
             * Render the document.
             * @access public
             * @param boolean       $cache          If true, cache the output
             * @param array         $params         Associative array of attributes
             * @return      string
             */
     
            function render($cache = false, $params = array())
            {
                    $pdf = $this->engine;
                    $data = parent::render();
                    $this->fullPaths($data);
                    //echo $data;exit;
                    $pdf->load_html($data);
                    $pdf->render();
                    $pdf->stream($this->getName() . '.pdf');
                    return '';
            }
     
            /**
             * (non-PHPdoc)
             * @see JDocumentHTML::getBuffer()
             */
     
            public function getBuffer($type = null, $name = null, $attribs = array())
            {
                    if ($type == 'head' || $type == 'component')
                    {
                            return parent::getBuffer($type, $name, $attribs);
                    }
                    else
                    {
                            return '';
                    }
            }
     
     
            /**
             * parse relative images a hrefs and style sheets to full paths
             * @param       string  &$data
             */
     
            private function fullPaths(&$data)
            {
                    $data = str_replace('xmlns=', 'ns=', $data);
                    libxml_use_internal_errors(true);
                    try
                    {
                            $ok = new SimpleXMLElement($data);
                            if ($ok)
                            {
                                    $uri = JUri::getInstance();
                                    $base = $uri->getScheme() . '://' . $uri->getHost();
                                    $imgs = $ok->xpath('//img');
                                    foreach ($imgs as &$img)
                                    {
                                            if (!strstr($img['src'], $base))
                                            {
                                                    $img['src'] = $base . $img['src'];
                                            }
                                    }
                                    //links
                                    $as = $ok->xpath('//a');
                                    foreach ($as as &$a)
                                    {
                                            if (!strstr($a['href'], $base))
                                            {
                                                    $a['href'] = $base . $a['href'];
                                            }
                                    }
     
                                    // css files.
                                    $links = $ok->xpath('//link');
                                    foreach ($links as &$link)
                                    {
                                            if ($link['rel'] == 'stylesheet' && !strstr($link['href'], $base))
                                            {
                                                    $link['href'] = $base . $link['href'];
                                            }
                                    }
                                    $data = $ok->asXML();
                            }
                    } catch (Exception $err)
                    {
                            //oho malformed html - if we are debugging the site then show the errors
                            // otherwise continue, but it may mean that images/css/links are incorrect
                            $errors = libxml_get_errors();
                            if (JDEBUG)
                            {
                                    echo "<pre>";print_r($errors);echo "</pre>";
                                    exit;
                            } 
                    }
     
            }
     
    }
    Quelqu'un peut-il m'aider svp ?

Annonce

Réduire
Aucune annonce pour le moment.

Partenaire de l'association

Réduire

Hébergeur Web PlanetHoster
Travaille ...
X