<p>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.</p>

<p><strong>Solution: Try moving the Printmaker PDF-generation code to the top of the template before any output.</strong></p>

<p>For example, at the top of the template...</p>

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

<p>...and then later, in your output content...</p>

<pre><code>&lt;a href="{{ pdfUrl }}" target="_blank"&gt;Download PDF Support Guide&lt;/a&gt;
</code></pre>

CC BY-SA 3.0
2016-03-07T17:53:54.477Z
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
CC BY-SA 3.0
2016-03-07T17:58:01.873Z
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
CC BY-SA 3.0
2016-03-07T18:23:20.077Z
Ah! Yes, that worked (though your code sample says pdfUrl and your actual var name is pdf!) Thanks Michael!!
John
CC BY-SA 3.0
2016-03-07T21:46:27.813Z
That's what I get for copy/pasting from old support emails. Fixed!
Michael Rog
CC BY-SA 3.0
2016-03-07T17:27:10.673Z
2016-03-07T21:46:03.910Z
2016-03-07T21:46:03.910Z
Michael Rog
<p>I’ve got a funny Printmaker issue here that I hope you can help me with!</p>

<p>I’m using the following code to generate a link to a PDF:</p>

<pre><code>{% 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) %}

&lt;a href=“{{ pdf.url }}" target="_blank"&gt;Download PDF Support Guide&lt;/a&gt;
</code></pre>

<p>In my HTML output, the beginning of the line is stripped out inexplicably:</p>

<pre><code>https://mysite.dev/Printmaker/support-guide.pdf" target="_blank"&gt;Download PDF Support Guide&lt;/a&gt;
</code></pre>

<p>How can I prevent the opening tag from being cut out like that?</p>

<pdf><plugin-printmaker><dompdf>
Printmaker plugin cuts off HTML when rendering PDF link
# Printmaker plugin cuts off HTML when rendering PDF link

(Asked by: username_0 on 2016-03-07)

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) %}

Download PDF Support Guide

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

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

**Tags:** pdf, plugin-printmaker, dompdf


---

## 1 answers

### Answer by username_0 on 2016-03-07. Score: 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...
Download PDF Support Guide

> **Comments:**
> **username_1**: 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?  
> **username_0**: 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?  
> **username_1**: Ah! Yes, that worked (though your code sample says pdfUrl and your actual var name is pdf!) Thanks Michael!!  
> **username_0**: That's what I get for copy/pasting from old support emails. Fixed!  

---

