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">
        <meta charset="utf-8">
        <title>PDF Template</title>
        <link href="pdf.css" rel="stylesheet" type="text/css">

        // PDF HTML


and here is my directory structure


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


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.

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