KnpSnappyBundle - wkhtmltopdf:CSS/images 已加载但未加载脚本
KnpSnappyBundle - wkhtmltopdf: CSS/images are loaded but not scripts
我从 HTML 生成的 PDF 的样式和图像加载良好,但脚本加载不当。
twig:
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
form_themes: ['bootstrap_4_horizontal_layout.html.twig']
globals:
pathToWeb: "%kernel.project_dir%/web"
knp_snappy:
pdf:
enabled: true
binary: /usr/bin/wkhtmltopdf --javascript-delay 5000 --no-stop-slow-scripts --enable-javascript --debug-javascript --margin-top 0 --margin-bottom 0 --margin-left 0 --margin-right 0
options: []
DockerFile(wkhtmltopdf 0.12.3 带有修补的 qt(我需要它用于页眉和页脚))
RUN apt-get install libssl1.0-dev -y
RUN cd ~
RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.3/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz
RUN tar vxf wkhtmltox-0.12.3_linux-generic-amd64.tar.xz
RUN cp wkhtmltox/bin/wk* /usr/bin/
base.html.twig
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>{% block title %}Meetings manager{% endblock %}</title>
{% block stylesheets %}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Lato:400,700" rel="stylesheet">
<link rel="stylesheet" href="{{ absolute_url(asset('css/navbar.css')) }}">
<link rel="stylesheet" href="{{ absolute_url(asset('css/general.css')) }}">
{% endblock %}
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
{% block body %}{% endblock %}
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>
然后扩展此模板并加载图像,例如:
<img style="width: 100%;" src="{{pathToWeb ~ asset('image/emargement_top.png') }}">
好像可以执行javascript,如果我插入
<script>document.write("test");</script>
有效,但其他脚本无效。
我试过了
<script src="{{ absolute_url(asset('pdf/js/bootstrap.js')) }}"></script>
<script src="{{ absolute_url(asset('pdf/js/jquery-3.3.1.js')) }}"></script>
和
<script src="{{pathToWeb ~ asset('pdf/js/bootstrap.js')) }}"></script>
<script src="{{pathToWeb ~ asset('pdf/js/jquery-3.3.1.js')) }}"></script>
它也不起作用(如您所见,我已将脚本的本地版本放在 web 文件夹中)
总结一下:
- CSS 有效(自定义 css 和 bootstrap css)
- 图片作品
- Javascript可以执行
- Jquery 和 bootstrap 脚本未加载(bootstrap 网格不工作)
有什么想法吗?
我从 HTML 生成的 PDF 的样式和图像加载良好,但脚本加载不当。
twig:
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
form_themes: ['bootstrap_4_horizontal_layout.html.twig']
globals:
pathToWeb: "%kernel.project_dir%/web"
knp_snappy:
pdf:
enabled: true
binary: /usr/bin/wkhtmltopdf --javascript-delay 5000 --no-stop-slow-scripts --enable-javascript --debug-javascript --margin-top 0 --margin-bottom 0 --margin-left 0 --margin-right 0
options: []
DockerFile(wkhtmltopdf 0.12.3 带有修补的 qt(我需要它用于页眉和页脚))
RUN apt-get install libssl1.0-dev -y
RUN cd ~
RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.3/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz
RUN tar vxf wkhtmltox-0.12.3_linux-generic-amd64.tar.xz
RUN cp wkhtmltox/bin/wk* /usr/bin/
base.html.twig
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>{% block title %}Meetings manager{% endblock %}</title>
{% block stylesheets %}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Lato:400,700" rel="stylesheet">
<link rel="stylesheet" href="{{ absolute_url(asset('css/navbar.css')) }}">
<link rel="stylesheet" href="{{ absolute_url(asset('css/general.css')) }}">
{% endblock %}
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
{% block body %}{% endblock %}
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>
然后扩展此模板并加载图像,例如:
<img style="width: 100%;" src="{{pathToWeb ~ asset('image/emargement_top.png') }}">
好像可以执行javascript,如果我插入
<script>document.write("test");</script>
有效,但其他脚本无效。
我试过了
<script src="{{ absolute_url(asset('pdf/js/bootstrap.js')) }}"></script>
<script src="{{ absolute_url(asset('pdf/js/jquery-3.3.1.js')) }}"></script>
和
<script src="{{pathToWeb ~ asset('pdf/js/bootstrap.js')) }}"></script>
<script src="{{pathToWeb ~ asset('pdf/js/jquery-3.3.1.js')) }}"></script>
它也不起作用(如您所见,我已将脚本的本地版本放在 web 文件夹中)
总结一下:
- CSS 有效(自定义 css 和 bootstrap css)
- 图片作品
- Javascript可以执行
- Jquery 和 bootstrap 脚本未加载(bootstrap 网格不工作)
有什么想法吗?