1

Similar to this issue Render styled output using Printmaker plugin

I am having the same issue and can't seem to figure out how to style the PDF.

Here is my code to generate the PDF:

    {% set html %}
        {% include '_includes/_pdf/social.twig' %}
    {% endset %}

    {% set pdfUrl = craft.printmaker.pdfFromHtml(html).url %}

    <a href="{{ pdfUrl }}" target="_blank">Print Page</a>

This opens the PDF in a separate tab.

and then I am loading pdf.css into the head of _includes/_pdf/social.twig but the PDF is not styled.

<!DOCTYPE html>
<html lang="en" dir="ltr">
    <head>
        <meta charset="utf-8">
        <title>PDF Template</title>
        <link href="pdf.css" rel="stylesheet" type="text/css">
    </head>
    <body>

        // PDF HTML

    </body>
</html>

and here is my directory structure

_includes
    _pdf
        pdf.css
        social.twig

Is it possible to style the PDF this way or do I need to use <style> tag or inline styles?

1

You can link to the CSS in this way, but if it's not working for you then try changing the path to

<link href="./pdf.css" rel="stylesheet" type="text/css">

assuming that your CSS is in the site root.

2
  • Yes. That does it.
    – seth
    Sep 30 '18 at 19:59
  • 1
    An include in the head works as well: <head><style type="text/css">{% include '_includes/_pdf/pdf.css' %}</style></head>
    – seth
    Sep 30 '18 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.