SpraedPDFGeneratorBundle : 用 CSS 生成 PDF [英] SpraedPDFGeneratorBundle : Generate PDF with CSS

查看:51
本文介绍了SpraedPDFGeneratorBundle : 用 CSS 生成 PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 SpraedPDFGeneratorBundle 从 Twig HTML 页面生成 PDF 文档,但问题是是不支持我的样式表.

I'm trying to generate a PDF document from a Twig HTML Page using SpraedPDFGeneratorBundle, but the problem is that my stylesheet is not supported.

我在某处关注了这个问题:使用 CSS 和图像生成 PDF 和我尝试这样做:

Somewhere I followed this question : Generate PDF with CSS and Images and I I tried to do like that:

<link rel="stylesheet" href="{{ app.request.scheme ~'://'~ app.request.httpHost ~ asset('css/bootstrap.min.css') }}" />

但我收到一个错误:

退出状态代码1"表示出了点问题:stderr:线程main"中的异常 java.lang.ClassCastException:org.xhtmlrenderer.render.BlockBox 无法在 org 上强制转换为 org.xhtmlrenderer.newtable.TableBox.xhtmlrenderer.layout.BoxCollector.collect(BoxCollector.java:127) at org.xhtmlrenderer.layout.BoxCollector.collect(BoxCollector.java:139) at org.xhtmlrenderer.layout.BoxCollector.collect(BoxCollector.java:139) atorg.xhtmlrenderer.layout.BoxCollector.collect(BoxCollector.java:139) 在 org.xhtmlrenderer.layout.BoxCollector.collect(BoxCollector.jav:...

The exit status code '1' says something went wrong: stderr: "Exception in thread "main" java.lang.ClassCastException: org.xhtmlrenderer.render.BlockBox cannot be cast to org.xhtmlrenderer.newtable.TableBox at org.xhtmlrenderer.layout.BoxCollector.collect(BoxCollector.java:127) at org.xhtmlrenderer.layout.BoxCollector.collect(BoxCollector.java:139) at org.xhtmlrenderer.layout.BoxCollector.collect(BoxCollector.java:139) at org.xhtmlrenderer.layout.BoxCollector.collect(BoxCollector.java:139) at org.xhtmlrenderer.layout.BoxCollector.collect(BoxCollector.jav:..

有人可以帮我吗?

推荐答案

SpraedPDFGeneratorBundle github页面中的某处提到了 这个:

要定义适当的打印 css,您可能需要阅读 w3.org 的提示:w3.org

To define proper print css you might want to read into the w3.org's hints on that: w3.org

我的问题之一是 SpraedPDFGeneratorBundle 无法正确解析我传递给他的 CSS 文件.这是 Twitter 引导程序的 CSS 文件(我使用的版本):

One of my problem was the fact that the SpraedPDFGeneratorBundle could not correctly parse the CSS file I passed him. This is the CSS file Twitter bootstrap (the version I used):

<link rel="stylesheet" href="{{ app.request.scheme ~'://'~ app.request.httpHost ~ asset('css/bootstrap.min.css') }}" />

更改 CSS 文件后,我替换了自己的样式表,一切正常,因为 SpraedPDFGeneratorBundle 正确验证了我的样式表:

After changing the CSS file, I replaced my own stylesheet, everything worked properly because SpraedPDFGeneratorBundle was properly validate my stylesheet:

<link rel="stylesheet" href="{{ app.request.scheme ~'://'~ app.request.httpHost ~ asset('css/my_custom_stylesheet.css') }}" />

这篇关于SpraedPDFGeneratorBundle : 用 CSS 生成 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