Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T17:53:54.477Z
Answers.Text: 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?
Answers.UserDisplayName: John
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T17:58:01.873Z
Answers.Text: 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?
Answers.UserDisplayName: Michael Rog
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T18:23:20.077Z
Answers.Text: Ah! Yes, that worked (though your code sample says pdfUrl and your actual var name is pdf!) Thanks Michael!!
Answers.UserDisplayName: John
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T21:46:27.813Z
Answers.Text: That's what I get for copy/pasting from old support emails. Fixed!
Answers.UserDisplayName: Michael Rog
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T17:27:10.673Z
Answers.LastActivityDate: 2016-03-07T21:46:03.910Z
Answers.LastEditDate: 2016-03-07T21:46:03.910Z
Answers.UserDisplayName: Michael Rog
Body: <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>
  
Tags: <pdf><plugin-printmaker><dompdf>
Title: Printmaker plugin cuts off HTML when rendering PDF link
ThreadText: # 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) %}
  
  <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?
  
  **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...
  
  ```
  <a href="{{ pdfUrl }}" target="_blank">Download PDF Support Guide</a>
  
  ```
  
  > **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 username_0!!  
  > **username_0**: That's what I get for copy/pasting from old support emails. Fixed!  
  
  ---
  
  