SpraedPDFGeneratorBundle : Generate PDF with CSS

别等时光非礼了梦想. 提交于 2020-01-17 04:19:09

问题


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.

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') }}" />

But I'm getting an error:

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:..

Can someone help me ?


回答1:


It is mentioned somewhere in the SpraedPDFGeneratorBundle github page this:

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

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') }}" />

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') }}" />


来源:https://stackoverflow.com/questions/28764146/spraedpdfgeneratorbundle-generate-pdf-with-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!