1

I’ve got a funny Printmaker issue here that I hope you can help me with!

I’m using the following code to generate a link to a PDF:

{% set vars = { title: supportGuides.title, body: supportGuides.body } %}

{% set settings = { orientation : 'portrait', filename:supportGuides.slug~'.pdf' } %}

{% set pdf = craft.printmaker.pdfFromTemplate('support-guides/download', vars, settings) %}

<a href=“{{ pdf.url }}" target="_blank">Download PDF Support Guide</a>

In my HTML output, the beginning of the line is stripped out inexplicably:

https://mysite.dev/Printmaker/support-guide.pdf" target="_blank">Download PDF Support Guide</a>

How can I prevent the opening tag from being cut out like that?

2

Depending on your server setup, DOMPDF might be resetting the output buffer when the PDF is generated. This is a fairly rare issue, but I have heard of it before.

Solution: Try moving the Printmaker PDF-generation code to the top of the template before any output.

For example, at the top of the template...

{% set pdfUrl = craft.printmaker.pdfFromTemplate('support-guides/download', vars, settings).url %}

...and then later, in your output content...

<a href="{{ pdfUrl }}" target="_blank">Download PDF Support Guide</a>
  • The code is within a for loop so i cannot really put it at the beginning as it's dependent on other logic. However, would the same affect be achieved by putting it in a Macro and returning the html into the template? – John Mar 7 '16 at 17:53
  • I think as long as the PDF generation happens on a separate line from your HTML output, it'll avoid that issue. Does it work if you use the code from my answer inside your loop? – Michael Rog Mar 7 '16 at 17:58
  • Ah! Yes, that worked (though your code sample says pdfUrl and your actual var name is pdf!) Thanks Michael!! – John Mar 7 '16 at 18:23
  • That's what I get for copy/pasting from old support emails. Fixed! – Michael Rog Mar 7 '16 at 21:46

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.