<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>

CC BY-SA 4.0
2018-07-31T17:54:55.947Z
2018-07-31T17:54:55.947Z
Clay Kilby
<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>

CC BY-SA 4.0
2018-07-27T20:04:32.830Z
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.
Clay Kilby
CC BY-SA 4.0
2018-07-27T20:06:41.903Z
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!
Clay Kilby
CC BY-SA 4.0
2018-07-27T20:27:01.407Z
@ClayKilby ah wonderful! Yeah I figured it had something to do with some whitespace being added somewhere 
Jalen Davenport
CC BY-SA 4.0
2018-07-28T13:52:18.610Z
@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.
Mats Mikkel Rummelhoff
CC BY-SA 4.0
2018-07-27T19:13:33.817Z
2018-07-27T19:13:33.817Z
Jalen Davenport
<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>

CC BY-SA 4.0
2018-07-27T19:33:58.277Z
2018-07-27T19:33:58.277Z
Mats Mikkel Rummelhoff
<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>

<plugin-printmaker>
Printmaker PDF includes odd spaces and blank page
# 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 %}
  
        
            
        
        
            
            {{ entry.displayTitle }}

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

                
                {% set queryString = craft.request.getQueryString() %}
                {% if craft.request.getParam('type') is not null %}
                    
                    
                        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 %}
                    {{ entry.sortedDirectoryExplanation }}

                {% elseif craft.request.getParam('keyword') is not null %}
                    
                    
                        This is a subset of the full directory filtered by 
                            the keyword: "{{ query }}."
                    {{ entry.sortedDirectoryExplanation }}

                {% elseif craft.request.getParam('facility') is not null %}
                    
                    
                        This is a subset of the full directory showing only programs operating in
                        {% for slug in indicatorQuery %}
                            {% for indicator in craft.entries.slug(slug) %}
                                {{ indicator.title }}.
                            {% endfor %}
                        {% endfor %}
                    {{ entry.sortedDirectoryExplanation }}

                {% endif %}

            
            
                {% for program in programs %}
                    
                        
                            {{ program.displayTitle }}
                                {% for type in program.programTypes %}
                                    {% if type.slug == 'prison-program' %}
                                        
                                    {% elseif type.slug == 'jail-program' %}
                                        
                                    {% elseif type.slug == 'campus-program' %}
                                        
                                    {% endif %}
                                {% endfor %}
                            
                            {{ program.programLocation }}
                            {% if ( program.programWebsite | length ) or ( program.programFacebook| length ) %}
                                {% if program.programWebsite|length %}{{ program.programWebsite }}{% endif %}{% if ( program.programWebsite | length ) and ( program.programFacebook| length ) %} | {% endif %}{% if program.programFacebook|length %}facebook{% endif %}
                            {% endif %}
                            
                                
                                    
                                        Operating In
                                        {{ program.operatingIn }}
                                    
                                    
                                        Programs Offered
                                        {{ program.programsOffered }}
                                    
                                    
                                        Contacts
                                        {{ program.programContacts }}
                                    
                                
                            
                        
                    
                {% endfor %}
            
        

{% 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  tag for example) in your template.
One way I think you could solve that is wrapping your html code in a Twig spaceless tag:
{% set html %}

  {% spaceless %}

    
      
        ...
      

      
        ...
      
    

  {% 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 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.  
> **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**: @ClayKilby ah wonderful! Yeah I figured it had something to do with some whitespace being added somewhere   
> **username_2**: @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.  

---

### 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.


---

