Stylesheet not found
truckee opened this issue · 9 comments
In Symfony 2.3, the controller reads:
* @Pdf(stylesheet="ManaClientBundle:Test:pdfstyle.xml.twig")
The file at ..src/Mana/ClientBundle/Resources/views/Test/pdfstyle.xml.twig reads:
<stylesheet>
<page class="card" page-size="8in:5in" margin=".5in" font-size="12">
</stylesheet>
And the document template reads:
<page class="card">
Yet the rendered page is not the given page size. The page size only occurs when the attributes are present in the document's template, as in:
<page page-size="8in:5in" margin=".5in" font-size="12">
Please advise. Thanks immensely.
I have tested this bug and I can't reproduce it. Maybe it is cache problem? Stylesheets are cached, so invoking cache:clear command maybe will resolve you problem.
Thanks for your reply. Clearing cache does not change behavior. Switching between the two configurations without clearing the cache shows two different page sizes.
Do I have the stylesheet naming and file placement correct?
In experimenting I observed that improper tags inside the stylesheet do not throw errors. The annotation itself does not throw errors, although I know I can make it do that if I move things around! This tells me that the annotation is respected. It's got to be something very simple.
George
If there is a bug, it's that the annotation does not report that the stylesheet is not found. I have entered non-existent filenames for the stylesheet and no error was thrown. The documentation gives the impression that the stylesheet should be in the same location as the template. This is not the case.
It is also true that the behavior is identical in dev and production modes.
George
If stylesheet file doesn't exist, exception would be thrown. Can you show minimal piece of full example that reproduces this behavior?
Controller snippet:
/**
* Test controller.
*
* @Route("/test")
*/
class TestController extends Controller {
/**
* @Pdf(stylesheet="barkatmoon.txt")
* @Route("/card")
*/
public function cardAction() {
$em = $this->getDoctrine()->getManager();
$household = $em->getRepository('ManaClientBundle:Household')->find(8607);
$facade = $this->get('ps_pdf.facade');
$response = new Response();
$this->render('ManaClientBundle:Test:roster.pdf.twig', array(
'household' => $household,
'date' => date_create(),
), $response);
$xml = $response->getContent();
$content = $facade->render($xml);
return new Response($content, 200, array('content-type' => 'application/pdf'));
}
Any other piece it would be useful to see? g
With apologies for improper formatting. I'm new here!
Deleted. I must stop demonstrating my ignorance. And frustration with lack of progress.
If you use $facade object directly, Pdf annotation is unnecessary. You should use Pdf annotation when you want to use pdf rendering in implicit way. In your code you should pass stylesheet xml as second argument of $facade->render(...) method.
example:
public function cardAction() {
//...
$stylesheetXml = $this->renderView('yourStylesheet', array());
$content = $facade->render($xml, $stylesheetXml);
return new Response($content, 200, array('content-type' => 'application/pdf'));
}
Thank you!!! Did I miss this in the documentation? I'll update my question in stackoverflow. g