English 中文(简体)
贾尼戈皮萨 -- -- 仅两个或两个以上页面的页数 -- -- 显示总页数的页数
原标题:django pisa - pagenumber just for two or more pages - show pagenumber of total pages

Is there a posibility to show the pagenumber with django pisa just for two or more pages? The template for showing up pagenumber looks like this:

<div id="footerContent">
   <p>Page <pdf:pagenumber></p>
</div>

我认为必须先获得页数,然后才能由比萨处理。 任何选择, 都可以使用假的 if/ else 语句 :

if pages > 1:
 ...
else:
 ...

如果您想要显示例如“ 强” page 1/5

问题回答

我有一个问题 添加一个计数器 来告诉我在文件的页面总数中 我所看的是哪个页码。 当我从下面切换 pisa 导入时, 它就能起作用 :

import ho.pisa as pisa

import xhtml2pdf.pisa as pisa 

用 pip 安装 xhtml2pdf

pip install xhtml2pdf

这就是我的脚脚现在的样子

<div id="footerContent">
    {%block page_foot%}
        Page <pdf:pagenumber> / <pdf:pagecount>
    {%endblock%}
</div>

在 python- pisa 的当前版本中无法做到这一点。 但是它有些补丁 。 如果您使用 pisa 或 xhtml2pdf 的版本, 您可以从这个 Github 获得页面的总数 。

https://github.com/chrisclass/xhtml2pdf" rel=“no follow'>https://github.com/chrisslass/xhtml2pdf

我的模板页脚看起来像这个 :

<div id="footerContent">
  "Page: <pdf:pagenumber> / <pdf:pagecount>
</div>

I think you can do it without using https://github.com/chrisglass/xhtml2pdf. What i did is, i use page break as below:

<h1 style="display:none">PAGECOUNT</h1>

和 H1 的 CSS 是

h1 {
    page-break-before:always;
}

现在,你可以用

<your-html-string>.count( PAGECOUNT ) + 1




相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签