I've installed KnpSnappyBundle on an existing Symfony 3.4 project. I've tested the PDF generator with a HTML twig with text only, no images, no css, no js : it works fine.
Then I've added (to the twig) an image and a Bootstrap.Css file using absolute URL (i'm working on localhost): the PDF generator displays an ugly error :
The process "wkhtmltopdf --lowquality '/tmp/knp_snappy5aeb39ad71e767.56551505.html' '/tmp/knp_snappy5aeb39ad71ebf0.62787578.pdf'" exceeded the timeout of 60 seconds.
What's wrong with the bundle ? I'm using an i7 laptop with 8Gb RAM (ubuntu 16.04), I don't think it's a problem of machine configuration.
UPDATE: I've tested wkhtmltopdf from the command line and it do convert my twig :
wkhtmltopdf http://127.0.0.1:8000/eshop/admin/order/print/2 out.pdf
So wkhtmltopdf have no problems with absolute URLs on localhost !
Thanks
Found a solution here : https://github.com/KnpLabs/KnpSnappyBundle/issues/82
It seems like wk is unable to find assets using the absolute URL when called from the bundle (so when executed in shell), you have to specify an absolute path. Create a twig global variable :
twig:
globals:
pathToWeb: "%kernel.root_dir%/../web"
Then in the twig use the new variable instead of asset() :
<link ... href="{{ pathToWeb }}/css/bootstrap.min.css"/>
<img ... src="{{ pathToWeb }}/images/logo.png"/>
Works like a charm
Related
I’m on a new symfony 5 project, with Webpack/encore and sass loader enable.
I also use symfony/apache-pack, so I’m use the following link to access on my web site :
https://localhost/myproject/public/show
I also installed bootstrap, with npm, and I import this css in the sass file : \myproject\assets\styles\app.scss with :
#import '~bootstrap/scss/bootstrap';
When I run a yarn encore dev there are no warning, the css file is in the following directory (with bootstrap inside) :
\myproject\public\build\
My problem is these :
when I use the normal link (I’m on windows with XAMPP) : https://localhost/myproject/public/show , in my twig template, the following twig command doesn’t work :
{{ encore_entry_script_tags('app') }}
links are broken :
I’m required to use for downloading the .css and .js files :
<link rel="stylesheet" href="{{ asset('./build/app.css') }}">
It is very strange, because, when I’m using the internal PHP symfony server (symfony server:start)
I use this URL : https://127.0.0.1/show , and the css could be load.
I don't edit the webpack.config.js (except enabling the sass loader)
Someone can help me, please ?
you must set setPublicPath in 'wbpack.config.js' file to setPublicPath('/show/build')
I am new to Laravel and currently attempt to import vue to my Laravel project.
After I ran 'npm run dev' command and check a page built with blade layout which is downloaded from a boilerplate project, I see the error : Undefined index in style(mix('/css/frontend.css')). This css file exists in public/css.
This is the line that invokes this error.
{{ style(mix('/css/frontend.css')) }}
What is its meaning and how to fix it?
Also, I can't find the api documentation that tell the function of style() and mix().
If you know where the documentation is, please give me the link. Thanks!
Check webpack.mix.js to see if frontend.css is being compiled by Laravel Mix. If you don't see any reference to it, then you should reference the file in your Blade views with asset('/css/frontend.css') instead of mix().
mix() reads from public/mix-manifest.json to map your source filenames to their output name, which is useful when files are versioned for cache busting. A mix-manifest entry might look like this: "/css/app.css": "/css/app.css?id=7564ad125f69af0035c3". If your file wasn't compiled or copied with Laravel mix then it would not have an entry in mix-manifest.json, which would explain the undefined index error and why you need to use asset() instead.
Also, I don't know what style() is but it doesn't come with the Laravel framework.
Refs: https://laravel.com/docs/5.7/mix#versioning-and-cache-busting
I have an incomprehensible problem.
I have used this bundle many times, and I understand the main logic to generate a pdf from a twig view.
But on my two last project i have this kind of error:
Error: Failed to load https://mydomain/bundles/bundle/css/bootstrap.css, with network status code 1 and http status code 0 - Connection refused
Exit with code 1 due to network error: ConnectionRefusedError
I have tried:
HTTP and HTTPS url
chmod 777 on var/cache folder - try acl
disable all parameters of wkhtml
update wkhtml
Disable extends twig view - ihave made a new file with full HTML
Clean controller use assets
filter / absolute_url filter / or web_url variable to prefix assets
On my development environment (Windows), i didn't have any problem.
This problem appeared when I work on production environment, based on Debian 9 with nginx, php 5.6, mariadb 10.0* and letsencrypt certificate.
I can't load any assets for now.
Does anyone have an idea??
Ok i have found a workaround. I use this trick :
create a global variable with this path :
pdf_url: '%kernel.root_dir%/../web'
then i call my assets like this :
<link href="{{ pdf_url}}/bundles/css/bootstrap.css" rel="stylesheet">
Its a not the ebst solution, but its works.
I use Silex-Skeleton. Twig layout is present in templates directory (templates/layout.html). I store images in web/img directory (top.jpg). I also use built-in php5.4 server running:
php -S localhost:8000 web/index_dev.php
In templates/layout.html I'd like to use web/img/top.jpg picture. So I put there:
<img src="{{ app.request.basepath }}/img/top.jpg">
But image doesn't show.
I've also tried:
<img src="/img/top.jpg">
<img src="/web/img/top.jpg">
But with no success either.
My controller looks like (index.html extends layout.html):
$app->get('/', function () use ($app) {
return $app['twig']->render('index.html', array());
})->bind('homepage');
What should I do to get images to work?
Can you navigate to http://localhost:8000/web/img/top.jpg or http://localhost:8000/img/top.jpg directly? If you can't browse and see them directly they will not render as the browser will not be able to find them to display on your page either.
Are your images actually in or below the /web folder? (i.e. they should not be in your /templates folder)
Perhaps you could try to set the docroot explicitly sing the -t option when you launch the PHP webserver.
Otherwise I would suggest setting up a real web server like Apache. Your OS may already have this installed if you are running OS X or *nix.
I've got very simple .WAR containing example servlet. I'm able to deploy it in servicemix using the following command:
osgi:install file:///home/seiho/apache-servicemix-4.4.2/deploy/TestServlet.war?Bundle-SymbolicName=TestServlet&Webapp-Context=/TestServlet
And then see it in my browser. But only with full path to a file, e.g.: localhost:8080/TestServlet/index.html or localhost:8080/TestServlet/TestServlet (my servlet is TestServlet class).
I'd like to launch the index.html page automatically after entering: localhost:8080/TestServlet
how to do it?
MORE IMPORTANT
I need a way to convert the .WAR file or servlet project (I've got the sources) so that new .WAR file can be auto-deployed by copying it to $SERVICEMIX_HOME/deploy directory.
I've tried editing the MANIFEST.MF file, but with no success. Probably I'm doing something wrong.
Thanks for any advice/help.
To be recognised as a wab, you need to add a context path header to your manifest:
Web-ContextPath: TestServlet
It's working now! I was doing my MANIFEST.MF according to this page: http://team.ops4j.org/wiki/display/ops4j/Pax+Web+Extender+-+War+-+OSGi-fy
The problem was that for some reason "Bundle-Version: 1.0" line was required as opposed to optional as stated on that page.
Honestly, just adding the Bundle-Version fix-it.
I knew it was something wrong with the MANIFEST.MF and after Holly Cummins' question I played with it a bit more. Thanks Holly.
I still can't do anything with the manual site launching (have to manually enter the index.html).
http://localhost:8080/TestServlet/ gives me this:
HTTP ERROR 404
Problem accessing /TestServlet/. Reason:
Not Found
Powered by Jetty://
http://localhost:8080/TestServlet/index.html gives me proper site.