Answers.Body: <p>It turns out there was an extra br tag inside the loop. I had intended to use it to add a short space between each entry, but instead they collected at the end of the document and created the long unwanted spacing. Removing that tag fixed it right up!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-31T17:54:55.947Z
Answers.LastActivityDate: 2018-07-31T17:54:55.947Z
Answers.UserDisplayName: Clay Kilby
Answers.Body: <p>I have a hunch the issues you're seeing with the extra spacing and blank pages on your website are being caused by the indentation and new lines (after the <code>&lt;/body&gt;</code> tag for example) in your template.</p>
  
  <p>One way I <em>think</em> you could solve that is wrapping your html code in a <a href="https://twig.symfony.com/doc/2.x/tags/spaceless.html" rel="nofollow noreferrer">Twig <strong>spaceless</strong> tag</a>:</p>
  
  <pre><code>{% set html %}
  
    {% spaceless %}
  
      &lt;html&gt;
        &lt;head&gt;
          ...
        &lt;/head&gt;
  
        &lt;body&gt;
          ...
        &lt;/body&gt;
      &lt;/html&gt;
  
    {% endspaceless %}
  
  {% endset %}
  
  
  {% set settings = { 
    orientation : 'portrait' 
  } %}
  
  {% set pdf = craft.printmaker.pdfFromHtml(html, settings) %}
  
  {{ pdf.output }}
  </code></pre>
  
  <p>Any extra whitespace <em>between</em> the html tags inside that <code>{% spaceless %}</code> tag is going to be removed in the final product and you don't have to sacrifice code indenting in your template to accomplish it </p>
  
  <p>Hopefully that helps, let me know how it goes!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-27T20:04:32.830Z
Answers.Text: Thanks Jalen! But unfortunately no, the spaceless tag didn't change anything in the output. I also tried minifying the whole template, also to no effect.
Answers.UserDisplayName: Clay Kilby
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-27T20:06:41.903Z
Answers.Text: Just figured it out! There was an unnecessary <br> just inside the end of the for loop. Getting rid of that fixed things right up!
Answers.UserDisplayName: Clay Kilby
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-27T20:27:01.407Z
Answers.Text: @ClayKilby ah wonderful! Yeah I figured it had something to do with some whitespace being added somewhere 
Answers.UserDisplayName: Jalen Davenport
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-28T13:52:18.610Z
Answers.Text: @ClayKilby Great that you figured it out. You should add an answer to this question with an explanation of the fix, and mark it as the correct answer – this would be helpful for other people who might struggle with the same issue in the future.
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-27T19:13:33.817Z
Answers.LastActivityDate: 2018-07-27T19:13:33.817Z
Answers.UserDisplayName: Jalen Davenport
Answers.Body: <p>It's very difficult to give a "canonical" answer to this issue, without actually playing around with the code, because it could be a combination of things that produce the unwanted spaces and page breaks.</p>
  
  <p>But I've experienced similar problems, and in my case I solved it by some careful use of different <a href="https://css-tricks.com/almanac/properties/p/page-break/" rel="nofollow noreferrer">CSS page-break properties</a>. Your mileage may vary, though.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-27T19:33:58.277Z
