Adama Camara Adama Camara - 5 months ago 4x
Python Question

The lines breaks in my rows when viewing in PDF. (When adding minus symbol)

I have a problem when i View my html page in PDF-form. The problem is that when the number values are to big then it breaks the line between the minus symbol and values.

Here is an example of the hmtl page, it works perfect
enter image description here

Then when i convert it to a PDF it looks like this:
enter image description here

Here i Render my page to a full html document:

def document_to_html_document(document):
Renders the invoice to a full html document with <html>, <head>, and <body> tags.
return render_to_string('invoice_print.html', {
'body': document_to_html(document),
'document': document,
'base_url': settings.SITE_BASE_URL

The code where i build the HTML string and converting it to a pdf:

def document_to_pdf(document, server_base_url, target=None):
# Build HTML string
html = document_to_html_document(document)

# Setup input and output files
html_file = tempfile.NamedTemporaryFile(suffix='.html')
target = target or tempfile.NamedTemporaryFile()

# Convert to pdf
command = 'xvfb-run wkhtmltopdf --footer-right "[page]/[topage]"{s} {o}'.format(,
s = subprocess.Popen(command, shell=True)

# Return pdf bytes

This is my hmtl code where i add the "body":

<title>MOSEK-{{ document }}</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!-- JQuery -->
<script src="{{ base_url }}static/assets/vendor/jquery-1.11.1.js"></script>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="{{ base_url }}static/assets/vendor/bootstrap-3.1.1-dist/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="{{ base_url }}static/assets/vendor/bootstrap-3.1.1-dist/css/bootstrap-theme.css">

<!-- Latest compiled and minified JavaScript -->
<script src="{{ base_url }}static/assets/vendor/bootstrap-3.1.1-dist/js/bootstrap.min.js"></script>

body {
width: 950px;
<div class="container">
{{ body|safe }}

I have no idea how to solve it, any help would be appreciated :)

This is the content of the Invoice_body:

<div class="row">
<div class="col-xs-12">
<table class="invoice-lines">
<tr class="underline overline">
<th>Part ID / Description</th>
<th class="nowrap fr sec-column">Quantity</th>
<th class="nowrap fr sec-column">List price</th>
<th class="nowrap fr sec-column">Unit price</th>
<th class="nowrap fr sec-column">Total</th>
{# We want the border-bottom of the last line to be darker. #}
{# In order to find this last line, we first need to determine #}
{# if there are custom items. If there are, then the last line #}
{# will be a custom item, since they are printed last. If not, #}
{# then we need to find the last product line. #}
{% for line in lines %}
{% with lines|next:forloop.counter0 as next_line %}
<tr class="line{% if not citems and not next_line %} last-line{% endif %}">
<td>{{ line.line }}</td>
{% if %}
{{ }}<br />
{% else %}
{{ }}-{% if line.objs.0.back == 1 %}BACK{% endif %}MAIN<br />
{% endif %}

{% if line.objs.0.back and line.objs.0.back_description != '' %}
{{ line.objs.0.back_description }}<br />
{% elif line.objs.0.back == False and line.objs.0.description != '' %}
{{ line.objs.0.description }}<br />
{% else %}
{{ line.objs.0.description }}<br />
{% endif %}

{% if line.objs.0.start %}
Period: {{ line.objs.0.start }} - {{ line.objs.0.end }}<br />
{% endif %}
Serial(s): {{ line.list }}

<td class="nowrap fr sec-column">{{ line.qty }}</td>
<td class="nowrap fr sec-column">{{ line.objs.0.price|floatformat:2 }}</td>
<td class="nowrap fr sec-column">
{{ line.objs.0.subtotal|floatformat:2 }}
{% if %}<br>({{ }}% dis.){% endif %}
<td class="nowrap fr sec-column">{{ line.rowtotal|floatformat:2 }}</td>

{% endwith %}
{% endfor %}

{% for citem in citems %}
{% with citems|next:forloop.counter0 as next_citem %}
<tr class="line{% if not next_citem %} last-line{% endif %}">
<td>{{ citem.line }}</td>
{{ }}
{% if citem.obj.agreement %}
<br>Agreement: {{ citem.obj.agreement }}
{% endif %}
<td class="sec-column"> </td>
<td class="fr sec-column">{{ citem.rowtotal|floatformat:2 }}</td>
<td class="fr sec-column">{{ citem.rowtotal|floatformat:2 }}</td>
<td class="fr sec-column">{{ citem.rowtotal|floatformat:2 }}</td>
{% endwith %}
{% endfor %}

<tr class="sum-line" id="subtotal-line">
<th colspan="4" class="fr">Subtotal</th>
<th> </th>
<td class="fr sec-column">{{ inv.subtotal|floatformat:2 }}</td>
{% for vat, lines, message, total, rate in vats %}
<tr class="sum-line">
<td colspan="4" class="fr">
<span class="nowrap">Line {{ lines }} : </span>
{{ message }}
<span class="nowrap"> ({{ rate }}% VAT)</span>
<td class="fr sec-column">{{ total }}</td>
<th> </th>
{% endfor %}
<tr class="sum-line">
<th colspan="4" class="fr">VAT total</th>
<th> </th>
<td class="fr sec-column">{{ inv.vat|floatformat:2 }}</td>
<tr class="sum-line">
<th colspan="4" class="fr">Total ({{ inv.currency }})</th>
<th> </th>
<td class="fr grand-total overline sec-column">{{|floatformat:2 }}</td>


add the flag zoom to the export command:

command= xvfb-run wkhtmltopdf --zoom 1.5 --footer-right