THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

Rejoignez la communauté sur le Discord Thelia : https://discord.gg/YgwpYEE3y3

Offline


I am developing a plugin which enable the customer to get a catalogue in pdf format. Each articles is presented with an image . 
An Exception is raised from Html2Pdf when the program is trying to draw the first image :

1: ERROR [ErrorListener.php:logException()] {109} 2018-11-09 19:35:04:Uncaught exceptionERREUR n°6 : Impossible de charger l'image http://localhost:8090/web/assets/frontOffice/spiced/Catalogue/assets/img/7a89493.jpg
Stack Trace: #0 /var/www/html/core/vendor/ensepar/html2pdf/HTML2PDF.php(5614): HTML2PDF->_drawImage('http://localhos...', false)
#1 /var/www/html/core/vendor/ensepar/html2pdf/HTML2PDF.php(1254): HTML2PDF->_tag_open_IMG(Array)
#2 /var/www/html/core/vendor/ensepar/html2pdf/HTML2PDF.php(1225): HTML2PDF->_executeAction(Array)
#3 /var/www/html/core/vendor/ensepar/html2pdf/HTML2PDF.php(2684): HTML2PDF->_makeHTMLcode()
#4 /var/www/html/core/vendor/ensepar/html2pdf/HTML2PDF.php(1254): HTML2PDF->_tag_open_DIV(Array)
#5 /var/www/html/core/vendor/ensepar/html2pdf/HTML2PDF.php(1225): HTML2PDF->_executeAction(Array)
#6 /var/www/html/core/vendor/ensepar/html2pdf/HTML2PDF.php(2684): HTML2PDF->_makeHTMLcode()
#7 /var/www/html/core/vendor/ensepar/html2pdf/HTML2PDF.php(1254): HTML2PDF->_tag_open_DIV(Array)
#8 /var/www/html/core/vendor/ensepar/html2pdf/HTML2PDF.php(1225): HTML2PDF->_executeAction(Array)
#9 /var/www/html/core/vendor/ensepar/html2pdf/HTML2PDF.php(2684): HTML2PDF->_makeHTMLcode()
#10 /var/www/html/core/vendor/ensepar/html2pdf/HTML2PDF.php(1254): HTML2PDF->_tag_open_DIV(Array)
#11 /var/www/html/core/vendor/ensepar/html2pdf/HTML2PDF.php(1225): HTML2PDF->_executeAction(Array)
#12 /var/www/html/core/vendor/ensepar/html2pdf/HTML2PDF.php(407): HTML2PDF->_makeHTMLcode()
#13 /var/www/html/core/lib/Thelia/Action/Pdf.php(41): HTML2PDF->writeHTML('\n<!doctype html...')
#14 [internal function]: Thelia\Action\Pdf->generatePdf(Object(Thelia\Core\Event\PdfEvent), 'thelia.generate...', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher))
#15 /var/www/html/core/vendor/symfony/event-dispatcher/EventDispatcher.php(181): call_user_func(Array, Object(Thelia\Core\Event\PdfEvent), 'thelia.generate...', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher))
#16 /var/www/html/core/vendor/symfony/event-dispatcher/EventDispatcher.php(46): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(Array, 'thelia.generate...', Object(Thelia\Core\Event\PdfEvent))
#17 /var/www/html/core/lib/Thelia/Controller/BaseController.php(120): Symfony\Component\EventDispatcher\EventDispatcher->dispatch('thelia.generate...', Object(Thelia\Core\Event\PdfEvent))
#18 /var/www/html/local/modules/Catalogue/Controller/Front/CatalogueController.php(42): Thelia\Controller\BaseController->dispatch('thelia.generate...', Object(Thelia\Core\Event\PdfEvent))
#19 [internal function]: Catalogue\Controller\Front\CatalogueController->createPdfAction()
#20 /var/www/html/core/vendor/symfony/http-kernel/HttpKernel.php(139): call_user_func_array(Array, Array)
#21 /var/www/html/core/vendor/symfony/http-kernel/HttpKernel.php(62): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Thelia\Core\HttpFoundation\Request), 1)
#22 /var/www/html/core/lib/Thelia/Core/TheliaHttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Thelia\Core\HttpFoundation\Request), 1, true)
#23 /var/www/html/core/lib/Thelia/Core/Stack/ParamInitMiddleware.php(87): Thelia\Core\TheliaHttpKernel->handle(Object(Thelia\Core\HttpFoundation\Request), 1, true)
#24 /var/www/html/core/lib/Thelia/Core/Stack/SessionMiddleware.php(80): Thelia\Core\Stack\ParamInitMiddleware->handle(Object(Thelia\Core\HttpFoundation\Request), 1, true)
#25 /var/www/html/core/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Thelia\Core\Stack\SessionMiddleware->handle(Object(Thelia\Core\HttpFoundation\Request), 1, true)
#26 /var/www/html/core/vendor/symfony/http-kernel/Kernel.php(185): Stack\StackedHttpKernel->handle(Object(Thelia\Core\HttpFoundation\Request), 1, true)
#27 /var/www/html/web/index.php(38): Symfony\Component\HttpKernel\Kernel->handle(Object(Thelia\Core\HttpFoundation\Request))
#28 {main}

The Code in the controller :

$catalogueHtml = $this->renderRaw('catalogue');
        $pdfEvent = new PdfEvent($catalogueHtml);

        $this->dispatch(TheliaEvents::GENERATE_PDF, $pdfEvent);

        if ($pdfEvent->hasPdf()) {
            return $this->pdfResponse($pdfEvent->getPdf(), 'catalogue');
        }

and the template :

{declare_assets directory="assets"}
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>Les Jardins d'écoute s'il pleut</title>
     {block name="before-bootstrap-css"}{/block}
     
    {stylesheets source="Catalogue" file="assets/css/catalogue.css"}
        <link href="{$asset_url}" rel="stylesheet" type="text/css" />
    {/stylesheets}
    {block name="after-bootstrap-css"}{/block}
   
   
</head>
<body>
    <div>
        <div>
            <div class="titre-bandeau">Le Jardins d'écoute s'il pleut</div>
            <div class="sous-titre-bandeau">Production de fougères rustiques</div>
            <div class="titre-catalogue">Catalogue public 2018</div>
            <div class="div-image-catalogue">
           
                {images source="Catalogue" file='assets/img/catalogue.jpg'}
                    <img rel="fougeres"  src="{$asset_url}">
                {/images}
            </div>
    ....

Offline


I tried a relative and an absolute url , but I got the same results.
Thank you for your help

Offline


If you try to access http://localhost:8090/web/assets/frontOffice/spiced/Catalogue/assets/img/7a89493.jpg, from your browser, do you see the image ?


OpenStudio Toulouse

Offline


Yes, I do . The image appears in my browser

Offline


OK. Could you please check that "allow_url_fopen" is "on" in your php.ini ? HTML2PDF is loading images by making an HTTP request, so you have to be sure that the PHP code could access the URL of the image. To be sure, try something like :

file_get_contents("http://localhost:8090/web/assets/frontOffice/spiced/Catalogue/assets/img/7a89493.jpg");

in a test script in your web/ directory.


OpenStudio Toulouse

Offline


Thank you for your help.
In fact, I am developing my plugin , using Docker.
Inside Docker , the container is listening on its own ip address and it is not able to load images from "localhost"

Offline


The ip port on the container is exposed on another port on the host. The error was due to this configuration.