1

Has anyone had any success with Printmaker PDF plugin?

I’m not sure where to put the tags? The only way I can get the template to actually load is to add the Printmaker tags at the end of the document. In which case, the "Download CV" link further up the page doesn’t work. It seems {{ pdf.url }} HAS to appear AFTER the Printmaker tags. If I move the Printmaker tags further up I get the error "Internal Server Error - Requested HTML document contains no data.”.

Also, i’ve linked to a print stylesheet and when I do get a document to be created the print.css is ignored?

Thanks

  • 1
    Quite disappointed with the plugin myself, the docs are skeleton at best. – erwinheiser Jan 12 '16 at 16:08
3

We've used it successfully to generate PDF tickets for orders. It may/may not help in your case.

On our order page, we simply have:

<a target="_blank" href="/orders/tickets?orderId={{ order.number }}">Download PDF Tickets</a>

Then, our order/tickets template:

{% set html %}
    {% set orderId = craft.request.param('orderId') %}

    // HTML/CSS to generate ticket
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <style>

    body {
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        font-size: 13px;
        line-height: 1.4em;
        font-weight: bold;
    }

    </style>
    </head>

    <body>

        // Ticket HTML

    </body>

    </html>

{% endset %}

{% set settings = {
    compress: true,
    orientation: 'portrait',
    size: 'letter',
    cacheDirectory: 'cache/tickets',
    filename: 'TICKET-' ~ craft.request.param('orderId') ~ '.pdf'
} %}

{% set pdf = craft.printmaker.pdfFromHtml(html, settings) %}

{{ pdf.output }}
  • Thanks for your help! I now seem to be getting somewhere.... I've used this href="/barristerPDF?entryId={{ entry.id }}" to link to the PDF template. Unfortunately the PDF is blank due to non of the field data being pulled through? My URL has /barristerPDF?entryId=201 which is the correct entry ID? I've stripped back to just {{ entry.title }} as a test but nothing :( – Martin Oct 23 '15 at 14:14
  • @Martin do you have an craft.entries criteria model in your template to get the entry with that ID? – carlcs Oct 23 '15 at 15:49
  • @carlcs - Yes I added an Criteria Model but i'm really just flying blind now :/ {% set entryId = craft.request.param('entryId') %} {% set entries = craft.entries.section('barristers') %} – Martin Oct 23 '15 at 15:56
  • 1
    Yay!! It's working :D Thanks @carlcs... Only issue now is the image isn't being pulled... I get the error "DOMPDF_ENABLE_REMOTE is set to FALSE macbook.local:5757/img/barristers/image.jpeg – Martin Oct 23 '15 at 17:33
  • 1
    Found it, its located at: craft/plugins/printmaker/vendor/dompdf/dompdf_config.inc.php for anyone else. – Gareth Dec 17 '15 at 14:08
1

Martin,

For reference, here's the template code you shared with me earlier:

{% set html %}

{% set entryId = craft.request.param('entryId') %}

    <html>
    ...    
    <body>
    {{ entry.title }} 
    </body>
    </html>

{% endset %}

{% set settings = {
    ...
} %}

{% set pdf = craft.printmaker.pdfFromHtml(html, settings) %}

{{ pdf.output }}

You're using an entry variable to reference your entry content, but you haven't created such a variable in your template yet.

Also, while {% set entryId = craft.request.param('entryId') %} is valid as a statement by itself, I think it might be conflicting with the opening of your {% set html %} tag pair.

Try this instead:

{% set entryId = craft.request.getParam('entryId') %}

{% set entry = craft.entries.id(entryId).first %}

{% set html %}
    ...
{% endset %}

...

Check out the Printmaker docs for more code examples.

Cheers!

  • 1
    Ooops, looks like a connection glitch on my end delayed this post 'til just now. Glad to see yall already got it sorted. :) – Michael Rog Oct 23 '15 at 21:26

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.