Answers.LastActivityDate: 2018-07-27T19:33:58.277Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I've got a directory download feature running on the Printmaker Plugin, that's including some odd spaces and blank pages. Live example at: <a href="https://correctionstocollegeca.org/directory-download" rel="nofollow noreferrer">https://correctionstocollegeca.org/directory-download</a>. Everything is great until the last couple pages, where entries get spaced out one per page, and the last page is blank. Any ideas for fixing the spacing?</p>
  
  <pre><code>{% set html %}
    &lt;html&gt;
          &lt;head&gt;
              &lt;link href="https://correctionstocollegeca.org/css/doc.css" rel="stylesheet"/&gt;
          &lt;/head&gt;
          &lt;body&gt;
              &lt;img src="https://correctionstocollegeca.org/assets/globals/ctcca-logo.png" style="width: 200px;"&gt;
              &lt;h1 style="line-height:0.8;margin-top:8px;"&gt;{{ entry.displayTitle }}&lt;/h1&gt;
  
              {% if craft.request.getParam('type') is not null %}
  
                          {# Get search parameters from the URL query string #}
                          {% set query = craft.request.getParam('type') %}
  
                          {# Start an array of search parameters (relationParam) with 'and' to match ALL categories #}
                          {% set relationParam = ['and'] %}
  
                          {# Find categories that match the slugs in your query string... #}
                          {% for querySlug in query %}
                                  {% set category = craft.categories.group('programTypes').slug(querySlug) %}
  
                                  {# And merge them into the relationParam array. #}
                                  {% set relationParam = relationParam|merge([{ targetElement: category }]) %}
                          {% endfor %}
  
                          {# Avoid passing an array with `['and']` only #}
                          {% if relationParam|length &lt; 2 %}
                              {% set relationParam = '' %}
                          {% endif %}
  
                          {% set searchParams = {
                              relatedTo:  relationParam,
                              section: 'colleges'
                          } %}
  
                          {# Find your entries #}
                          {% set programs = craft.entries(searchParams).order('title') %}    
  
                  {% elseif craft.request.getParam('facility') is not null %}
  
                          {% set query = craft.entries.slug(craft.request.getParam('facility')) %}
                          {% set programs =  craft.entries.section('colleges').relatedTo(query).order('title') %}
                          {% set indicatorQuery = craft.request.getParam('facility') %}
  
                  {% elseif craft.request.getParam('keyword') is not null %}
  
                          {% set query = craft.request.getParam('keyword') %}
                          {% set programs =  craft.entries.section('colleges').search(query).order('score') %}
  
                  {% elseif craft.request.getParam('featured') is not null %}
  
                          {% set featured = craft.request.getParam('featured') %}
                          {% set featuredPrograms =  craft.entries.id(featured) %}
                          {% set programs = craft.entries.section('colleges').order('title').id('and, not ' ~ featured | join(', not '))%}
  
                  {% elseif craft.request.getParam('featuredFacility') is not null %}
  
                          {% set featuredFacility = craft.entries.slug(craft.request.getParam('featuredFacility')) %}
                          {% set featuredPrograms =  craft.entries.section('colleges').relatedTo(featuredFacility).order('title') %}
                          {% set featuredIds = featuredPrograms.ids() %}
                          {% set programs = craft.entries.section('colleges').order('title').id('and, not ' ~ featuredIds | join(', not ')) %}
  
                  {% else %}
  
                          {% set programs = craft.entries.section('colleges').order('title') %}
  
                  {% endif %}
  
                  &lt;!-- Query Indicator --&gt;
                  {% set queryString = craft.request.getQueryString() %}
                  {% if craft.request.getParam('type') is not null %}
                      &lt;br&gt;
                      &lt;p&gt;
                          This is a subset of the full directory filtered to show only
                          {% if query|length == 1 %}
                              {% for slug in query %}
                                  {% for indicator in craft.categories.slug(slug) %}
                                      {{ indicator.title|lower }}s.
                                  {% endfor %}
                              {% endfor %}
                          {% elseif  queryString == "p=directory-download&amp;type%5B%5D=prison-program&amp;type%5B%5D=jail-program" %}
                              prison and jail programs.
                          {% elseif  queryString == "p=directory-download&amp;type%5B%5D=prison-program&amp;type%5B%5D=campus-program" %}
                              prison and campus programs.
                          {% elseif  queryString == "p=directory-download&amp;type%5B%5D=prison-program&amp;type%5B%5D=jail-program&amp;type%5B%5D=campus-program" %}
                              prison, jail and campus programs.
                          {% elseif  queryString == "p=directory-download&amp;type%5B%5D=jail-program&amp;type%5B%5D=campus-program" %}
                              jail and campus programs.
                          {% endif %}
                      &lt;/p&gt;{{ entry.sortedDirectoryExplanation }}
  
                  {% elseif craft.request.getParam('keyword') is not null %}
                      &lt;br&gt;
                      &lt;p&gt;
                          This is a subset of the full directory filtered by 
                              &lt;span class="label filter-label"&gt;the keyword: "{{ query }}."&lt;/span&gt;
                      &lt;/p&gt;{{ entry.sortedDirectoryExplanation }}
  
                  {% elseif craft.request.getParam('facility') is not null %}
                      &lt;br&gt;
                      &lt;p&gt;
                          This is a subset of the full directory showing only programs operating in
                          {% for slug in indicatorQuery %}
                              {% for indicator in craft.entries.slug(slug) %}
                                  &lt;span class="label filter-label"&gt;{{ indicator.title }}.&lt;/span&gt;
                              {% endfor %}
                          {% endfor %}
                      &lt;/p&gt;{{ entry.sortedDirectoryExplanation }}
  
                  {% endif %}&lt;!-- /Query Indicator --&gt;
  
              &lt;br&gt;
              &lt;table style="table-layout: fixed; width:100%;" &gt;
                  {% for program in programs %}
                      &lt;tr&gt;
                          &lt;td colspan="3" style="width:33%;border:1px solid #bbb;padding-left:10px;padding-right:10px;" valign="top"&gt;
                              &lt;h2&gt;{{ program.displayTitle }}&lt;span class="no-wrap"&gt;
                                  {% for type in program.programTypes %}
                                      {% if type.slug == 'prison-program' %}
                                          &lt;img src="https://correctionstocollegeca.org/assets/globals/p-symbol.png" style="width:18px;margin-right:5px;"&gt;
                                      {% elseif type.slug == 'jail-program' %}
                                          &lt;img src="https://correctionstocollegeca.org/assets/globals/j-symbol.png" style="width:18px;margin-right:5px;"&gt;
                                      {% elseif type.slug == 'campus-program' %}
                                          &lt;img src="https://correctionstocollegeca.org/assets/globals/c-symbol.png" style="width:18px;margin-right:5px;"&gt;
                                      {% endif %}
                                  {% endfor %}&lt;/span&gt;
                              &lt;/h2&gt;
                              &lt;p class="directory-location"&gt;{{ program.programLocation }}&lt;/p&gt;
                              {% if ( program.programWebsite | length ) or ( program.programFacebook| length ) %}
                                  &lt;p class="directory-links"&gt;{% if program.programWebsite|length %}&lt;a href="//{{ program.programWebsite }}"&gt;{{ program.programWebsite }}&lt;/a&gt;{% endif %}{% if ( program.programWebsite | length ) and ( program.programFacebook| length ) %} | {% endif %}{% if program.programFacebook|length %}&lt;a href="{{ program.programFacebook }}"&gt;facebook&lt;/a&gt;{% endif %}&lt;/p&gt;
                              {% endif %}
                              &lt;table style="table-layout: fixed; width:100%;"&gt;
                                  &lt;tr&gt;
                                      &lt;td style="width: 33%;" valign="top"&gt;
                                          &lt;p style="font-size:14px;margin-bottom:-2px;"&gt;&lt;b&gt;Operating In&lt;/b&gt;&lt;/p&gt;
                                          {{ program.operatingIn }}
                                      &lt;/td&gt;
                                      &lt;td style="width: 33%;" valign="top"&gt;
                                          &lt;p style="font-size:14px;margin-bottom:-2px;"&gt;&lt;b&gt;Programs Offered&lt;/b&gt;&lt;/p&gt;
                                          {{ program.programsOffered }}
                                      &lt;/td&gt;
                                      &lt;td style="width: 33%;word-break:break-all; word-wrap:break-word;" valign="top"&gt;
                                          &lt;p style="font-size:14px;margin-bottom:-2px;"&gt;&lt;b&gt;Contacts&lt;/b&gt;&lt;/p&gt;
                                          {{ program.programContacts }}
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                              &lt;/table&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  {% endfor %}
              &lt;/table&gt;
          &lt;/body&gt;
  &lt;/html&gt;
  {% endset %}
  {% set settings = { 
      orientation : 'portrait' 
  } %}
  
  {% set pdf = craft.printmaker.pdfFromHtml(html, settings) %}
  
  {{ pdf.output }}
  </code></pre>
  
Tags: <plugin-printmaker>
Title: Printmaker PDF includes odd spaces and blank page
ThreadText: # Printmaker PDF includes odd spaces and blank page
  
  (Asked by: username_0 on 2018-07-27)
  
  I've got a directory download feature running on the Printmaker Plugin, that's including some odd spaces and blank pages. Live example at: <https://correctionstocollegeca.org/directory-download>. Everything is great until the last couple pages, where entries get spaced out one per page, and the last page is blank. Any ideas for fixing the spacing?
  
  ```
  {% set html %}
    <html>
          <head>
              <link href="https://correctionstocollegeca.org/css/doc.css" rel="stylesheet"/>
          </head>
          <body>
              <img src="https://correctionstocollegeca.org/assets/globals/ctcca-logo.png" style="width: 200px;">
              <h1 style="line-height:0.8;margin-top:8px;">{{ entry.displayTitle }}</h1>
  
              {% if craft.request.getParam('type') is not null %}
  
                          {# Get search parameters from the URL query string #}
                          {% set query = craft.request.getParam('type') %}
  
                          {# Start an array of search parameters (relationParam) with 'and' to match ALL categories #}
                          {% set relationParam = ['and'] %}
  
                          {# Find categories that match the slugs in your query string... #}
                          {% for querySlug in query %}
                                  {% set category = craft.categories.group('programTypes').slug(querySlug) %}
  
                                  {# And merge them into the relationParam array. #}
                                  {% set relationParam = relationParam|merge([{ targetElement: category }]) %}
                          {% endfor %}
  
                          {# Avoid passing an array with `['and']` only #}
                          {% if relationParam|length < 2 %}
                              {% set relationParam = '' %}
                          {% endif %}
  
                          {% set searchParams = {
                              relatedTo:  relationParam,
                              section: 'colleges'
                          } %}
  
                          {# Find your entries #}
                          {% set programs = craft.entries(searchParams).order('title') %}    
  
                  {% elseif craft.request.getParam('facility') is not null %}
  
                          {% set query = craft.entries.slug(craft.request.getParam('facility')) %}
                          {% set programs =  craft.entries.section('colleges').relatedTo(query).order('title') %}
                          {% set indicatorQuery = craft.request.getParam('facility') %}
  
                  {% elseif craft.request.getParam('keyword') is not null %}
  
                          {% set query = craft.request.getParam('keyword') %}
                          {% set programs =  craft.entries.section('colleges').search(query).order('score') %}
  
                  {% elseif craft.request.getParam('featured') is not null %}
  
                          {% set featured = craft.request.getParam('featured') %}
                          {% set featuredPrograms =  craft.entries.id(featured) %}
                          {% set programs = craft.entries.section('colleges').order('title').id('and, not ' ~ featured | join(', not '))%}
  
                  {% elseif craft.request.getParam('featuredFacility') is not null %}
  
                          {% set featuredFacility = craft.entries.slug(craft.request.getParam('featuredFacility')) %}
                          {% set featuredPrograms =  craft.entries.section('colleges').relatedTo(featuredFacility).order('title') %}
                          {% set featuredIds = featuredPrograms.ids() %}
                          {% set programs = craft.entries.section('colleges').order('title').id('and, not ' ~ featuredIds | join(', not ')) %}
  
                  {% else %}
  
                          {% set programs = craft.entries.section('colleges').order('title') %}
  
                  {% endif %}
  
                  <!-- Query Indicator -->
                  {% set queryString = craft.request.getQueryString() %}
                  {% if craft.request.getParam('type') is not null %}
                      <br>
                      <p>
                          This is a subset of the full directory filtered to show only
                          {% if query|length == 1 %}
                              {% for slug in query %}
                                  {% for indicator in craft.categories.slug(slug) %}
                                      {{ indicator.title|lower }}s.
                                  {% endfor %}
                              {% endfor %}
                          {% elseif  queryString == "p=directory-download&type%5B%5D=prison-program&type%5B%5D=jail-program" %}
                              prison and jail programs.
                          {% elseif  queryString == "p=directory-download&type%5B%5D=prison-program&type%5B%5D=campus-program" %}
                              prison and campus programs.
                          {% elseif  queryString == "p=directory-download&type%5B%5D=prison-program&type%5B%5D=jail-program&type%5B%5D=campus-program" %}
                              prison, jail and campus programs.
                          {% elseif  queryString == "p=directory-download&type%5B%5D=jail-program&type%5B%5D=campus-program" %}
                              jail and campus programs.
                          {% endif %}
                      </p>{{ entry.sortedDirectoryExplanation }}
  
                  {% elseif craft.request.getParam('keyword') is not null %}
                      <br>
                      <p>
                          This is a subset of the full directory filtered by 
                              <span class="label filter-label">the keyword: "{{ query }}."</span>
                      </p>{{ entry.sortedDirectoryExplanation }}
  
                  {% elseif craft.request.getParam('facility') is not null %}
                      <br>
                      <p>
                          This is a subset of the full directory showing only programs operating in
                          {% for slug in indicatorQuery %}
                              {% for indicator in craft.entries.slug(slug) %}
                                  <span class="label filter-label">{{ indicator.title }}.</span>
                              {% endfor %}
                          {% endfor %}
                      </p>{{ entry.sortedDirectoryExplanation }}
  
                  {% endif %}<!-- /Query Indicator -->
  
              <br>
              <table style="table-layout: fixed; width:100%;" >
                  {% for program in programs %}
                      <tr>
                          <td colspan="3" style="width:33%;border:1px solid #bbb;padding-left:10px;padding-right:10px;" valign="top">
                              <h2>{{ program.displayTitle }}<span class="no-wrap">
                                  {% for type in program.programTypes %}
                                      {% if type.slug == 'prison-program' %}
                                          <img src="https://correctionstocollegeca.org/assets/globals/p-symbol.png" style="width:18px;margin-right:5px;">
                                      {% elseif type.slug == 'jail-program' %}
                                          <img src="https://correctionstocollegeca.org/assets/globals/j-symbol.png" style="width:18px;margin-right:5px;">
                                      {% elseif type.slug == 'campus-program' %}
                                          <img src="https://correctionstocollegeca.org/assets/globals/c-symbol.png" style="width:18px;margin-right:5px;">
                                      {% endif %}
                                  {% endfor %}</span>
                              </h2>
                              <p class="directory-location">{{ program.programLocation }}</p>
                              {% if ( program.programWebsite | length ) or ( program.programFacebook| length ) %}
                                  <p class="directory-links">{% if program.programWebsite|length %}<a href="//{{ program.programWebsite }}">{{ program.programWebsite }}</a>{% endif %}{% if ( program.programWebsite | length ) and ( program.programFacebook| length ) %} | {% endif %}{% if program.programFacebook|length %}<a href="{{ program.programFacebook }}">facebook</a>{% endif %}</p>
                              {% endif %}
                              <table style="table-layout: fixed; width:100%;">
                                  <tr>
                                      <td style="width: 33%;" valign="top">
                                          <p style="font-size:14px;margin-bottom:-2px;"><b>Operating In</b></p>
                                          {{ program.operatingIn }}
                                      </td>
                                      <td style="width: 33%;" valign="top">
                                          <p style="font-size:14px;margin-bottom:-2px;"><b>Programs Offered</b></p>
                                          {{ program.programsOffered }}
                                      </td>
                                      <td style="width: 33%;word-break:break-all; word-wrap:break-word;" valign="top">
                                          <p style="font-size:14px;margin-bottom:-2px;"><b>Contacts</b></p>
                                          {{ program.programContacts }}
                                      </td>
                                  </tr>
                              </table>
                          </td>
                      </tr>
                  {% endfor %}
              </table>
          </body>
  </html>
  {% endset %}
  {% set settings = { 
      orientation : 'portrait' 
  } %}
  
  {% set pdf = craft.printmaker.pdfFromHtml(html, settings) %}
  
  {{ pdf.output }}
  
  ```
  
  **Tags:** plugin-printmaker
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2018-07-31. Score: 1 | Accepted answer
  
  It turns out there was an extra br tag inside the loop. I had intended to use it to add a short space between each entry, but instead they collected at the end of the document and created the long unwanted spacing. Removing that tag fixed it right up!
  
  
  ---
  
  ### Answer by username_1 on 2018-07-27. Score: 1
  
  I have a hunch the issues you're seeing with the extra spacing and blank pages on your website are being caused by the indentation and new lines (after the `</body>` tag for example) in your template.
  
  One way I *think* you could solve that is wrapping your html code in a [Twig **spaceless** tag](https://twig.symfony.com/doc/2.x/tags/spaceless.html):
  
  ```
  {% set html %}
  
    {% spaceless %}
  
      <html>
        <head>
          ...
        </head>
  
        <body>
          ...
        </body>
      </html>
  
    {% endspaceless %}
  
  {% endset %}
  
  {% set settings = { 
    orientation : 'portrait' 
  } %}
  
  {% set pdf = craft.printmaker.pdfFromHtml(html, settings) %}
  
  {{ pdf.output }}
  
  ```
  
  Any extra whitespace *between* the html tags inside that `{% spaceless %}` tag is going to be removed in the final product and you don't have to sacrifice code indenting in your template to accomplish it
  
  Hopefully that helps, let me know how it goes!
  
  > **Comments:**
  > **username_0**: Thanks username_1! But unfortunately no, the spaceless tag didn't change anything in the output. I also tried minifying the whole template, also to no effect.  
  > **username_0**: Just figured it out! There was an unnecessary <br> just inside the end of the for loop. Getting rid of that fixed things right up!  
  > **username_1**: @username_0 ah wonderful! Yeah I figured it had something to do with some whitespace being added somewhere   
  > **username_2**: @username_0 Great that you figured it out. You should add an answer to this question with an explanation of the fix, and mark it as the correct answer – this would be helpful for other people who might struggle with the same issue in the future.  
  
  ---
  
  ### Answer by username_2 on 2018-07-27. Score: 1
  
  It's very difficult to give a "canonical" answer to this issue, without actually playing around with the code, because it could be a combination of things that produce the unwanted spaces and page breaks.
  
  But I've experienced similar problems, and in my case I solved it by some careful use of different [CSS page-break properties](https://css-tricks.com/almanac/properties/p/page-break/). Your mileage may vary, though.
  
  
  ---
  
  