问题
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