'Remove white stripe on last page of PDF created by wkhtmltopdf?
I'm capturing IBM 3270 terminal screens in HTML, preserving attributes such as color and underlining in <span> elements with class attributes. This works well.
Now I want to present multiple screen captures in a PDF file, one capture per page; a slideshow.
I'm using wkhtmltopdf to convert the HTML to PDF. This works well, too, except for one nit: an unwanted thin white stripe at the bottom of the last page in the PDF. Hence this question.
Here's an HTML test case, consisting of 3 screens (simplistic test cards, with no display attributes):
<!DOCTYPE html>
<html>
<head>
<title>3270 terminal screen captures</title>
<style>
body {
font-family: sans-serif;
margin: 0;
padding: 0;
background-color: #000000;
}
pre.terminal {
font-family: "IBM Plex Mono";
margin: 0;
padding: 0.5em;
color: #00FF00;
font-size: 9.5pt;
line-height: 1;
}
pre.terminal:not(:first-child) {
page-break-before: always;
}
</style>
</head>
<body>
<pre class="terminal">12345678901234567890123456789012345678901234567890123456789012345678901234567890
2--------+---------+---------+---------+---------+---------+---------+---------+
3
4 Screen 1
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre>
<pre class="terminal">12345678901234567890123456789012345678901234567890123456789012345678901234567890
2--------+---------+---------+---------+---------+---------+---------+---------+
3
4 Screen 2
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre>
<pre class="terminal">12345678901234567890123456789012345678901234567890123456789012345678901234567890
2--------+---------+---------+---------+---------+---------+---------+---------+
3
4 Screen 3
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre>
</body>
</html>
Here's the wkhtmltopdf command line I'm using to create the PDF (shown here with line breaks for readability):
wkhtmltopdf
--enable-local-file-access
--disable-smart-shrinking
--print-media-type
--dpi 300
--page-width 6.527in
--page-height 3.327in
--margin-top 0
--margin-right 0
--margin-bottom 0
--margin-left 0
input.html
output.pdf
Why wkhtmltopdf? My primary platform, and the primary platform of users I'll be sharing this method with, is Windows 10. I've read the project status of wkhtmltopdf, and looked at weasyprint, but I'm baulking at the steps involved in installing weasyprint on Windows.
I've read and applied the advice in the existing question "wkhtmltopdf with full page background", but that's not fixed this issue.
Setting the height of the <pre> to match the wkhtmltopdf page height doesn't fix it, either:
box-sizing: border-box;
height: 3.327in;
Workaround
Workaround, not a solution: append extraneous content, and then delete the last page from the PDF. The remaining pages have edge-to-edge ("full-bleed") background color, as desired.
For example, add a bottom border to the <body> element:
border-bottom: 1px solid #000000;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

