Javascript 在PDF中查看时,我的行中的换行符。(添加减号时)
当我以PDF格式查看html页面时出现问题。问题是,当数值太大时,它会打断减号和数值之间的界线 这里是hmtl页面的一个示例,它工作得非常完美 然后,当我将其转换为PDF时,它如下所示: 在此,我将页面呈现为完整的html文档:Javascript 在PDF中查看时,我的行中的换行符。(添加减号时),javascript,python,html,pdf,wkhtmltopdf,Javascript,Python,Html,Pdf,Wkhtmltopdf,当我以PDF格式查看html页面时出现问题。问题是,当数值太大时,它会打断减号和数值之间的界线 这里是hmtl页面的一个示例,它工作得非常完美 然后,当我将其转换为PDF时,它如下所示: 在此,我将页面呈现为完整的html文档: def document_to_html_document(document): """ Renders the invoice to a full html document with <html>, <head>, and <bod
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
})
这是我的hmtl代码,我在其中添加了“body”:
MOSEK-{{document}
身体{
宽度:950px;
}
{{body | safe}}
我不知道如何解决它,任何帮助都将不胜感激:)
这是发票主体的内容:
<div class="row">
<div class="col-xs-12">
<table class="invoice-lines">
<thead>
<tr class="underline overline">
<th>No.</th>
<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>
</tr>
</thead>
<tbody>
{# 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>
<td>
{% if line.objs.0.product.name %}
{{ line.objs.0.product.name }}<br />
{% else %}
{{ line.objs.0.serial.product.name }}-{% 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>
<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 line.discount %}<br>({{ line.discount }}% dis.){% endif %}
</td>
<td class="nowrap fr sec-column">{{ line.rowtotal|floatformat:2 }}</td>
</tr>
{% 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>
<td>
{{ citem.obj.name }}
{% if citem.obj.agreement %}
<br>Agreement: {{ citem.obj.agreement }}
{% endif %}
</td>
<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>
</tr>
{% 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>
</tr>
{% 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>
<td class="fr sec-column">{{ total }}</td>
<th> </th>
</tr>
{% 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>
<tr class="sum-line">
<th colspan="4" class="fr">Total ({{ inv.currency }})</th>
<th> </th>
<td class="fr grand-total overline sec-column">{{ inv.total|floatformat:2 }}</td>
</tr>
</tbody>
</table>
</div>
</div>
不
零件ID/说明
量
标价
单价
全部的
{#我们希望最后一行的边框底部更暗。#
{#为了找到这最后一行,我们首先需要确定#}
{#如果有自定义项。如果有,则最后一行#}
{#将是自定义项,因为它们是最后一次打印的。如果不是,则#}
{那么我们需要找到最后一条生产线。}
{第%行中的第%行}
{行数为%|下一行:forloop.counter0作为下一行%}
{{line.line}}
{%if line.objs.0.product.name%}
{{line.objs.0.product.name}}
{%else%}
{{line.objs.0.serial.product.name}-{%if line.objs.0.back==1%}back{%endif%}MAIN
{%endif%}
{%if line.objs.0.back和line.objs.0.back_说明!=''%}
{{line.objs.0.back_description}}
{%elif line.objs.0.back==False和line.objs.0.description!=''%}
{{line.objs.0.description}}
{%else%}
{{line.objs.0.description}}
{%endif%}
{%if line.objs.0.start%}
句点:{line.objs.0.start}-{{line.objs.0.end}}
{%endif%}
序列号:{line.list}
{{line.qty}
{{line.objs.0.price | floatformat:2}
{{line.objs.0.小计| floatformat:2}
{%if line.discount%}
({{line.discount}}%dis.){%endif%}
{{line.rowtotal | floatformat:2}
{%endwith%}
{%endfor%}
{citems%中citem的%s}
{使用citems | next:forloop.counter0作为next_citem%}
{{citem.line}
{{citem.obj.name}
{%if citem.obj.agreement%}
协议:{citem.obj.Agreement}
{%endif%}
{{citem.rowtotal}floatformat:2}
{{citem.rowtotal}floatformat:2}
{{citem.rowtotal}floatformat:2}
{%endwith%}
{%endfor%}
小计
{{inv.subtotal}floatformat:2}
{增值税、行数、消息、总计、增值税百分比的百分比}
第{{lines}}行:
{{message}}
({{rate}}}%增值税)
{{total}}
{%endfor%}
增值税总额
{{inv.vat | floatformat:2}
总计({inv.currency}})
{{inv.total | floatformat:2}
来自Eliethesaiyan的解决方案:
在命令=xvfb中,运行wkhtmltopdf--zoom 1.5--footer right将标志zoom添加到导出命令:
command= xvfb-run wkhtmltopdf --zoom 1.5 --footer-right
如果输入大数字,html是否也会中断?\n否,只需减去symboltry即可将引擎专门设置为gecko,如下面的回答所示[在命令中=xvfb run wkhtmltopdf--zoom 1.5--footer right Thank you@Eliethesaiyan it worked:)
<div class="row">
<div class="col-xs-12">
<table class="invoice-lines">
<thead>
<tr class="underline overline">
<th>No.</th>
<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>
</tr>
</thead>
<tbody>
{# 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>
<td>
{% if line.objs.0.product.name %}
{{ line.objs.0.product.name }}<br />
{% else %}
{{ line.objs.0.serial.product.name }}-{% 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>
<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 line.discount %}<br>({{ line.discount }}% dis.){% endif %}
</td>
<td class="nowrap fr sec-column">{{ line.rowtotal|floatformat:2 }}</td>
</tr>
{% 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>
<td>
{{ citem.obj.name }}
{% if citem.obj.agreement %}
<br>Agreement: {{ citem.obj.agreement }}
{% endif %}
</td>
<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>
</tr>
{% 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>
</tr>
{% 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>
<td class="fr sec-column">{{ total }}</td>
<th> </th>
</tr>
{% 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>
<tr class="sum-line">
<th colspan="4" class="fr">Total ({{ inv.currency }})</th>
<th> </th>
<td class="fr grand-total overline sec-column">{{ inv.total|floatformat:2 }}</td>
</tr>
</tbody>
</table>
</div>
</div>
command= xvfb-run wkhtmltopdf --zoom 1.5 --footer-right